* Amos Shapira <[EMAIL PROTECTED]> [070218 05:18]:
> On 17/02/07, Peter <[EMAIL PROTECTED]> wrote:
> >
> >
> >On Fri, 16 Feb 2007, Baruch Even wrote:
> >
> >> You assume that the signal was received in the recv() call, you'll have
> >> a race condition where a child might die just before you go into recv()
> >> and the child is never reaped. The chance might be small to miniscule
> >> but it's still there.
> >
> >That's why you must use both a reaper and select() with timeout.
> 
> 
> What's the point of select(2) with a timeout? How long should the timeout be
> set and what should be checked when it's reached? Why wouldn't a child
> reaper be enough in the situation Baruch describes?

You want to avoid another case of race condition.

Without a select you will have code like:

handle_sigchld() { dead_child=1; wait(); }
dorecv() {
        if (!dead_child) {
                recv();
        }
}

The problem now can be that the 'if (!dead_child)' is executed, then the
signal comes and then the recv() is executed since we already thought
that the child is alive.

A select with a timeout will rescue you since you will go into the
select but you'll come out of it and be able to test the variable again
to learn that the child is dead.

Baruch

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to