Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fork() & wait() 1

Status
Not open for further replies.

cmancre

Programmer
Jan 30, 2005
35
PT
Hello
code:

while(condition){
pID=fork();
if(!pID){
/* do something */
exit(number);
}
}
wait(number);

Imagine that my while loop creats 4 childs processes. The execution time of each child are diferent, so child nº2 could end first than child nº1. My question is, how my parent process waits for all childs?
 
You need to wait (if you want to wait) for each child process - you cannot (well you can) wait for just one child and hope to catch the other three !

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Read the manual page for waitpid() and study which magic values allow you to wait for any child.

If you have 4 children, waitpid() 4 times.


--
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top