Search code examples
shellsignalssystem-callssigaction

Sigaction vs Signal


Can someone please explain the difference between sigaction and signal. I know they signal works differently depending on which machine you are working on i.e. Mac, Windows, or Linux and that sigaction works the same on all platforms. But my question is why is that, because I have tried using signal on different platforms and have gotten the same result. Also which one would you guys recommend using for better practice.


Solution

  • I know few things about sigaction and signal. But what i know is that:

    • sigaction call is more complex to use than signal call (as you already know).
    • sigactionallows you to obtain more information about the signal received by your program (see siginfo_t structure).
    • According to Michael KERRISK's book : "The Linux Programming Interface" (Ch. 22, page: 456) : "...it is good practice always to use sigaction, rather than signal to establish signal handlers."
    • Finally (again from Michael KERRISK's book): "The Linux kernel contains an implementation of signal as system call, this implementation provides the older, unreliable semantics. However, glibc bypasses this system call by providing a signal library function that calls sigaction "

    Hope it helps.