What does `kill -0 $pid` in a shell script do?

gjain picture gjain · Jun 13, 2012 · Viewed 57.5k times · Source

Basically, what signal does '0' represent, because here I see SIGNAL numbers starting from 1.

Answer

dwalter picture dwalter · Jun 13, 2012

sending the signal 0 to a given PID just checks if any process with the given PID is running and you have the permission to send a signal to it.

For more information see the following manpages:

kill(1)
$ man 1 kill
...
If sig is 0, then no signal is sent, but error checking is still performed.
...
kill(2)
$ man 2 kill
...
If sig is 0, then no signal is sent, but error checking is still performed; this 
can be used to check for the existence of a process ID or process group ID.
...