Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Linux, I use ps -C command_name to select processes of specified command name. But it doesn't work in Mac OS X. I read the the man page of ps carefully, but just can not find any option to do this.

So anyone know if there is way to select specified processes by command name when using ps in Mac OS X?

share|improve this question
Try ps | grep command_name – Oliver Salzburg Jul 26 '12 at 9:37
ps | grep command_name will include the ps | grep command_name itself. – khotyn Jul 26 '12 at 10:49
ps | grep command_name | grep -v grep is the simple solution for that. /cc @oli – slhck Jul 26 '12 at 11:17
@slhck Thanks, it works! – khotyn Jul 26 '12 at 13:57

An easy way to filter the output of ps is to use a tool that can generally filter input, grep.

To do this, we just pipe the output of ps into grep, like so:

oliver@cloud:~$ ps | grep bash
31131 pts/0    00:00:00 bash

In case you're listing all processes, you'll quickly run into an issue though:

oliver@cloud:~$ ps a | grep bash
 2729 pts/0    S+     0:00 grep bash
31131 pts/0    Ss     0:00 -bash

Now it returns grep itself as well! How do we fix it?

Simply by using grep yet again, to filter out the excess result:

oliver@cloud:~$ ps a | grep bash | grep -v grep
31131 pts/0    Ss     0:00 -bash
share|improve this answer
Thanks, @slkch already give this answer, but I'll accept yours anyway. – khotyn Jul 26 '12 at 15:29

I have faced the same problem. Here is a solution, not totally satisfying:

ps -p `pidof <command_name> | tr ' ' ','`

This does not work all the time (e.g. when the command name is actually a call to an interpreter), and it is rather ugly. I hope it can give ideas and yield better solutions!

share|improve this answer

<- OSX -> To get PID of running binary called Humans by matching binary aka COMMAND name.

helios:~ TimberWolf$ killall -s Humans

-> Just the number

helios:~ TimberWolf$ killall -s Humans | tr -d [:alpha:][:space:]-

-> Use PID with ps command for more refined details such as priority of the binary.

helios:~ TimberWolf$ ps killall -s Humans | tr -d [:alpha:][:space:]-

share|improve this answer
from man killall : -s Show only what would be done, but do not send any signal. – harschware Feb 25 '15 at 0:33

In the general case, it seems you can't really do this without using grep as an aide or piping/shelling to a second second linux command to help out. If your attempting to do this by launching a process from some other language, e.g. Java, you may need to avoid using any shellisms and hence need to do it one command. Therefore consider pgrep as an alternative. e.g. To list all java processes:

pgrep java
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .