Like ps, the top command lists all processes running on a Linux system. It acts as a process management tool by enabling you to prioritize, sort, or terminate processes interactively. It displays a dynamic process status, reflecting real-time changes.

Syntax

The syntax of the top command is:

Listing the state of running processes.

top command examples in Linux

Different keystrokes within this tool execute various process management actions. Some of the frequently used command keys include the following.

Key Used To
Enter Refresh the status of all processes.
Shift+N Sort processes in the decreasing order of their PID.
M Sort processes by memory usage.
P Sort processes by CPU usage.
u Display processes belonging to the user specified at the prompt.
k Terminate the process for which you specify the PID.
r Renice the process for which you specify the PID.
q Exit the process list.

top Command Examples

1. “top” command for one iteration:

2. kill process without exiting “top”:

# top
--> then press k
--> then enter PID

3. To renice a process:

4. “top” for specific user:

5. “top” for specific process:

6. To display the CPU’s:

7. Refreshing output of “top”:

# top
--> then press "spacebar"

To change the output update frequency, press d in interactive mode, and enter the time in seconds.

8. Highlight Running Processes in the Linux Top Command Output:

9. Display Absolute Path of the Command and its Arguments:

10. Executing Unix Top Command in Batch Mode:

Useful when you want to capture the output in txt format.

11. Split Top Output into Multiple Panels:

12. Toggle Top Header to Increase Number of Processes Displayed:

# top
then
-->     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.

13. To save top command configuration changes: