Create a pidof command to find PID numbers easily

Jun 19, '03 10:33:00AM

Contributed by: adamjacobmuller

After having working in UNIX enviroments for the past dozen years, when I got my new PowerBook, I was sorely dissapointed to find that there was no pidof command. Even with the Dev Tools, even with Fink, even with a week of searching Google. So I wrote my own.

#!/bin/sh
ps axc|awk "{if (\$5==\"$1\") print \$1}";
Place this in a script (/bin/pidof is a good idea) and chmod it 755 (chmod 755 /bin/pidof) (or 700 if you are paranoid). Once in place, you can find the PID number of any running program by typing (for example) pidof iTunes; if you want to kill a program, you can just type kill `pidof iTunes`.

A lot of the custom scripts I have written in the past years work well on OS X; in particular one program that I love is gjukebox, a web-based MP3 jukebox that works on OS X with a few tweaks -- except for the lack of a pidof command.

[robg adds: I tested this one, and it worked as expected.]

Comments (23)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030618114543169