Sunday, 17 April 2016

How to monitor CPU and memory usage using top command ?


top command provides an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive tasks on the system, and can provide an interactive interface for manipulating processes.
By default top command displays the processes in the order of CPU usage.

Example : $ top

 



















Other forms of top command


Display selected user
$ top -u shaan
It displays a specific user processes only in the top command output.

Display only specific process with given PIDs
$ top -p 1309, 1882

Executing top command in batch mode
$ top -b -n 1

Quit top Command After a Specified Number of Iterations
$ top -n 2

Get top command help
$ top -h


Options for TOP command in interactive mode

When the top command is running, you can use following : 
Sorting of processes
1. To display processes sorted by memory usage, press M
2. To sort by any column, Press O and choose the column.
3. To sort in reverse order, press R

Kill a Task Without Exiting From Top
Press k, which will ask for the PID (process id) and signal to send.

Change the priority of the process
Press r, This will ask PID and priority.

Displays a specific user processes
Press u, which will ask for username to filter result.

Display all CPUs / cores
Press 1 (one), which will break the CPU down and show details for all the individual CPUs running on the system.

Highlight running processes
Press z or b, which will highlight all running process

Decrease number of processes displayed
Press n, which prompts for a number and shows only that.

Toggle top headers
Press l, to hide or show the load average. 1st header line.
Press t, to hide or show the CPU states. 2nd and 3rd header line.
Press m, to hide or show the memory information. 4th and 5th line.

Save top configuration settings
If you’ve made any interactive top command configurations suggested in the above examples, you might want to save those for all future top command output. Once you’ve saved the top configuration, next time when you invoke the top command all your saved top configuration options will be used automatically.
Press W, which will write the configuration files to ~ / .toprc
This will display the write confirmation message.

Split top output into multiple panels
Press A to display multiple views of top command output on the terminal.
You can cycle through these windows using a.

Get top command help
Press h, which will display help for interactive top commands.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.