Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The kill() system call can serve another purpose. If the sig argument is specified as 0 (the so-called null signal), then no signal is sent. Instead, kill() merely performs error checking to see if the process can be signaled. Read another way, this means we can use the null signal to test if a process with a specific process ID exists. If sending a null signal fails with the error ESRCH, then we know the process doesn’t exist. If the call fails with the error EPERM (meaning the process exists, but we don’t have permission to send a signal to it) or succeeds (meaning we do have permission to send a signal to the process), then we know that the process exists.
Verifying the existence of a particular process ID doesn’t guarantee that a particular program is still running. Because the kernel recycles process IDs as processes are born and die, the same process ID may, over time, refer to a different process. Furthermore, a particular process ID may exist, but be a zombie (i.e., a process that has died, but whose parent has not yet performed a wait() to obtain its termination status, as described in Section 26.2).