In a program, SIGCHLD is blocked from main thread, then
- thread “THREAD_1” is doing sigwait(),
- thread “THREAD_2” which forks a child process and kills it, in this thread I called pthread_sigmask(SIG_UNBLOCK, &set, 0) to unblock SIGCHLD before killing the child.
But SIGCHLD is still being picked up by sigwait().
Other than unblock SIGCHLD from main() before creating threads, is there a way to make SIGCHLD bypass sigwait() ? I do not want sigwait() to handle SIGCHILD.
Thanks,
Advertisement
Answer
This behavior is permissible per the spec:
Signals generated for the process shall be delivered to exactly one of those threads within the process which [thread] is in a call to a sigwait() function selecting that signal or [which thread] has not blocked delivery of the signal.
(Emphasis added.)
Simply remove SIGCHLD from the waiting thread’s selection mask and the program will do what you want.