LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to count the number of occurrences of a process (https://www.linuxquestions.org/questions/linux-general-1/how-to-count-the-number-of-occurrences-of-a-process-484725/)

beeblequix 09-18-2006 02:41 PM

how to count the number of occurrences of a process
 
I WAS going to ask how to do this but since I figured it out I present it to fellow n00bs(and myself in case I forget).

I wanted to know how many occurrences of a process that I have running--

command: ps -aux|grep 'some_process'|wc -l
explanation: 1)take the current listing of all processes in BSD format 2)search for all lines containing 'some_process' 3)then count how many lines 'some_process' occurs on.

Is there a better way to do this?

acid_kewpie 09-18-2006 02:42 PM

Code:

pidof <process name> | wc -w

marozsas 09-18-2006 03:31 PM

variations about this theme....

Code:

$ pgrep <process_name> | wc -l

haertig 09-18-2006 04:17 PM

Quote:

Originally Posted by beeblequix
ps -aux|grep 'some_process'|wc -l

This method can come up with a count that's one too hig (intermittantly). You will sometimes catch your "grep" in the count to!

I know I'm only running one copy of "init", but see below where my count would have been two by your method:
Code:

$ ps aux | grep init
root        1  0.0  0.0  1600  536 ?        S    Sep14  0:02 init [2]
haertig  22987  0.0  0.0  1928  600 pts/0    R+  15:13  0:00 grep init
$



All times are GMT -5. The time now is 03:10 AM.