0

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 ?

pensee
  • 47
  • 4
  • If the man page says you should avoid it, then you should avoid it. It does not necessarily mean “always.” Most commonly when an old routine has been supplanted by a new routine, there is no need to use the old routine except when working in special situations such as working with old systems where the new routine is not available. To avoid `signal`, simply write your code to use `sigaction` when there is a choice. If there is no choice, because something prevents you from using `sigaction` to get the desired result, then use `signal`. – Eric Postpischil Dec 13 '20 at 12:34

1 Answers1

0

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.

pilcrow
  • 56,591
  • 13
  • 94
  • 135