Top Ten Processes Watcher
July 13th, 2008 mysurface Posted in head, tail, top, watch | Hits: 117678 | 3 Comments »
top command provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. But if you want get something more specific, you must play some tricks on it. For example, I want a clean view of top ten busiest processes every seconds without those summary info, how should I do with top?
Batch mode operation
top is a real-time application that keeps display processes info sorted by cpu usage, if you redirects the outputs to a file like command line below, you will having your results mixed with ugly symbols, which is not what you want.
top > top.txt
Well, top support batch mode. By specified top on batch mode, top will display the outputs without arrange the views properly, but if you redirects it to a file, you won’t get those messy symbols mixed up.
top -b > top.txt
I just want to monitor top ten processes every seconds!
You can limits your views of top ten using head and tail, but this will STOP top from continuing to monitor the processes.
top -d 1 | head -n 17 | tail -n 11
Fortunately, we have watch to help, but you needs to put top in batch mode, and also you can ask top to stop after done displaying the result for one time. This will increase the accuracy of the result.
watch -n 1 "top -b -n 1 | head -n 17 | tail -n 11"







August 4th, 2010 at 11:37 pm
Nice bit of code….
But I\’ve got a bit of an issue; I\’m trying to run the command (for 70+ servers) from a .bat file, which calls a .txt file with the following command
watch -n 1 \"top -b -n 1 | head -n 17 | tail -n 11\"
My problem is, when run directly from a Putty window its fine, however, when read from a .txt file I get an error: \"Error opening terminal: unknown\", I\’m assuming this might be down to the quotes (\") either end of the top command…..
Has anyone had a similar issue…and managed to resolve it :-) ?
Cheers
March 20th, 2011 at 2:26 pm
great codes…
July 5th, 2012 at 11:55 am
how to create a script process top when a memory usage 80% process top can send e-mail alert to administrator?
thanks
cyd