Introduction to Linux basic commands IX: process and memory

Time:2022-5-17

The purpose of computers is to run all kinds of programs. So far, most of the commands we introduce are programs written in programming language to complete some kind of calculation. They are saved in the operating system in the form of files (such as various commands under / bin); However, static programs can not produce results “spontaneously”. Only when they specify input data in the operating system and run, can they get output results. The main form of program operation in the operating system isprocess
Static programs can exist for a long time, and dynamic processes have a limited life cycle. At the beginning of each program run (such as typing a command and pressing enter), the operating system should prepare various resources for the program run, and most of these resources are inMemoryin In order to limit the permissions of multi-user processes, Linux also defines two process runtime states:Kernel stateandUser state; When a process wants to request system services (such as operating a physical device), it must passsystem call(the interface function provided by the operating system to the user space). At this time, the system switches to the kernel state and executes the system call on behalf of the program. After execution, the system switches back to the user state and continues to execute the program code.
This article introduces the process and memory management commands in Linux (more view commands)

1、uptimeSystem running time

uptime [options]

When this command is executed separately, the output information indicates: the current time, the system running time, the number of logged in users, and the average load of the system in the past 1, 5, and 15 minutes.

[[email protected] ~]# uptime
 10:46:38 up 58 days, 19:20,  3 users,  load average: 0.00, 0.01, 0.05

2、psDisplay system process information

ps [options]

When the PS command is run separately, the displayed information is: process ID number (PID), terminal (TTY), running cumulative CPU time (time), command name (CMD)

[[email protected] ~]# ps
  PID TTY          TIME CMD
 9503 pts/1    00:00:00 bash
 9570 pts/1    00:00:00 ps

Here is a brief description ofprocessProcess groupconversationandterminalRelationship. In order to facilitate the management of processes, Linux operating system classifies processes with similar functions or parent-child and brother relationships into a group. Each process must belong to one process group or only one process group. In addition to a process ID, a process also has a process group ID(PGID); Each process group has a process group leader whose PID is the same as the process group ID. Just as a series of related processes can be merged into a process group, a series of process groups can also be merged into a sessionsession。 A session is established by a process, which is called the session leader. The PID of the first session process is the SID (session ID) of this session. Each session starts with user login and ends with user exit. Each process group in a session is called a job. A session can have one process group as the foreground of the session, while other process groups are the background. Each session is associated with a control terminalcontrol terminal, when the session is terminated (the user exits the terminal), the system will send a termination signal(SIGHUP)For all process groups in the session, the default processing method of the process for this signal is to terminate the process.

psAccepts options in three formats with prefixed symbols-ofUNIXFormat options; Without prefixBSDStyle options; With two-ofGNULong format options. The three types of options can be combined freely, but there may be conflicts.

optiona(BSD) indicates that all process information associated with the terminal is displayed when the cooperation option is selectedx(BSD) when used together, it indicates that all process information is displayed (at this time, the TTY column of terminal independent processes is displayed as?)。
option-a(Unix) indicates that the process information associated with the terminal other than the first process of the session is displayed. option-eRepresents all processes.

[[email protected] ~]# ps a
  PID TTY      STAT   TIME COMMAND
 2528 tty1     Ss+    0:00 -bash
 9336 pts/0    Ss     0:00 -bash
 9503 pts/1    Ss     0:00 -bash
 9550 pts/2    Ss+    0:00 -bash
 9571 pts/0    S+     0:00 man ps
 9582 pts/0    S+     0:00 less -s
 9643 pts/1    R+     0:00 ps a
[[email protected] ~]# ps -a
  PID TTY          TIME CMD
 9571 pts/0    00:00:00 man
 9582 pts/0    00:00:00 less
 9644 pts/1    00:00:00 ps

As shown in the example, BSD style options also display the status information of the process and the parameters of the command. The possible states of the process during operation include:

D non interruptible sleep state (usually waiting for IO)
R is running or can run (in the run queue)
S interruptible sleep state (waiting for an event to complete)
T pause status
Ttracking status
W page change status (kernel version 2.6 and later)
X death status (invisible)
Z dead state
#The BSD style option stat column may also include the following characters
< high priority process
N low priority process
L locked state
S session first process
L multithreaded process
+Process is in foreground process group

optionuDisplay user oriented process information (such as the initiating user of the process, the percentage of CPU and MEM occupied by the user state, etc.)

[[email protected] ~]# ps au
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
Root 2528 0.0 0.0 115636 2384 tty1 SS + September 30 0:00 - Bash
root      9336  0.0  0.0 115596  2240 pts/0    Ss   08:44   0:00 -bash
root      9571  0.0  0.0 119196  1972 pts/0    S+   10:59   0:00 man ps
root      9582  0.0  0.0 110276   980 pts/0    S+   10:59   0:00 less -s
root      9835  0.0  0.0 115636  2172 pts/1    Ss   13:48   0:00 -bash
root      9938  0.0  0.0 115512  2096 pts/2    Ss   14:49   0:00 -bash
root      9960  0.0  0.0 154068  5632 pts/2    S+   14:50   0:00 vim others.sh
root      9967  0.0  0.0 139496  1640 pts/1    R+   14:59   0:00 ps au

VSZIndicates the total address space occupied. It includes pages that are not mapped to memory.
RSSIndicates the memory size that actually resides “in memory”, excluding the memory exchanged. And vsz are in KB
Generally, the command is used to view all process informationps -eforps aux
option-ooroIndicates the specified output format
For example, the PID, command name and logical CPU of all bash processes are displayed:

[[email protected] ~]# ps -eo pid,comm,psr|grep bash
 2528 bash              1
 9336 bash              4
 9835 bash              3
 9938 bash              6

Fit options--sortYou can specify to sort the output by a column

#Indicates sorting by user name
ps -eo pid,user,args --sort user

You can also use – O to specify many other information. Please consult the relevant manuals.

3、killTerminate process

kill [options] pid...

commandkillIt will send a specific signal to the specified process or process group. If no signal is specified, it will send a term signal
option-lIndicates that all supported signals are listed:

[[email protected] ~]# kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX
[[email protected] ~]# 

Options are available-sSpecifies the signal to send
Such as starting a process at a terminalsleep 300, check at another terminal and terminate it with the signal sigkill:

[[email protected] ~]# sleep 300
#At this point, you will wait for sleep to complete
#In another terminal
[[email protected] temp]# ps -ef|grep [s]leep
root     10359  9835  0 12:05 pts/1    00:00:00 sleep 300
#Send signal
[[email protected] temp]# kill -s SIGKILL 10359
#Original terminal display
[[email protected] ~]# sleep 300
Killed
[[email protected] ~]#

Or execute the commandkill -9 10359Is the same effect. For the function of other signals, please search by yourself.

4、pgrepandpkillSearch or send signals to processes

pgrep [options] pattern
pkill [options] pattern

therepatternIs a regular expression used to match the process name
If the view name isgunicornAll processes

[[email protected] ~]# pgrep gunicorn
17268
17286
17289
17290
17293

option-lDisplays the process name and PID

[[email protected] ~]# pgrep -l gun
17268 gunicorn
17286 gunicorn
17289 gunicorn
17290 gunicorn
17293 gunicorn

If all sleep processes are terminated

pkill sleep

If makesyslogdReread its configuration file

pkill -HUP syslogd

5、topDisplay process information

topCommand real-time and dynamic display of system summary information and process status information. It refreshes every 1s and press the keyboardqPress the key to exit.
Execute separatelytopCommand displays the following output:

top - 03:20:02 up 59 days, 17:30,  3 users,  load average: 0.00, 0.01, 0.05
Tasks: 184 total,   1 running, 183 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.1 us,  0.0 sy,  0.0 ni, 99.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8010720 total,  5100308 free,   420652 used,  2489760 buff/cache
KiB Swap:  8257532 total,  8257532 free,        0 used.  6905944 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
    1 root      20   0  193664   8708   2396 S   0.0  0.1   1:23.98 systemd
    2 root      20   0       0      0      0 S   0.0  0.0   0:00.44 kthreadd
    3 root      20   0       0      0      0 S   0.0  0.0   0:00.10 ksoftirqd/0
    5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H
    7 root      rt   0       0      0      0 S   0.0  0.0   0:00.34 migration/0
    8 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/0
   10 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/1

The output contents of each line are explained below (Note: the top version is3.3.10, the fourth and fifth lines of the output of other versions may be different)

The first line displays information and commandsuptimeThe output of is consistent;

The second line displays the task summary information, which is the four possible states of the process;

The third line displays CPU load information, whereusIndicates the percentage of CPU time occupied by user status tasks,syIndicates the percentage of CPU time occupied by kernel tasks,niIndicates a process that has changed its priority (throughniceorreniceCommand) CPU time percentage,idRepresents the percentage of CPU idle time,waIndicates the percentage of CPU time consumed by processes waiting for input and output,hiIndicates the time taken for hardware interruption,siIndicates the time taken for software interruption,stIndicates the time that the virtual machine waits for CPU resources of the real physical machine

The fourth line displays memory information,totalRepresents the total memory,freeIndicates unallocated memory,usedIndicates the memory used (value is)total-free-buff/cacheResults of the test),buff/cacheIndicates cache memory;

The fifth line shows the usage of switching partitions, whereavail MemIndicates the maximum memory that can be allocated to a new program when it is started. The difference from the free column in the third row is that it counts the memory in the cache allocator (slab) and page cache that can be recycled. (in some earlier top implementations, there was no value for this column)

Next, after a blank line, the process related information, header columns and fields are displayedpsThe output of the command has a corresponding relationship, wherePRIndicates priority;NIIndicates nice value (described later);VIRTIndicates the size of virtual memory, corresponding to that in PS commandVSZRESIndicates the resident memory size of the process, which corresponds to the size in the PS commandRSSSHRIndicates the size of shared memory;SIndicates the process status, corresponding to the PS commandSTAT

There is a concept of priority in the process state of Linux system. Its value is a dynamically changing integer, ranging from 0 to 139. The smaller this value is, the higher the priority is, and the more priority it will be executed by CPU. IftopcommandPRColumns are displayed asrt, indicating that this process isReal time process, its priority range is 0-99, which is higher than other ordinary processes. There is also the concept of static priority in Linux. Users can use commandsniceandreniceSetting or changing the static priority of a process can be regarded as a modified value of the dynamic priority, which can affect the value of the dynamic priority.

PRThe value displayed in the column is the value after the actual priority minus the maximum priority of the real-time process. The default value of 3.10 kernel non real-time process is 20, that is:DEFAULT_PRIO = MAX_RT_PRIO + 20 = 120
NIWhen the column is not 0, it indicates that the process has been set with a static priority value, ranging from – 20 to 19. Its relationship with the current priority value is:DEFAULT_PRIO = MAX_RT_PRIO + (nice) + 20
If you use nice to start a sleep process:

#When not specified with option - N, the default value is 10
[[email protected] ~]# nice -n -10 sleep 300
#For existing processes, you can use the renice command to adjust their static priority
[[email protected] ~]# 
[[email protected] ~]# ps -eo pri,ni,comm|grep sleep
29  -10 sleep
[[email protected] ~]#
[[email protected] ~]# top -bn1 |egrep 'COMMAND$|sleep$'
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
11967 root      10 -10  107892    616    528 S   0.0  0.0   0:00.00 sleep
#Note that the priority values of PS and top are different here. The value of PRI column of PS command is 29 = max_ PRIO(139) -  MAX_ RT_ PRIO(100) + nice(-10)。 Their actual priority values are equal.

The option is used in the above example-nIndicates the number of top refreshes,-bIndicates that the batch mode runs top. This mode will remove the control characters in the output to facilitate the output to other programs for processing.
option-o fieldnameSort output by specified column, options-OCan list-oColumn names that can be specified

#Execute the command by yourself to see the effect
top -O |tr '\n' ' '
top -bn1 -o PR

Some are briefly introduced belowtopInteractive commands available in:

Q exit top
H get help information
1 display the information of each logical CPU
K terminate a process (the user will be prompted to enter the PID to be terminated and what signal to send)
R reset the process static priority (equivalent to executing renice)
I ignore idle and dead processes
H displays thread information
M sort by resident memory size
P sort by CPU usage percentage
Write w to current setting ~ / Toprc file

6、freeDisplays the system memory usage

free [options]

freeThe command displays the current memory and swap usage of the system. The default unit is KB

#Version 3.3.10
[[email protected] ~]# free
              total        used        free      shared  buff/cache   available
Mem:        8010720      423060     4540476      375580     3047184     6897052
Swap:       8257532           0     8257532

The displayed information is consistent with the corresponding value in the output of the top command, wheresharedRepresents the size of memory used in the memory file system (TMPFS).
As mentioned earlieravailableThe meaning represented by the corresponding value is usually checked to see how much memory is available in the systemavailableThe corresponding value of is OK. hereAvailable = free + cache (recyclable part)
However, in the older version of free, there is no such value. Its output may be as follows:

             total       used       free     shared    buffers     cached
Mem:       8174384    4120488    4053896          0     229320    1041712
-/+ buffers/cache:    2849456    5324928
Swap:     16779884          0   16779884

explain:
BufferIt is designed to improve the speed of data exchange between memory and hard disk (or other I / O devices)
Cache (CACHE)It is designed to improve the data exchange speed between CPU and memory
So in the outputbuffersIt can be simply understood as buffer data to be written to the hard disk;cachedIt can be understood as the cached data read from the hard disk (page cache memory)Recyclable partFrom cached and slab (CACHE allocator)

Memthat ‘s ok:used = total - freeFree memory at this timefreeColumn does not reflect the current available memory size of the system
-/+ buffers/cachethat ‘s ok:used = total - free(Mem) - (buffers + cached), herefreeColumns and previously describedavailableRelationship isAvailable = free + cache (recyclable part)
So when notavailableWhen the column can be viewed, it cannot be passedfreeCommand to find or calculate the real available memory. You need to know the specific situation of the cache part.

option-b-k-m-gIndicates the unit of each specified value: bytes, KB, MB, or GB

7、fuserLocate a process using a file or socket

fuserOften used to see which processes use files

[[email protected] ~]# fuser .
/root:                2528c 11430c 11447c

The example shows that three processes are using the current directory, including:2528cThe first number represents the process PID, and the last character c represents the current directory (i.e. the process works in this directory). Other possible characters are:

E indicates that the process is running and executing the file
F open the file and omit it when outputting by default
Open the file in F writing mode. The output is omitted by default
R root directory
M MMAP file or shared library file

option-kIndicates the transmission signalSIGKILLTo relevant processes (use with caution)
option-iRepresents interaction, asking the user before killing a process
option-lList supported signals
option-SIGNALDesignated signal

8、lsofList open files

stayThis oneIn, we briefly describe the first three files opened by bash process and associate them with file descriptors respectively0,1,2。 The same is true for files opened by other processes. The system maintains a file descriptor table for each process, and the values of this table are numbers starting from 0. Execute separatelylsofThe open files of all processes in the system will be displayed when using the command

#The command version is 4.87
[[email protected] temp]# lsof |head
COMMAND     PID   TID    USER   FD      TYPE             DEVICE  SIZE/OFF       NODE NAME
systemd       1          root  cwd       DIR              253,0      4096        128 /
systemd       1          root  rtd       DIR              253,0      4096        128 /
systemd       1          root  txt       REG              253,0   1489960       6044 /usr/lib/systemd/systemd
systemd       1          root  mem       REG              253,0     20032  201329002 /usr/lib64/libuuid.so.1.3.0
systemd       1          root  mem       REG              253,0    252704  201330338 /usr/lib64/libblkid.so.1.1.0
systemd       1          root  mem       REG              253,0     90632  201328968 /usr/lib64/libz.so.1.2.7
systemd       1          root  mem       REG              253,0     19888  201329137 /usr/lib64/libattr.so.1.1.0
systemd       1          root  mem       REG              253,0     19520  201328509 /usr/lib64/libdl-2.17.so
systemd       1          root  mem       REG              253,0    153192  201328867 /usr/lib64/liblzma.so.5.0.99

Each line has an open file, and the header columns mean:

Command the first 9 characters of the process command name
PID process ID
TID task ID
FD 1) document description symbol or the following characters:
    CWD current working directory
    Err FD error message
    LTx shared library code
    MEM memory mapping file
    MMAP memory mapping device
    PD parent directory
    RTD root directory
    Txt program code
    2) When it is FD (number), it may be followed by the following authority characters:
    R read
    W write
    U reading and writing
    The space permission is unknown and there are no locking characters
    -The permission is unknown but has locking characters
    3) After the permission character, there may be the following locking characters:
    R file partial read lock
    R entire file read lock
    W file partial write lock
    W write lock of the whole file
    U arbitrary length read / write lock
    U unknown type lock
    Blank no lock
Type, possible values are:
    Dir directory
    Reg common file
    Chr character device file
    BLK block device file
    FIFO pipeline file
    UNIX socket file
    IPv4 socket file
    ....
Device device number
Size / off file size or offset (bytes)
Node file No

option-nIndicates that IP to host name conversion is not performed
option-c stringDisplays all open files of the process that contains the specified character in the command column
option-u usernameDisplays the files opened by the user process
option-d FDDisplays the file whose open file descriptor is FD

[[email protected] ~]# lsof -d 4
COMMAND     PID    USER   FD      TYPE             DEVICE SIZE/OFF      NODE NAME
systemd       1    root    4u  a_inode                0,9        0      5755 [eventpoll]
systemd-j   539    root    4u     unix 0xffff880230168f00      0t0     10467 /run/systemd/journal/socket
systemd-u   549    root    4u     unix 0xffff88003693d640      0t0     12826 /run/udev/control
lvmetad     555    root    4wW     REG               0,18        4      8539 /run/lvmetad.pid
auditd      693    root    4w      REG              253,0   701364 208737917 /var/log/audit/audit.log
....

option+d DIRDisplays the files opened by the process in the directory
option+D DIRRecursively display the files opened by the process in the directory

[[email protected] ~]# lsof +d /root|head -3
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF      NODE NAME
bash     2528 root  cwd    DIR  253,0     4096 201326721 /root
bash    12902 root  cwd    DIR  253,0     4096 201326721 /root

option-iIndicates that the file opened by the qualified process is displayed. The format is[46][protocol][@hostname|hostaddr][:service|port]

#View the operation of port 22
[[email protected] ~]# lsof -ni :22
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
sshd     1358 root    3u  IPv4    8979      0t0  TCP *:ssh (LISTEN)
sshd     1358 root    4u  IPv6    8981      0t0  TCP *:ssh (LISTEN)
sshd    12900 root    3u  IPv4 3509687      0t0  TCP 10.0.1.254:ssh->192.168.78.143:57325 (ESTABLISHED)
#For example, SMTP is one of the services listed in the / etc / services file
[[email protected] ~]# lsof -ni [email protected]:22,smtp  
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
sshd     1358 root    3u  IPv4    8979      0t0  TCP *:ssh (LISTEN)
master   2162 root   13u  IPv4   16970      0t0  TCP 127.0.0.1:smtp (LISTEN)
sshd    12900 root    3u  IPv4 3509687      0t0  TCP 10.0.1.254:ssh->192.168.78.143:57325 (ESTABLISHED)

Imagine what happens if you delete a file that is being opened by another process? Experiment to see the phenomenon:

#Use the more command to view a file
[[email protected] ~]# more /root/.bash_history
#Use lsof to view at another terminal
[[email protected] ~]# lsof|grep ^more
more      14470          root  cwd       DIR              253,0      4096  201326721 /root
more      14470          root  rtd       DIR              253,0      4096        128 /
more      14470          root  txt       REG              253,0     41096  134321844 /usr/bin/more
more      14470          root  mem       REG              253,0 106065056  134319094 /usr/lib/locale/locale-archive
more      14470          root  mem       REG              253,0   2107816  201328503 /usr/lib64/libc-2.17.so
more      14470          root  mem       REG              253,0    174520  201328905 /usr/lib64/libtinfo.so.5.9
more      14470          root  mem       REG              253,0    164440  225392061 /usr/lib64/ld-2.17.so
more      14470          root  mem       REG              253,0    272001   67147302 /usr/share/locale/zh_CN/LC_MESSAGES/util-linux.mo
more      14470          root  mem       REG              253,0     26254  201328839 /usr/lib64/gconv/gconv-modules.cache
more      14470          root    0u      CHR              136,1       0t0          4 /dev/pts/1
more      14470          root    1u      CHR              136,1       0t0          4 /dev/pts/1
more      14470          root    2u      CHR              136,1       0t0          4 /dev/pts/1
more      14470          root    3r      REG              253,0     17656  202386313 /root/.bash_history
#Delete this file
[[email protected] ~]# rm -f /root/.bash_history
#Check
[[email protected] ~]# lsof -d 3|grep ^more
more      14470    root    3r      REG              253,0    17656  202386313 /root/.bash_history (deleted)
[[email protected] ~]#
#You will find that the file lists the word delete

In Linux system/procThe directory stores the data related to all processes of the system, and the digital directory name in it is PID. Let’s take a closer look at the file descriptor of the more process just now

[[email protected] ~]# cat /proc/14470/fd/3 > /root/.bash_history.bak
#This saves the contents of file descriptor 3 to / root / bash_ history. bak
#Stop the more process and view
[[email protected] ~]# ls -l /root/.bash_history*
-Rw-r -- R -- 1 root 17656 November 30 07:47 / root / bash_ history. bak
[[email protected] ~]# cat /root/.bash_history.bak
#You will find that the original file is gone, and the new file saves all the contents of the original file

The conclusion is that if a process is opening the file when deleting the file, the contents of the file can still be recovered through the corresponding file descriptor of the process. At the same time, if a file is deleted and the space is not released, it indicates that a process is opening the file (command)lsof|grep deleteAfter restarting the process, the space will be released.

9、iostatDisplay CPU and I / O statistics

[[email protected] ~]# iostat
Linux 3.10.0-327. el7. x86_ 64 (centos7) November 30, 2016_ x86_ 64_         (8 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.00    0.03    0.00    0.00   99.85

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.23         0.79         3.05    4178309   16079082
dm-0              0.22         0.57         2.94    3002207   15480498
dm-1              0.00         0.00         0.00       1088          0
dm-2              0.03         0.22         0.11    1146430     596232
dm-3              0.06         0.01         1.91      28900   10079073
dm-4              0.03         0.01         1.91      28644   10079073

The CPU part of the display information is in the commandtopThere are corresponding explanations in the description of. The I / O part is the read-write rate and total amount information of each device, in whichtpsIndicates how many I / O requests are made per second
option-cDisplay CPU Information
option-dDisplay device information
option-xShow more detailed information
commandiostat m nThe number (m, n), M represents the time interval and N represents the number of times; At this time, iostat will print every m seconds for N times.

[[email protected] ~]# iostat -c 1 3
Linux 3.10.0-327. el7. x86_ 64 (centos7) November 30, 2016_ x86_ 64_         (8 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.00    0.03    0.00    0.00   99.85

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.00    0.00    0.00    0.00   99.88

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.00    0.12    0.00    0.00   99.75

You can also view the I / O information of the specified device by receiving the device name

[[email protected] ~]# iostat sda
Linux 3.10.0-327. el7. x86_ 64 (centos7) November 30, 2016_ x86_ 64_         (8 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.12    0.00    0.03    0.00    0.00   99.85

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.23         0.79         3.05    4178309   16084862

10、vmstatDisplay virtual memory statistics

vmstat [options] [delay [count]]

Some CPU and I / O information will also be displayed
option-wFormat output

[[email protected] ~]# vmstat -w
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
 r  b         swpd         free         buff        cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 1  0            0      4517628         3184      3067904    0    0     0     1    1    0   0   0 100   0   0

among

procs
    R indicates the number of processes in runnable state
    B indicates the number of non interruptible sleep state processes
memory
    Swpd virtual memory usage
    Free free memory
    Buffer memory usage in buffer
    Cache memory usage in cache
swap
    Amount of Si hard disk swapped to memory
    So amount of memory exchanged to hard disk
io
    The number of blocks received by the Bi from the block device
    Bo number of blocks sent to the block device
system
    In number of interrupts per second, including locks.
    CS number of process context switches per second.
CPU (same as the command top)
    Percentage of CPU time occupied by us user mode tasks
    Percentage of CPU time occupied by sy kernel tasks
    ID CPU idle time percentage
    Wa percentage of CPU time consumed by processes waiting for input and output
    The time that the st virtual machine waits for CPU resources of the real physical machine

option-mShow slab information
option-sDisplays various memory counters and their information
option-dDisplay disk I / O information
option-p deviceDisplays detailed I / O information for device partitions
withiostatIt also supports printing times by frequency

11、mpstatDisplay CPU related information

mpstat [options] [interval [count]]

Display information andtopCommand similarity

[[email protected] ~]# mpstat 1 2
Linux 3.10.0-327. el7. x86_ 64 (centos7) November 30, 2016_ x86_ 64_         (8 CPU)

09:18:19 CPU% usr% nice% sys% iowait% IRQ% soft% steel% guest% gnice% idle
09:18:20 all 0.12 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.88
09:18:21 all 0.12 0.00 0.12 0.00 0.00 0.00 0.00 0.00 0.00 99.75
Average time: all 0.12 0.00 0.06 0.00 0.00 0.00 0.00 0.00 99.81

option-ADisplaying all CPU and interrupt information is equivalent to executionmpstat -I ALL -P ALL
option-I { SUM | CPU | SCPU | ALL }Display interrupt information
option-P { cpu [,...] | ON | ALL }Display CPU Information

[[email protected] ~]# mpstat -P 3,5
Linux 3.10.0-327. el7. x86_ 64 (centos7) November 30, 2016_ x86_ 64_         (8 CPU)

09:29:03 CPU% usr% nice% sys% iowait% IRQ% soft% steel% guest% gnice% idle
09:29:03.3 0.15 0.00 0.04 0.00 0.00 0.00 0.00 0.00 99.81
09:29:03 s 5 0.11 0.00 0.03 0.00 0.00 0.00 0.00 0.00 99.86

This paper briefly introduces the related commands of process and memory in Linux. Process and memory are very important in the computer operating system and involve a lot of content. I won’t do it here.