There is another way to look for the PID of a particular process instead of piping the output of the ps command into grep and chopping it up. Solaris 2.x (and maybe some other SVR4s) can use the fuser(1) command. Simply use the following command from a Bourne Shell:
fuser /path/to/executable 2>/dev/null
The fuser command prints out the PID of all processes that currently have opened the named file, and all processes have their own executable's text segment open.
The fuser command will also print out the PID of all processes that have a file or files open for reading, or that are using the named directory as the current directory. The PIDs are printed on standard output. Formatting and the name of the file(s) are printed on standard error. It also takes a switch -k to send the KILL signal to all PIDs found.
This is much more reliable than grepping the ps output.
Return to : Unix
System Administration Hints and Tips