ps
or top
are often the first utilities a Linux administrator reaches for when looking at what’s happening on a system. It’s very much the text equivalent of Windows Task Manager. The problem is top
can be very busy, with constant changes in the order of things not helping the situation. Fortunately there are some commands one can use to filter top
to a specific process only. As an alternative we recommend using ps
instead.
Here is a super handy ps
running:
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head
This will check what’s potting and stop the output.
For top
, the command to view realtime with a filter do this:
top -p `pgrep -d "," gzip`
Now, instead of being overwhelmed by things moving up and down, you can focus your attention on just the one process that matters.
This command has interesting behavior. If you run it continuously while the process is happening, it will work. But once the process stops, you get this awkward error:
> top -p `pgrep -d "," gzip` top: -p requires argument
Don’t get fooled. The process might have run but has now stopped.
If what you’re after is actually monitoring two or more processes, try this command:
top -p $(pgrep -d, "(backup-domain|tar|zip|ssh)" )
If the example, above, the system administrator is watching four processes, backup-domain
, tar
, zip
, and ssh
to see the process of a backup job that first uses both tar
and zip
, and then SSH
to transfer to another server.
Don’t forget to press ‘c’ on the keyboard to get more information about the running process.
Now if we can get this command sequence to dynamically update as the processes come and go….please leave us a comment.