Re: pipe question said:
> You want to set up a signal handler for SIGCHLD.  It will be called
> when a child process dies.  Just call wait() to get the child's exit
> status, then do something to make the rest of your program aware of
> that the child has died (set a variable to something, or add an idle
> function).  The signal handler should not run for too long though.

> James. 

The 'should not run for too long' is a good point.  One nice way to do
this is to have the sigchld handler do nothing more than set a flag,
I'll call it sigchld_flag.  Typically, the program is blocked on a
read in which case the read() will return with errno set to EINTR and
you can just check whether sigchld_flag was set. You shoud check for
EIO, too.

I usually set the signal to call set_sigchld_flag() and when I find
the flag is set I call sigchld_handler().  This way,
set_sigchld_flag() is short and sweet and sigchld_handler() can do
whatever it wants to:  send email, call home, and balance the
checkbook for the last 12 years.  You laugh, you don't know what
someone else might do to the code. 

Mike Sangrey

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]