01-23-04 10:36 PM
On Sun, 18 Jan 2004 00:44:32 -0500, Michael B Allen wrote:
quote:
> On Sat, 17 Jan 2004 08:29:09 -0500, Valentin Nechayev wrote:
>
> Ok, so I write the pid of the process that exited to a pipe and then read
> that in the main loop, call wait and collect the information? Mmm, that
> sounds reasonable.
No, don't do that as you'll have big problems if you get a lot of signals
at once (Ie. the pipe will become full and block -- which will be a
deadlock). There are also nasty problems lurking with PIPE_BUF and
pid separation.
The way it's "commonly" done is to write a single byte down the pipe
(non-blocking). Then when the select comes back, you just call...
int status = 0;
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
{ /* pid is now the pid of a proc. */
}
...and lookup the process from the pid. For more selection you can use
process groups etc. ... see man waitpid.
--
James Antill -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/
[ Post a follow-up to this message ]
|