During the training of the company, I learned that I can see the list of running processes with the top command. The purpose of this article is to understand the information displayed by the top command while organizing what you have learned and what you have researched.
I referred to this article
https://qiita.com/k0kubun/items/7368c323d90f24a00c2f
The top command is a linux command that displays a list of processes running on that system. You can see the load of the entire system and the memory usage of each process.
When you execute the top command, the process information of the system is displayed at once.
There is a lot of information for beginners, but we will look at it little by little.
Let's take a blank line in the image as a delimiter and look at the upper part as the header part.
top - 19:41:02 up  3:35,  1 user,  
Information on the first line where "top" is written. From the left
--Current time --Server uptime ("up 3:35" part, "hour: minute" notation) --Number of logged-in users
It will be.
load average
load average: 0.52, 0.44, 0.53
Information on the rest of the first line. This column shows the average number of waiting tasks (processes) per unit time. Three decimal numbers are lined up, but the most recent from the left is the number of waiting tasks per unit time between "1 minute, 5 minutes, 15 minutes". In the image above, for example, the average number of waiting tasks in the last minute is 0.52 tasks.
Tasks
Tasks: 387 total,   1 running, 315 sleeping,   0 stopped,   0 zombie
You can see the current task by state.
--total: total number of tasks --running: Number of running tasks --sleeping: number of waiting tasks --stop: Number of tasks stopped --zombie: Number of zombie tasks
CPU
%Cpu(s):  2.9 us,  0.3 sy,  0.0 ni, 96.6 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st
You can see the percentage of CPU usage time for each process type. There is no unit in the image above, but the unit is "%".
--us: user process --sy: system process --ni: nice process --id: idle process --wa: I / O wait process --hi: hardware interrupt process (interrupt means "interrupt") --si: software interrupt process
(I will investigate what each process is like at another time.) You can switch to information for each individual CPU by pressing "1" on the screen.
%Cpu0  :  1.0 us,  0.0 sy,  0.0 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.7 si,  0.0 st
%Cpu1  :  0.7 us,  0.0 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu2  :  1.4 us,  0.3 sy,  0.0 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  0.4 us,  0.7 sy,  0.0 ni, 98.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu4  :  0.7 us,  0.3 sy,  0.0 ni, 99.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu5  :  1.0 us,  0.7 sy,  0.0 ni, 98.3 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu6  :  0.3 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu7  :  0.3 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
Memory/Swap
KiB Mem :  7965864 total,   336044 free,  5603244 used,  2026576 buff/cache
KiB Swap:  2097148 total,  1692156 free,   404992 used.   800580 avail Mem 
The amount of physical memory and swap area used is displayed. "Mem" is the physical area and "Swap" is the swap area. Regarding the swap area, the site of here was easy to understand.
--total: total memory amount --free: Amount of unused memory --used: Amount of memory in use --buff / cache: Amount of memory used in the buffer / cache
The final "avail Mem" is "the amount of memory a new app can use without swapping".
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                 
 1407 sada      20   0  604828  92172  63112 S   2.0  1.2   6:17.70 Xorg                                                                                                                                    
 2196 sada      20   0 7374224 476924  53408 S   1.7  6.0   8:05.10 java                                                                                                                                    
 1537 sada      20   0 4039788 274080 115156 S   1.3  3.4   8:13.99 gnome-shell                                                                                                                             
 2768 sada      20   0 2008760 555128 310552 S   1.0  7.0   7:52.98 chrome                                                                                                                                  
12359 sada      20   0  849556  48752  34872 S   1.0  0.6   0:07.22 gnome-terminal- 
A list of running processes is displayed below the blank line.
--PID: Process ID --USER: The user running the process --PR: Relative priority based on priority 0. There are also negative values. --VIRT: Amount of virtual memory reserved --RES: Amount of physical memory used --SHR: Amount of memory that may be shared with other processes --S: Process status classified by alphabet --D: Uninterruptable When pressed --R: Running --S: Sleep state --T: Stopped --Z: Zombie process --% CPU: CPU usage --% MEM: Memory usage --TIME +: Process execution time --COMMAND: Process execution command name
In this process list, you can sort by CPU usage (% CPU) with "Shift + p" and by memory usage (% MEM) with "Shift + m". If you press "c" on the screen, the "COMMAND" part will be displayed as an absolute path.
Here is an image showing the absolute path, sorted by memory usage.

We have summarized how to read the process list screen displayed by the top command. The top command seems to have many other useful features. I want to master it and manage the process smoothly.
Recommended Posts