There are many ways for processes to communicate on Unix. This post introduces a simple way to use signals. You can first read Beej’s introduction. As the name suggests, a signal is a notification sent and received by processes. For example, when you use a shell, Ctrl-C can interrupt a program because the shell catches the SIGINT signal triggered by Ctrl-C, recognizes it as an interrupt signal, and terminates the program.
To send signals, you can use sigaction() or signal(). I recommend sigaction because it’s newer. For a detailed comparison, see the Stack Overflow thread “What is the difference between sigaction and signal?”.
If you want to trigger a signal, you can use kill() or sigqueue(). The difference is that the latter is Linux-only, but it lets you attach additional information via siginfo. In addition, some system calls can trigger signals as well. For example, if you try to send() to a non-existent socket, you’ll get a SIGPIPE.
Continue reading