To sort top output by any column, Press O (upper-case O) , which will display all the possible columns that you can sort by as shown below.
Current Sort Field: P for window 1:Def
Select sort field via field letter, type any other key to return
a: PID = Process Id v: nDRT = Dirty Pages count
d: UID = User Id y: WCHAN = Sleeping in Function
e: USER = User Name z: Flags = Task Flags
When the linux top command is running, Press R, which does the sort in reverse order.
Once you’ve located a process that needs to be killed, press ‘k’ which will ask for the process id, and signal to send. If you have the privilege to kill that particular PID, it will get killed successfully.
Press r, if you want to just change the priority of the process (and not kill the process). This will ask PID for renice, enter the PID and priority.
$ top -u geek
While unix top command is running, press u which will ask for username as shown below.
Use top -p as shown below to display specific PIDs.
$ top -p 1309, 1882
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1309 geek 23 0 2483m 1.7g 27m S 0 21.8 45:31.32 gagent
1882 geek 25 0 2485m 1.7g 26m S 0 21.7 22:38.97 gagent
Top output by default shows CPU line for all the CPUs combined together as shown below.
By default, linux top command updates the output every 3.0 seconds. When you want to update the output on-demand, press space bar.
To change the output update frequency, press d in interactive mode, and enter the time in seconds as shown below.
Until you press q, top continuously displays the output. If you would like to view only a certain iteration and want the top to exit automatically use -n option as shown below.
The following example will show 2 iterations of unix top command output and exit automatically
To display multiple views of top command output on the terminal, press A. You can cycle through these windows using ‘a’. This is very helpful, when you can sort the output on multiple windows using different top output columns.
Get a quick command line option help using top -h as shown below.
Press n in the Interactive mode, which prompts for a number and shows only that. Following example will display only 2 process as a time.
By default top displays total number process based on the window height. If you like to see additional process you might want to eliminate some of the top header information.
Press l – to hide / show the load average. 1st header line.
Press t – to hide / show the CPU states. 2nd and 3rd header line.
Press m – to hide / show the memory information. 4th and 5th line.
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.