|
Signal Handling with LinuxThrreads
Hi.
I have a multi-threaded daemon which starts child processes and reads the output from them via a pipe, with a controlling thread for each child process. The daemon needs to listen for SIGCHLD to tell when the child has been stopped/continued or has exited.
The problem I'm having is that LinuxThreads doesn't send the SIGCHLD to the daemon process, but instead sends it to the thread that started the child - which is contrary to POSIX.
I can't handle the SIGCHLD asynchronously because none of the pthread functions are asnyc-signal-safe, and at the very least I'd need to lock the variable I'm accessing. So, it looks like I'll have to have two threads for each child - one to read its output via the pipe, and another to sit and wait synchronously with sigwait(). However, the docs for sigwait() say that you should only have one thread in the whole process waiting for a particular signal at any one time - but I would have as many sigwait()s as I have child processes.
It seems then that there's no safe way to proceed. Can anyone suggest another way of doing this?
|