The functions signal
, sigset
(and its relatives), and sigaction
all establish or remove signal handlers.
signal
is the only one of these functions specified by ISO C, and therefore the most portable, but it is also the most limited, and crucial aspects of its behavior are underspecified (e.g. whether or not it establishes signals that interrupt blocking system calls).
The sigset
family was part of POSIX but is now marked obsolescent. These functions were never reliably available cross-platform, and didn't fix all of the underspecification problems with signal
. Don't use them.
sigaction
is in POSIX.1, offers more functionality than any other option, and its behavior is well-specified including all of the corner cases. It should be used if at all possible. Since it's not in ISO C, but is in POSIX.1-2001, to first order you can use it everywhere with the critical exception of Windows. However, signal handlers shouldn't be used at all on Windows, because they are not system primitives there and do not work reliably; it is my understanding that one should use structured exception handling and asynchronous procedure calls instead, depending on what one is trying to do.
Your lecturer is teaching specifically POSIX system programming, so they should update their sample code and lectures to refer only to sigaction
. They really ought to cover sigprocmask
, sigtimedwait
, and pselect
as well.