Making “top” watch instances of a particular command


top -p $(ps --no-headers -o pid -C exim | head -20 | paste -s -d ,)

UPDATE 2008-08-10: Used explicit HTML entities to work around WordPress’s “improvements”. Added ” head -20″ to deal with top’s limit on the number of PIDs that it will track.


7 Responses to “Making “top” watch instances of a particular command”

  1. j2 Says:

    Curiously, when I paste this (on OSX to FreeBSD machine if it matters) I get this:

    top -p $(no-headers -o pid -C exim | paste -s -d ,)ps


    top -p $(ps –no-headers -o pid -C exim | paste -s -d ,)

    Oh and neither works. I’ll have to dig out a linux box, I’m curious to see it.

  2. Anand Kumria Says:

    What version of ps are you using?

    I get the headers (PID) and I have no idea what paste is doing.

  3. razcx Says:

    J: the updated HTML should probably now paste correctly. I believe that all of the ps options that I’ve used, in particular no-headers instead of h, are platform independent.

    Anand: procps 1:3.2.7-5ubuntu3 , but if you’re seeing the headers it suggests that WordPress’s fiddling is breaking the PS options. Try again. Make certain that you have a double-hyphen preceeding no-headers.

  4. Roland Turner Says:

    Anand: “paste” in this mode simply puts the entire contents of stdin onto one line, newlines replaced with the delimiter, comma in this case.

  5. j2 Says:

    hmmm… New version pastes correctly but it looks like my ps implementation disagrees with its own man page and even the -help… The format suffixing -o is apparently ignored. Oh well.

  6. Roland Turner Says:


  7. Roland Turner Says:

    (Oh, is there an issue with PS’s “personality” in a BSD environment?)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: