I know there are two system calls that can be used for this, but which one is preferred for portable code?
Asked
Active
Viewed 24 times
0
-
There is a standard C function `signal` which is a part of the language and therefore fully portable (on the systems that support signaling, of course) – Eugene Sh. May 10 '21 at 20:42
-
Is there another one I can use? – BettySwuttox May 10 '21 at 20:46
-
It depends on your portability requirements. Using `sigaction()` is generally best on POSIX systems because you gain more control over the signals. If you need to include Windows, then you will have to investigate harder — you may be stuck using C standard `signal()`, but that limits what you can rely on in the way of behaviour (and even more severely limits what you can do in signal handler functions). Using other sets of functions than `sigaction()` or `signal()` is likely a bad choice for portability. (Don't use `sigrelse()`, `sigignore()`, `sigpause()`, `sigset()` and `sighold()`.) – Jonathan Leffler May 10 '21 at 20:52