Use the Top command to see the processes running in Linux
The top command in Linux is used to display all processes running in the Linux environment. This tutorial shows you how to use the top command through explaining the various parameters available and the content they display.
The top command in Linux is used to display all processes running in the Linux environment. This tutorial shows you how to use the top command through explaining the various parameters available and the content they display.
Control the processes running in Linux with the top command
- How to run the top command
- What information is displayed?
- Line 1
- Line 2
- Line 3
- Line 3
- Line 4
- Main board
- Keep the top command always running in the background on a Linux computer
- The main parameters for the top command
- Show current version
- Specify a delay between screen refreshes
- Get a list of columns to sort by
- Sort columns in top command by column name
- Show only processes for a specific user
- Hide Task Idle
- Add the column displayed with the top command
- Switch between modes
- Change color
- Change the display while the top command is running
How to run the top command
Basically, all you need to do to display the currently running processes is to type the following into the terminal:
top
What information is displayed?
The following information is displayed when you run the top command in Linux:
Line 1
- Time
- How long has the computer been running?
- Number of users
- Average load
- Average load displays system load time in the last 1, 5 and 15 minutes.
Line 2
- Total tasks
- Number of running tasks
- Number of actions in 'sleep' state
- Number of tasks stopped
- Number of zombie tasks (the process does not exist)
Line 3
- User CPU usage by percentage
- CPU usage by system in percentage
- CPU usage by low priority processes by percentage
- CPU usage by idle process (process indicates the processor is idle) in percentage
- CPU usage by io wait (CPU time does not work to wait for I / O disk to complete) as a percentage
- CPU usage by hardware interrupt by percentage
- CPU usage by software interrupt by percentage
- CPU usage by steal time (virtual CPU time "standby" real CPU, while virtualization is serving other virtual processors) according to percentage
Line 3
- Total system memory
- Memory free
- Memory used
- Buffer cache cache
Line 4
- Total swap is available
- Total swap is empty
- Total swap used
- Memory available
Swap is virtual RAM, used when physical memory (RAM) is full.
Main board
- Process ID
- User
- Priority level
- Nice level (call a shell script with a specific priority)
- Virtual memory used by the process
- 'Resident' memory that a process uses (ie the process is always in memory and cannot be transferred to other storage devices)
- Memory can be shared
- CPU is used by process according to percentage
- Memory is used by processes in percentage
- The process time has been run
- Order
Keep the top command always running in the background on a Linux computer
You can easily keep the top command always running without having to enter the command into the terminal each time you open the machine.
To pause the top command and continue using the terminal, press CTRL + Z on the keyboard.
To bring the top command back to the foreground, enter fg.
The main parameters for the top command
- -h - Display the current version
- -c - This parameter converts the command column state from displaying the command to displaying the program name and vice versa
- -d - Specify the delay time when refreshing the screen
- -o - Sort by named school
- -p - Displays only processes with the specified ID
- -u - Displays only the processes of the specified user
- -i - Do not display task idle
Show current version
Enter the following information to display the current version details for the top command:
top -h
Output in the following form:
procps -ng version 3.3.10
Specify a delay between screen refreshes
To specify the delay between screen refreshes while using top, enter the following command:
top -d
To refresh the screen after every 5 seconds, enter:
top -d 5
Get a list of columns to sort by
Get the list of columns that you can sort top commands by entering the following:
top -O
There are many columns listed, so you can reduce the output shown as follows:
top -O | less
Sort columns in top command by column name
Use the command in the previous section to find a sortable column, then use the following syntax to sort by that column:
top -o
To sort by% CPU, type the following command:
top -o %CPU
Show only processes for a specific user
To show only the processes that specific users are running, use the following syntax:
top -u
For example, to display all the processes that the user is running, type the following command:
top -u gary
Hide Task Idle
The default view in the top may be a bit confusing and if you only want to see active processes (ie processes not in idle mode - 'idle') then you can run the following command:
top -i
Add the column displayed with the top command
While running the top command, you can press F to display the list of fields that can be displayed in the table:
Use the arrow keys to move up and down the list of fields.
To display a field on the screen, press D. To delete the field, press D on the field again. The asterisk (*) will appear next to the displayed fields.
You can sort the table by school by pressing the S key on the field you want to sort.
Press Enter to confirm the change and press Q to exit.
Switch between modes
While running the top command, you can press A to switch between standard and replacement screens.
Change color
Press Z to change the color of the values in the top.
There are three stages needed to change colors:
1. Press S for summary data, M for notification, H for column heading or T for task information to target areas that need to change colors.
2. Select the color for the specified target: 0 is black, 1 is red, 2 is green, 3 is yellow, 4 are blue, 5 is magenta, 6 is green and 7 is white
3. Press Enter to confirm the change
Press B to bold the text.
Change the display while the top command is running
While the top command is running, you can enable and disable many features by pressing the relevant keys.
The following table shows the key to press and the function it provides:
Function key DescriptionA Replacement display (default off) d Refresh the screen after the specified delay, in seconds (default is 1.5 seconds) p PID monitoring (default off), display all processes B Activate bold (default on), values displayed in bold text l Display load averages (default on) t Specify how to display tasks (default 1 + 1) m Specify the memory usage displayed (default 2 lines) 1 single CPU (default off) - ie display for multiple CPUs J Align numbers to the right (default turn on) j Align text right (default off) R Reverse arrangement (default on) - From the highest progress to the lowest progress S Accumulation time (default off) u User filter (default off ), display only euid U User filter (default off) displays any uid V Forest view (default turned on) displayed as branches x Highlight column (default off) z Multiple display color or monochrome (default on)There are more parameters for the top command. You can read more about them by entering the following information in the terminal window:
man top
You should read it
- Instructions for using pstree command on Linux
- How to use the which command in Linux
- 11 uses of ps command in Linux
- 20+ essential Linux security commands
- How to use the stat command on Linux
- 14 interesting Linux commands in Terminal
- Basic Linux commands everyone needs to know
- The Cat command in Linux
- How to use the last command in Linux
- How to use ss command on Linux
- 8 commands for efficient management of Linux processes
- Instructions for using zforce command on Linux