process monitoring with kill

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: