Search code examples
macosbashshellcommand-lineopenbsd

How do I count specific processes on Mac OS X?


Using a Mac, what would be the best way to count the number of instances of a particular process I am running? This is for a script I am writing to find the number of ffmpeg processes running on my machine.

Should I be using top here? ps aux|grep ffmpeg? What would be the best way to get the number?


Solution

  • grep -c will count occurrences:

    count=`ps aux | grep -v "grep" | grep -c ffmpeg`
    echo $count