Just kill 'em

How do we send a signal to another process: the short answer, via the kill(2) system call. The kill API can deliver a signal, any signal, to a process given its PID; the function signature from the man page on kill(2):

#include <sys/types.h>#include <signal.h>int kill(pid_t pid, int sig);

Note it's very generic—you can send pretty much any signal to any process (it might perhaps have been better named as sendsig, but, of course, that's not as exciting a name as kill).

The user command kill(1) is, of course, a wrapper over the kill(2) system call.

Quite obviously, from the previous API, you can infer that the signal sig is sent to the process that has the PID value pid. Hang on, though, there are several special cases to consider ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.