Are you there?
Checking for a process's very existence, is it alive now?, can be crucial to an application. For example, an application function receives the PID of a process as a parameter. Before it actually does something with the process via the provided PID (perhaps send it a signal), it would be a good idea to verify that the process is indeed valid (what if it's dead or the PID invalid?).
The kill(2) system call helps us in this regard: the second parameter to kill is the signal to send; using the value 0 (recall there is no signal numbered 0) validates the first parameter: the PID. How exactly? If the kill(2) returns failure, either the PID is invalid or we do not have permission to send the process (or process group) a signal.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access