Top Ten Processes Watcher

July 13th, 2008 mysurface Posted in head, tail, top, watch | Hits: 162873 | 7 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"

7 Responses to “Top Ten Processes Watcher”

  1. 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 :-) ?


  2. great codes…

  3. how to create a script process top when a memory usage 80% process top can send e-mail alert to administrator?


  4. Please let me know if you’re looking for a article author for your site.
    You have some really good articles and I think I would be a good asset.

    If you ever want to take some of the load off, I’d really like to write
    some content for your blog in exchange for a link back to mine.
    Please shoot me an email if interested. Thank you!

  5. thank you

  6. It offers complete compatibility of Spotify, Deezer Rdio, Rhapshody, Enjoy musical, and more.

Leave a Reply