process monitoring with kill
June 6, 2008 Leave a comment
Part of the reason why pid files often exist. This technique avoids parsing through ps output or rumaging around /proc.
From the man page:
Name Num Action Description
0 0 n/a exit code indicates if a signal may be sent
Here is example usage
lundeen2@lundeen-office:~$ ps
PID TTY TIME CMD
12833 pts/7 00:00:00 bash
12899 pts/7 00:00:00 ps
lundeen2@lundeen-office:~$ /bin/bash
lundeen2@lundeen-office:~$ ps
PID TTY TIME CMD
12833 pts/7 00:00:00 bash
12902 pts/7 00:00:00 bash
12968 pts/7 00:00:00 ps
lundeen2@lundeen-office:~$ kill -0 99999
bash: kill: (99999) – No such process
lundeen2@lundeen-office:~$ echo $?
1
lundeen2@lundeen-office:~$ kill -0 12902
lundeen2@lundeen-office:~$ echo $?
0
lundeen2@lundeen-office:~$ ps
PID TTY TIME CMD
12833 pts/7 00:00:00 bash
12902 pts/7 00:00:00 bash
12977 pts/7 00:00:00 ps