AFP548 Changing the world one server at a time.

Scripting and Automation

Make Your Own pidof Utility

By filipp 1 min read

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.

0 comments

    1. 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:

      #!/bin/bash
      ps -Ac | egrep -i $@ | awk '{print $1}'

Leave a Reply