Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The signal() function has implementation-defined behavior and behaves differently in , for example, on Windows than it does on Linux/BSD systems. When a signal handler is installed with the signal() function in Windows, the default action is restored for that signal after the signal is triggered. Conversely, Linux/BSD systems leave the signal handler defined by the user in place until it is explicitly removed.

...

Different actions must be taken depending on whether or not you desire signal handlers to be persistent.

Persistent

...

Handlers

By default, *nix systems leave the handler in place after a signal is generated, whereas Windows system do not.

...

Code Block
bgColor#ccccff
void handler(int signum) {
#ifdef#ifndef WINDOWS
  /* windows automatically resets handlers to default */
#else
  signal(signum, SIG_DFL);
#endif
  /* handling code */
}

Windows automatically resets handlers to default.

Risk Analysis

Failure to understand implementation-specific details regarding signal handler persistence can lead to unexpected behavior.

...