Thread Signal Handling

The items listed in this section explain the signal handling concepts.

  • A signal mask is associated with each thread.
  • The list of actions associated with each signal number is shared among all threads in the process.
  • If the signal action specifies termination, stop, or continue, the entire process, thus including all its threads, is respectively terminated, stopped, or continued.
  • Synchronous signals attributable to a particular thread (such as a hardware fault) are delivered to the thread that caused the signal to be generated.
  • Signals can be directed to a particular thread. If the target thread has blocked the signal from delivery, the signal remains pending on the thread until the thread unblocks the signal from delivery, or the action associated with the signal is set to ignore by any thread within the process.

The signal mask of a thread is handled by the limit_sigs and sigsetmask kernel services. The kthread_kill kernel service can be used to direct a signal to a particular thread.

In the kernel environment, when a signal is received, no action is taken (no termination or handler invocation), even for the SIGKILL signal. A thread in kernel environment, especially kernel-only threads, must poll for signals so that signals can be delivered. Polling ensures the proper kernel-mode serialization. For example, SIGKILL will not be delivered to a kernel-only thread that does not poll for signals. Therefore, SIGKILL is not necessarily an effective means for terminating a kernel-only thread.

Signals whose actions are applied at generation time (rather than delivery time) have the same effect regardless of whether the target is in kernel or user mode. A kernel-only thread can poll for unmasked signals that are waiting to be delivered by calling the sig_chk kernel service. This service returns the signal number of a pending signal that was not blocked or ignored. The thread then uses the signal number to determine which action should be taken. The kernel does not automatically call signal handlers for a thread in kernel mode as it does for user mode.

See Kernel Process Signal and Exception Handling for more information about signal handling at process level.