Fork and child process
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Fork and child process




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Fork and child process  
Doug Ly


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-23-04 09:33 PM

Hi,
I've learned that to wait for all the children, we put wait(0) in the main()
function.
But my program gives me weird result. It seems like main() exits when there
are children are still running.
Is there a way to check if a program has collected all of its children
before it can exit?

Thanks







[ Post a follow-up to this message ]



    Re: Fork and child process  
Dragan Cvetkovic


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-23-04 11:34 PM

"Doug Ly" <dmly@sbcglobal.net> writes:

> Hi,
> I've learned that to wait for all the children, we put wait(0) in the main
()
> function.
> But my program gives me weird result. It seems like main() exits when ther
e
> are children are still running.
> Is there a way to check if a program has collected all of its children
> before it can exit?
>

According to wait(3c) man page:

The wait() function will suspend execution  of  the  calling
thread  until  status  information for one of its terminated
child processes is available, or until delivery of a  signal
whose action is either to execute a signal-catching function
or to terminate the process. If  more  than  one  thread  is
suspended in wait(), waitpid(3C), or waitid(2) awaiting ter-
mination of the same process, exactly one thread will return
the  process status at the time of the target process termi-
nation. If status information is available prior to the call
to wait(), return will be immediate.

So, if you want to wait for all children, you have to loop (wait sets errno
to ECHILD if there are no existing unwaited-for child processes).

HTH, Dragan


--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:52 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register