It's often required to know the ID number of a certain process. In many *NIX distributions, this is done using the "pidof" utility which OS X lacks. While we have "killall" which is useful for sending signals to processes by name, what if we just need the ID number? To get it, simply add this line to you ~/.bash_profile file:
pidof () { ps -Ac | egrep -i $@ | awk '{print $1}'; }
Then calling "pidof procname" will give you the PID(s) of the processes whose names contain "procname" (ignoring case). You can also use it to quickly check if a process is running.
ooooh, very handy! i like it! it’s going right into /etc/profile, fire up nano…
—
Mat X – Mac VFX SysAdmin
What if the default shell is tcsh?
If I put that line in .tcshrc I get an
tcsh: Illegal variable name.
error.If you use tcsh, put the code into a shell script file to be run by bash, and
execute that. If properly set up (script is in your
$path
, etc.)the effect is the same. The script would look like:
Thanks, it worked!
And the p.s. — What about ps? section of Daring
Fireball: Processing Processes mentions other caveats on this topic.