FUSER instead of  PS for PID

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.

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.