linux 查看哪个进程占用io

2024-11-15 09:19:05
推荐回答(1个)
回答1:

用 lsof 查看某块磁盘上的读写进程。

gddg:~ # lsof /dev/xvda2 |head
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
init 1 root cwd DIR 202,2 4096 2 /
init 1 root rtd DIR 202,2 4096 2 /
init 1 root txt REG 202,2 40784 193218 /sbin/init
init 1 root mem REG 202,2 19114 8063 /lib64/libdl-2.11.1.so
init 1 root mem REG 202,2 1661454 8057 /lib64/libc-2.11.1.so
init 1 root mem REG 202,2 236384 8114 /lib64/libsepol.so.1
init 1 root mem REG 202,2 113904 8115 /lib64/libselinux.so.1
init 1 root mem REG 202,2 149797 8050 /lib64/ld-2.11.1.so
kthreadd 2 root cwd DIR 202,2 4096 2 /

然后可以通过 lsof -p $pid 查看详情

gddg:~ # lsof -p 32597
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 32597 root cwd DIR 202,2 4096 16097 /root
bash 32597 root rtd DIR 202,2 4096 2 /
bash 32597 root txt REG 202,2 584016 32203 /bin/bash
bash 32597 root mem REG 202,2 293936 8125 /lib64/libncurses.so.5.6
bash 32597 root mem REG 202,2 1661454 8057 /lib64/libc-2.11.1.so
bash 32597 root mem REG 202,2 19114 8063 /lib64/libdl-2.11.1.so
bash 32597 root mem REG 202,2 263568 8153 /lib64/libreadline.so.5.2
bash 32597 root mem REG 202,2 149797 8050 /lib64/ld-2.11.1.so
bash 32597 root mem REG 202,2 217016 16498 /var/run/nscd/passwd
bash 32597 root mem REG 202,2 256324 149503 /usr/lib/locale/en_US.utf8/LC_CTYPE
bash 32597 root mem REG 202,2 54 149490 /usr/lib/locale/en_US.utf8/LC_NUMERIC
bash 32597 root mem REG 202,2 2454 133112 /usr/lib/locale/en_US.utf8/LC_TIME
bash 32597 root mem REG 202,2 1163682 149504 /usr/lib/locale/en_US.utf8/LC_COLLATE
bash 32597 root mem REG 202,2 286 133111 /usr/lib/locale/en_US.utf8/LC_MONETARY