3

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 please clarify what's going on, preferably with a code example? Thanks in advance.

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.