Article count:922 Read by:3074353

Account Entry

Master these Linux commands to check IO status, and don’t ask for help at critical moments!

Latest update time:2024-05-04
    Reads:


Source: https://www.cnblogs.com/arthinking/p/14450337.html 

Introduce three commonly used I/O related commands in Linux. Use iostat to solve the problem of excessive I/O pressure, use iotop to check the I/O status of the disk, and use lsof to check the I/O process ranking.

1. iostat

The iostat tool will monitor the system's disk operation activities. Its characteristic is to report disk activity statistics, and also report CPU usage. To use the iostat command, you need to install the sysstat software

[root@localhost ~]# yum -y install sysstat[root@localhost ~]# iostatLinux 5.14.0-162.6.1.el9_1.x86_64 (localhost.localdomain)       12/02/22        _x86_64_        (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle 1.75 0.02 5.84 0.60 0.00 91.79
Device tps kB_read/s kB_wrtn/s kB_dscd/s kB_read kB_wrtn kB_dscddm-0 73.70 2078.84 358.65 0.00 162919 28107 0dm-1 1.26 29.96 0.00 0.00 2348 0 0nvme0n1 104.45 2809.71 385.01 0.00 220197 30173 0sr0 1.03 40.12 0.00 0.00 3144 0 0

Output information:

avg-cpu segment

%user: 用户程序占用CPU的百分比%nice: nice操作占用CPU的百分比%system: 系统占用CPU的百分比%iowait: CPU等待硬件I/O时占用CPU百分比%idle: CPU空闲时间的百分比

Device segment

tps: 每秒钟I/O请求数kB_read /s: 每秒读取的块数kB_wrtn/s: 每秒写入的块数kB_read: 读入的块总数kB_wrtn: 写入的块总数

Common parameters

-c 仅显示CPU统计信息,与-d互斥-d 仅显示磁盘统计信息,与-c互斥-k 以K为单位显示每秒的磁盘请求数,默认单位块-p 设备名 | ALL,只显示某个设备的信息,或者全部设备-x 输出扩展信息sec 间隔sec秒显示一次

2. iotop

iotop is a top tool used to monitor disk I/O usage. It has a UI similar to top, including PID, user, I/O, process and other related information. iotop is not a command that comes with the system. If you want to use the iotop command, you need to install the iotop software.

[root@localhost ~]# yum -y install iotop[root@localhost ~]# iotopTotal DISK READ :       0.00 B/s | Total DISK WRITE :       0.00 B/sActual DISK READ:       0.00 B/s | Actual DISK WRITE:       0.00 B/s    TID  PRIO  USER     DISK READ DISK WRITE>    COMMAND                                                                                                           1 be/4 root        0.00 B/s    0.00 B/s systemd --switched-root --system --deserialize 28      2 be/4 root        0.00 B/s    0.00 B/s [kthreadd]      3 be/4 root        0.00 B/s    0.00 B/s [rcu_gp]      4 be/4 root        0.00 B/s    0.00 B/s [rcu_par_gp]      5 be/4 root        0.00 B/s    0.00 B/s [netns]      7 be/4 root        0.00 B/s    0.00 B/s [kworker/0:0H-events_highpri]      9 be/4 root        0.00 B/s    0.00 B/s [kworker/0:1H-events_highpri]     10 be/4 root        0.00 B/s    0.00 B/s [mm_percpu_wq]     12 be/4 root        0.00 B/s    0.00 B/s [rcu_tasks_kthre]     13 be/4 root        0.00 B/s    0.00 B/s [rcu_tasks_rude_]     14 be/4 root        0.00 B/s    0.00 B/s [rcu_tasks_trace]     15 be/4 root        0.00 B/s    0.00 B/s [ksoftirqd/0]     16 be/4 root        0.00 B/s    0.00 B/s [rcu_preempt]     17 be/4 root        0.00 B/s    0.00 B/s [migration/0]     19 be/4 root        0.00 B/s    0.00 B/s [cpuhp/0]     20 be/4 root        0.00 B/s    0.00 B/s [cpuhp/1]

Through the output results, we can clearly know what program is reading and writing to the disk, speed, command line, pid and other information.

Common parameters

-b 批量显示,无交互。主要用作记录到文件-n NUM 显示NUM次,主要用于非交互式模式-d SEC 间隔SEC秒显示一次-p PID 监控的进程pid-u USER 监控的进程用户

3. lsof

lsof (list open files) is a tool that lists open files in the current system. lsof needs to access core memory and various files, so it must be executed as root to take full advantage. lsof is not a command that comes with the system. If you want to use the lsof command, you need to install the lsof software.

[root@localhost ~]# yum -y install lsof[root@localhost ~]# lsofCOMMAND    PID TID TASKCMD     USER   FD      TYPE             DEVICE SIZE/OFF       NODE NAMEsystemd      1                 root  cwd       DIR              253,0      235        128 /systemd      1                 root  rtd       DIR              253,0      235        128 /systemd      1                 root  txt       REG              253,0  1945080   67508326 /usr/lib/systemd/systemdsystemd      1                 root  mem       REG              253,0    45416   67348788 /usr/lib64/libffi.so.8.1.0systemd      1                 root  mem       REG              253,0   153600   67348802 /usr/lib64/libgpg-error.so.0.32.0systemd      1                 root  mem       REG              253,0    28568   67348896 /usr/lib64/libattr.so.1.1.2501systemd      1                 root  mem       REG              253,0   102568   67348636 /usr/lib64/libz.so.1.2.11systemd      1                 root  mem       REG              253,0    32528   67348775 /usr/lib64/libcap-ng.so.0.0.0systemd      1                 root  mem       REG              253,0    41064   67420376 /usr/lib64/libeconf.so.0.4.1systemd      1                 root  mem       REG              253,0   637880   67348851 /usr/lib64/libpcre2-8.so.0.11.0systemd      1                 root  mem       REG              253,0   906176   67323555 /usr/lib64/libm.so.6systemd      1                 root  mem       REG              253,0   178744   67348640 /usr/lib64/liblzma.so.5.2.5systemd      1                 root  mem       REG              253,0   882384   67348653 /usr/lib64/libzstd.so.1.5.1systemd      1                 root  mem       REG              253,0  1293840   67348792 /usr/lib64/libp11-kit.so.0.3.0systemd      1                 root  mem       REG              253,0  4459096   67420748 /usr/lib64/libcrypto.so.3.0.1systemd      1                 root  mem       REG              253,0   144144   67348822 /usr/lib64/liblz4.so.1.9.3systemd      1                 root  mem       REG              253,0  1305536   67348868 /usr/lib64/libgcrypt.so.20.4.0systemd      1                 root  mem       REG              253,0   201832   67348663 /usr/lib64/libcrypt.so.2.0.0systemd      1                 root  mem       REG              253,0    36944   67348643 /usr/lib64/libcap.so.2.48

Parameter Description:

PID: Process identifier
USER: Process owner
FD: File descriptor
TYPE: File type, such as DIR, REG, etc.
DEVICE: The name of the specified disk
SIZE: The size of the file
NODE: Index node
NAME: The exact name of the open file Common parameters lsof abc.txt displays the process of opening the file abc.txt

Common usage methods:

lsof -c abc 显示abc进程现在打开的文件lsof -p 1234 列出进程号为1234的进程所打开的文件lsof -g gid 显示归属gid的进程情况lsof +d /DIR/ 显示DIR目录下被进程打开的文件




Spring recruitment has begun. If you are not fully prepared, it will be difficult to find a good job in spring recruitment.


I’m sending you a big employment gift package, so you can raid the spring recruitment and find a good job!



Latest articles about

 
EEWorld WeChat Subscription

 
EEWorld WeChat Service Number

 
AutoDevelopers

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building,Block B, 18 Zhongguancun Street, Haidian District,Beijing, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号