I have a thread in an application that has a loop like this:
... while (1) { checkDatabase(); checkChildren(); sleep(3); } ...
checkDatabase() is self-explanatory; checkChildren() simply calls waitpid(-1, &status, WNOHANG) to process child processes that either waitpid(-1, &status, WNOHANG) or receive a signal.
The application works quite well, but has a default signal processing. The problem is that this parent process has multiple threads (don't worry about child processes at the moment), and I have no experience with synchronous signals, not to mention the POSIX thread application. I used signal() before, but apparently it is not portable, and in any case, it does not do what I need. I have no experience whatsoever with sigaction methods, and I cannot find good documentation on how to fill structures, etc.
I need to make it so that it synchronously captures trailing signals such as SIGINT , SIGTERM and SIGQUIT in the above loop (and I need to completely ignore SIGPIPE so that I can catch the EPIPE error from the IO methods), so it will look like this:
... while (1) { checkDatabase(); checkChildren(); checkForSignals(); sleep(3); } ...
All other threads should have nothing to do with the signal; only the thread that runs this loop needs to know about it. And, obviously, this should be a non-blocking check, so the loop is not blocked during the first iteration. The method, called if a signal is detected, will sort the other threads and destroy the mutexes, and all that.
Can someone please give me heads-up? Thank you very much.