hi, how I can get everyone child pid's the some parent?
hi, how I can get everyone child pid's the some parent?
Add them to some record when you call fork()
Remove them from that record when you waitpid() for them to exit
Or are you trying to create some kind of process tree?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
for instance, i use it function many times... I can tell parent from child (1), but how I can tell from child with B child A?
and why parent_pid differentCode:int main(void){ launcher("A"); launcher("B"); } void launcher(char *put){ pid_t pid; TELL_WAIT(); if ((pid = fork()) < 0) { printf("fork error\n"); } if (pid == 0) { glob++; var++; if(strcmp(put,"A")){ printf("output from child glob = %d, var = %d , put = A \n",glob, var); } if(strcmp(put,"B")){ printf("output from child glob = %d, var = %d , put = B \n",glob, var); TELL_CHILD(pid); // I want call child A from child B WAIT_CHILD(); } //WAIT_PARENT(); //1 } else { if(strcmp(put,"A")){ printf("pid = %d, parent_pid=%u,glob = %d, var = %d, xxx %d put = A \n", getpid(), getppid(), glob, var, pid); } if(strcmp(put,"B")){ printf("pid = %d, parent_pid=%u,glob = %d, var = %d, xxx %d put = B\n", getpid(), getppid(), glob, var, pid); //TELL_CHILD(pid); //1 } } }
pid = 31483, parent_pid=4460,glob = 6, var = 88, xxx 31485 put = B
output from child glob = 7, var = 89 , put = B
pid = 31483, parent_pid=4460,glob = 6, var = 88, xxx 31486 put = A
pid = 31485, parent_pid=31483,glob = 7, var = 89, xxx 31487 put = A
output from child glob = 7, var = 89 , put = A
output from child glob = 8, var = 90 , put = A
Last edited by quantt; 08-13-2009 at 05:04 AM.
Your code starts three children:
A, which then returns to start a B process.
and B started from the main process.
So you have two "B" processes, one with the main process as parent, and one with A as parent.
You may want to change your code around so that the launch of A doesn't return to start B.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
right, how make one parent with two child's and telling from one child another child?
Use the pid of each child.
You might also want to investigate getppid() (get parent process id) and this stuff:
Launching Jobs - The GNU C Library
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge