Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
ps | grep command_name | grep -v grep is the simple solution for that. /cc @oli –  slhck Jul 26 '12 at 11:17
1  
@slhck Thanks, it works! –  khotyn Jul 26 '12 at 13:57
add comment

3 Answers

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
add comment

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
add comment

<- 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.