Linux – Can signal be ignored (lost)

linuxsignals

I have an application which is communicating with workers via signals (particullary SIGUSR1/SIGUSR2/SIGSTOP).

Can I trust that whatever happens every signal will be delivered and processed by handler?

What happens if signals are sent quicklier than is't possible for application to handle them (eg. due to high host load at the moment)?

Best Answer

Aside from the "too many signals" problem, signals can be explicitly ignored. From man 2 signal:

If the signal signum is delivered to the process, then one of the
following happens:    
  *  If the disposition is set to SIG_IGN, then the signal is ignored.

Signals can also be blocked. From man 7 signal;

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.

Both blocked and ignored sets of signals are inherited by child processes, so it may happen that the parent process of your application ignored or blocked one of these signals.

What happens when multiple signals are delivered before the process has finished handling previous ones? That depends on the OS. The signal(2) manpage linked above discusses it:

  • System V would reset the signal disposition to the default. Worse, rapid delivery of multiple signals would result in recursive (?) calls.
  • BSD would automatically block the signal until the handler is done.
  • On Linux, this depends on the compilation flags set for GNU libc, but I'd expect the BSD behaviour.
Related Question