Search code examples
csignalssigaction

Is sigaction preferred over signal function?


The following is from the man page of signal

The behavior of signal() varies across UNIX versions, and has also varied historically across different versions of Linux. Avoid its use: use sigac‐ tion(2) instead. See Portability below.

Does that mean that we should always use the sigaction call instead of using signal ?


Solution

  • Yes. You've already identified the Linux reference, and POSIX says the same thing:

    The sigaction() function supersedes the signal() function, and should be used in preference.

    sigaction addresses the historical inconsistencies in signal by forcing the user to make decisions about syscall interruption (SA_RESTART), handler interruption (sa_mask, SA_NODEFER), child handling (SA_NOCLD[WAIT|STOP]), disposition permanence (SA_RESETHAND), and more.