LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-18-2006, 02:41 PM   #1
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Rep: Reputation: 30
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?
 
Old 09-18-2006, 02:42 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,397

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
Code:
pidof <process name> | wc -w
 
Old 09-18-2006, 03:31 PM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Rep: Reputation: 63
variations about this theme....

Code:
$ pgrep <process_name> | wc -l

Last edited by marozsas; 09-18-2006 at 03:35 PM.
 
Old 09-18-2006, 04:17 PM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,004

Rep: Reputation: 304Reputation: 304Reputation: 304Reputation: 304
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
$
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
count total number of lines in several files xushi Programming 5 11-12-2005 04:42 PM
Javasript to count number of mouse clicks LinuxLala Programming 3 06-17-2005 12:23 AM
C++ STL count() number of substring occurences... nyk Programming 4 06-25-2004 07:12 AM
help on finding the number that has max occurrences in a column [sql query] zeppelin Programming 6 06-15-2004 01:41 PM
Count number of line in a file. philipina Programming 7 03-18-2004 05:04 PM


All times are GMT -5. The time now is 04:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration