-   Programming (
-   -   A program which exists only after all its children have exited.. plz comment (

tuxfood 05-08-2005 03:56 PM

A program which exists only after all its children have exited.. plz comment

This is just a trial to write a program in which the parent quits only after all its children have finished executin..

so heres what i did

Now i case i am talking abt here is that the parent creates all the child process and then only starts to wait for them

1) so for each process forked().. i put the pid of that process into a list.
2) after creating the process the parent waits all children have exited..
the code for this is something like this

wait_list is the list to which the pids are added
Addtolist() adds a value pid to the wait_list
RemovefromList () removes the node with value pid from the wait_list



switch ( pid = fork ())
case -1 : perror("fork");
case 0:
execl( ........ );

printf("starting executing of process with pid.. %d",pid);

while(wait_list!=(List *)0)

pid = waitpid(0,&wait_val,__WALL);
if(pid == -1)
//printf("do we reach here..\n");

switch ( pid ){
case 0: //printf("no child exited..\n");

default: //i.e somechild has exited. so remove child from wait_list
printf("process with pid - %d exited..removing from list\n",pid);


One questions about this piece of code

Sometimes in waitpid() call .. it gives an error and prints out... "No Child Processes "

But in each case i tried all child processes had finished execution before this error came... does anyone know why?



tuxfood 05-08-2005 03:59 PM

Sorry abt the heading.... its

" A program which exits only after all its children have exited.."

Can this be edited in the forum page anyway????

thnks and sorry


All times are GMT -5. The time now is 05:18 PM.