I'm trying to figure out how to block a signal in Linux kernel 2.4 (user space) from invoking its handler, but keep it available to be handled later, preferably as soon as I re activate the handling of said signal.
The function sigprocmask seem to come up in all my search results, but I can't find a good, clear description that explains whether the blocked signal gets "saved" to be handled later, and if so where and how do I handle it when I'm ready for it.
Can someone ple开发者_运维百科ase clarify what's going on, preferably with a code example? Thanks in advance.
I really can't say it better than the signal(7)
man page:
A signal may be blocked, which means that it will not be delivered until it is later unblocked. Between the time when it is generated and when it is delivered a signal is said to be pending.
Each thread in a process has an independent signal mask, which indicates the set of signals that the thread is currently blocking. A thread can manipulate its signal mask using
pthread_sigmask(3)
. In a traditional single-threaded application,sigprocmask(2)
can be used to manipulate the signal mask.
So, you can block and unblock the signal with sigprocmask()
. If the signal is raised while it's blocked, the handler won't be called until it's unblocked. If a signal is pending when it's unblocked, the handler for the signal will be called as usual.
Note that a given signal is either pending or not; it can't be "pending twice" (or more). if the signal is raised twice while it is blocked, it'll still only be delivered once.
精彩评论