monitor custom programs with ps and watch

March 26th, 2007 mysurface Posted in Admin, ps, watch | Hits: 93071 | 19 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.

19 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

  9. Hey There. I discovered your blog using msn. This is
    an extremely well written article. I will be
    sure to bookmark it and come back to learn extra
    of your helpful information. Thank you for the post. I will certainly comeback.

  10. Every weekend i used to pay a visit this web page, for the reason that
    i want enjoyment, as this this site conations genuinely nice funny stuff too.

  11. An outstanding share! I’ve just forwarded this onto a colleague who
    was doing a little research on this. And he actually ordered me lunch because I
    found it for him… lol. So allow me to reword this….
    Thank YOU for the meal!! But yeah, thanx for spending some time to discuss this issue here on your web page.

  12. I just like the valuable information you supply in your articles.
    I’ll bookmark your blog and take a look at again right here regularly.
    I’m somewhat certain I will be told lots of new stuff right right here!
    Best of luck for the next!

  13. Excellent weblog right here! Also your website quite a bit
    up very fast! What host are you the use of? Can I am getting your associate link
    for your host? I wish my web site loaded up as fast as yours lol

  14. Hi there friends, its fantastic piece of writing concerning
    teachingand completely defined, keep it up all the time.

  15. I’m really loving the theme/design of your site. Do you ever run into
    any web browser compatibility problems? A few of my blog audience have complained about
    my blog not working correctly in Explorer but looks great in Firefox.
    Do you have any solutions to help fix this issue?

  16. Do you mind if I quote a few of your articles as long as I provide credit
    and sources back to your blog? My website is in the very same area of interest
    as yours and my visitors would definitely benefit from some of
    the information you present here. Please let me know if this okay with you.
    Appreciate it!

  17. I am not certain the place you are getting your info,
    but good topic. I must spend a while finding out
    much more or working out more. Thanks for excellent information I used to be on the lookout for this information for my mission.

  18. What’s up everyone, it’s my first pay a quick visit at this site, and post is actually fruitful for me,
    keep up posting these types of posts.

Leave a Reply