Linux: Understand the information displayed by the top command

Introduction

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

What is the top command?

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.

Try running the top command

When you execute the top command, the process information of the system is displayed at once. Screenshot from 2020-06-02 19-31-18.png There is a lot of information for beginners, but we will look at it little by little.

Header part

Let's take a blank line in the image as a delimiter and look at the upper part as the header part.

Time and number of users

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".

Process list part

  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. Screenshot from 2020-06-02 20-51-59.png

at the end

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

Linux: Understand the information displayed by the top command
Linux: Rename the process displayed by the ps command
About the number (section number) in () displayed by the Linux man command
Understand the attributes of Linux files (ls -l command)
Understand the Linux audit system Audit
[linux] kill command to kill the process
Hit the top command with htop
Linux command # 4
[Python] Visualize the information acquired by Wireshark
[Linux] How to use the echo command
How to use the Linux grep command
Linux: Fix the address returned by malloc
Notify Slack when the linux command finishes
Linux command # 5
Understand the "temporary" part of UNIX / Linux
top command
Adjust file permissions with the Linux command chmod
The story of misreading the swap line of the top command
It's a Mac. What is the Linux command Linux?
Linux command list
linux at command
[Linux] Search command
Linux [directory command]
Linux server command
Linux Command Summary
[Basic] linux command
Linux [shell command]
IPF command information
My linux command
Linux command <Basic 1>
Linux command collection
Linux mkdir command
Linux command basics
[Linux] Git command
Linux (command memory)
Gradually display the output of the command executed by subprocess.Popen
Open Chrome version of LINE from the command line [Linux]
[Linux] Execute git pull regularly with the crontab command
[Statistics] Understand the mechanism of Q-Q plot by animation.
Linux user addition, how to use the useradd command
Multiply PDF by OCR on command line on Linux (Ubuntu)
(Remember quickly) How to use the LINUX command line