Backoff Signal Handling in Linux
I am trying to figure out how to block a signal in Linux 2.4 kernel (user space) from invoking its handler, but keep it available for processing later, preferably as soon as I reactivate the specified signal handling.
The sigprocmask function seems to show up in all of my search results, but I can't find a good, clear description explaining whether a blocked signal will be "saved" for processing later, and if so, where and how to handle it when I ready for it.
Can someone please clarify what's going on, preferably with a sample code? Thanks in advance.
a source to share
I really can't say it better than the man page signal(7)
:
The signal can be blocked, which means that it will not be delivered until it is unblocked. Between the time of its creation and when it is delivered, the signal is said to be pending.
Each thread in the process has an independent signal mask that indicates the set of signals that the thread is currently blocking. a thread can manipulate its signal mask using
pthread_sigmask(3)
. A traditional single-threaded applicationsigprocmask(2)
can be used to control the signal mask.
So, you can block and unblock the signal with sigprocmask()
. If the signal is raised when it is blocked, the handler will not be called until it is unblocked. If the signal is ready when it is enabled, the handler for the signal will be invoked as usual.
Note that this signal is either pending or not; it cannot be "waiting twice" (or more). if the signal is raised twice when blocked, it will still only be delivered once.
a source to share