I am sure you all have used the kill command to kill or reload processes, but have you ever used to monitor the state of a process using kill command ? Most of the times, the answer will be NO.

But we can use kill command to verify whether the process ID is a valid entry in the process table or whether a process is accepting signals or in hung state. There is no reference for this in the kill man page, you need to check info pages. Info pages states that signal 0 is special and that if you pass this signal to the process ID through kill command, then the return code from the command could tell you whether a process is accepting the signals.


$ echo $$
$ /bin/zsh
$ echo $$
$ kill -0 12023
$ echo $?
$ exit
$ kill -0 12023
kill: kill 12023 failed: no such process
$ echo $?

This is one of the very lightest way to monitor a process from their process ids.


Q. Will this kill or impact the running process in any way ?

A. No, It will just check whether the process is accepting signals and alive.

Q. There are lots of other way of monitoring a process, why should I use this ?

A. Firstly, it’s easy. Secondly,┬áit’s very much light on the system, instead of going through parsing result from ps.


  1. Linux Journal
If you enjoyed this post, make sure you subscribe to my RSS feed!!!!