Super Cool way to use TOP utility in Linux

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as list of tasks currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable and that configuration can be made persistent across restarts.
The program provides a limited interactive interface for process manipulation as  well as a much more extensive interface for personal configuration, encompassing every aspect of its operation. It refreshes its output every 3 seconds by default.

What we normally do is, run the top utility, check the report for few moments and then quit the top utility. What if we wanted the top reports to be collected periodically, and write it to a log file every now and then. We have several ways available to do the same like schedule a job via crontab or create a script for the purpose. 

Is there an easier way for the same?

Well, yes there is. The same can be achieved using top in batch mode. Let me show you what this actually is. top command can be used, non-interactively, in batch mode. Time delay, refresh rate and the number of iterations can be configured making the utility much flexible for desired output.

Here is an example:

top -b -d 10 -n 3 >> top-file

 Here, top is running in batch mode (-b). It's going to refresh every 10 seconds, as specified by the delay (-d) flag, for a total count of 3 iterations (-n). The output will be sent to a file - top-file.

This is the output you get in the top-file.

Read More:

The power of PROC file system in Linux
Working with modules in Linux made easy


open source 5303240536381143304

Post a Comment



Recent Posts


Join Us