views:

50

answers:

3

I was looking for the best way to find the number of running processes with the same name via the command line in Linux. For example if I wanted to find the number of bash processes running and get "5". Currently I have a script that does a 'pidof ' and then does a count on the tokenized string. This works fine but I was wondering if there was a better way that can be done entirely via the command line. Thanks in advance for your help.

+1  A: 
result=`ps -Al | grep command-name | wc -l`
echo $result
Amardeep
+5  A: 
ps -C command_name --no-headers | wc -l
David Zaslavsky
+1  A: 
ps -Al | grep -c bash
Alex B