monitor custom programs with ps and watch

March 26th, 2007 mysurface Posted in Admin, ps, watch | Hits: 74560 | 9 Comments »

ps is a very useful tool to list all current running processes with various info such as CPU usage, memory usage, process status, process id etc.

watch is another good tool to continuously execute some programs in infinite loop. watch allows you to make use of commands such as ps, netstat, lsof into monitoring purpose.

The common use of ps is to list all executing processes in user-oriented format.

ps aux

To the extend of checking the “target” processes, let say “fluxbox”, we do this,

ps aux | grep fluxbox

With that, the lines with keyword “fluxbox” will be grepped. But, the first line of ps which use to display the field caption will be lost.

Output looks like this:

mysurface     4491  0.0  1.4  23516  7256 ?        Ss   21:15   0:02 /usr/bin/fluxbox
mysurface     5962  0.0  0.1   2800   768 pts/0    S+   21:51   0:00 grep fluxbox

You probably can remember which field indicate what, but I can’t. I couldn’t remember the value 1.4 is what. Furthermore, the last line, “grep fluxbox”, is not what I targeted.

As long as you know the exactly you want, you can use the command line as bellow:

ps u -C fluxbox

Same way I want it to be user-oriented and I ask ps to give me only my targeted “process”.

mysurface     4491  0.0  1.4  23516  7256 ?        Ss   21:15   0:02 /usr/bin/fluxbox

Neat and nice isn’t it? Thanks to bytee for the tip.

You can place a list of targeted processes. But bare in mind, its not like grep, you have put the exact process name.

ps u -C fluxbox,gaim,xchat

At last, you wanna monitor these command list, that is where watch take place,

watch -n 1 "ps u -C fluxbox,gaim,xchat"

-n is to specify the time interval, execute the line every 1 second. Ctrl+c to quit watch.

9 Responses to “monitor custom programs with ps and watch”

  1. Or how about a better one:
    ps aux | grep [f]luxbox

    Note that you can put the brackets around any one of the letters in the process you want to grep for. That will leave out the grep process just the same without having to remember different ps options.

    The joys of modern shells :)

  2. […] I have make the comparison between this application and a simple ncurses program, this program seems to use lesser memory. Couldn’t measure for CPU resources, as both ps and top shows 0.0 %. […]

  3. Good Command. Thanks

  4. […] But, ps capable of doing more, one of my favorite post, Monitor custom programs with ps and watch […]

  5. […] monitor custom programs with ps and watch ps is a very useful tool to list all current running processes with various info such as CPU usage, memory usage, proces… […]

  6. pgrep will return the pid of a named process.By default, multiple results are listed in a verticle column. You can make that more “ps friendly” by setting a comma as a delimiter ( the -d switch).
    Note that the examples use backticks, not single quotes.
    ps u -p `pgrep -d, tty`
    Or use the same idea in
    top p `pgrep -d, tty`
    You can get the same result with
    top p $(pgrep -d, tty)

  7. This points to the fact that it has already become a phenomenon in today’s times, and
    is poised to get even bigger in the days to come. It is true that a CMS can make life easier for the web designer who
    can hand over the deliverable to the customer in the knowledge that the customer has got everything they need to
    update the website themselves. This will increase your link percentage and your anchor text percentage.

  8. Vous avez un colle de canalisation bouchée sur le secteur de Paris 13 et la region de paris ?

    Planete service est une entreprise de serrurerie qualifiés qui intervient
    chez vous 24/7.

    Villes du 94 dans lesquelles nos vitrier se déplacent :
    electricien Vitry-sur-Seine

    Villes du 95 dans lesquelles nos serrurier se déplacent :

    plombier Sarcelles

    Villes du 92 dans lesquelles nos serrurier se déplacent :
    vitrier Asnières-sur-Seine

    Villes du 93 dans lesquelles nos volet metalique se déplacent :
    plombier Montreuil

    Villes du 78 dans lesquelles nos electricien se déplacent :
    serrurier Sartrouville

Leave a Reply