LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-08-2005, 04:56 PM   #1
tuxfood
Member
 
Registered: Aug 2003
Location: kerala , India
Distribution: RH9 , FC1 ,
Posts: 141

Rep: Reputation: 15
A program which exists only after all its children have exited.. plz comment


hi...

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

/**************************************************************\

for(;..........)
{
.......

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

default:
//parent
printf("starting executing of process with pid.. %d",pid);
AddtoList(pid);
break;
}
}

while(wait_list!=(List *)0)
{

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

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

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


/***************************************************************\

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?


thnks

tuxfood
 
Old 05-08-2005, 04:59 PM   #2
tuxfood
Member
 
Registered: Aug 2003
Location: kerala , India
Distribution: RH9 , FC1 ,
Posts: 141

Original Poster
Rep: Reputation: 15
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

tuxfood
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
screen shooting program plz einstien Linux - Software 6 07-16-2012 10:05 AM
To find which all services depend on a particular service... a method ..plz comment tuxfood Red Hat 1 06-15-2005 11:47 PM
SIOCADDRT: File exists SIOCCADDRT: File Exists Failed to bring up eth0. opsraja Linux - Networking 0 01-10-2005 09:29 AM
Exists a DC++ like program for Linux? zWaR Linux - Newbie 4 12-27-2003 01:52 PM
program 4 autistic children???? Felipe78 Linux - Software 5 12-25-2003 04:00 AM


All times are GMT -5. The time now is 02:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration