the best form to wait the finish of execution of a child...
Florent Thoumie
flz at xbsd.org
Wed Mar 30 10:28:36 PST 2005
Le Mercredi 30 mars 2005 à 14:17 -0400, zean zean a écrit :
> Hi Hackers:
>
> Excuse for my badly English. which is the best form to wait the
> finish of execution of a child.
It depends on the context of your program
(synchronous/asynchronous).
> My idea is:
>
> pid_t chilpid;
>
> while(childpid != wait(&status))
> ;
That's a possibility, you can catch SIGCHLD with a signal
handler (see signal(3), sigprocmask(2), sigaction(2)) which
would set a global flag, and then use a non-blocking waitpid(2)
or wait4(2) instead.
Note: What you suggested isn't really safe. You shouldn't
ignore wait(2) return status (could be -1 because something
unexpected happened, see ERRORS section from the manpage).
--
Florent Thoumie
flz at xbsd.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20050330/3cda5edf/attachment.bin
More information about the freebsd-hackers
mailing list