【 fuser】Linux上如何查看文件被哪个进程占用?
2022-10-28 本文已影响0人
Bogon
监控告警,某台服务器磁盘快爆盘了,登录上去一看是某个文件在疯狂增长。
从文件名无法判断此文件属于哪个进程,此时删除或者清空文件是没用的,需要找到该文件所属的进程。
fuser
<0>.查看某个进程的pid
# fuser /usr/bin/pulseaudio
/usr/bin/pulseaudio: 11206e
<1>.查看当前目录正在被哪些进程在使用
# fuser -uv .
用户 进程号 权限 命令
/home/test: test 3022 ..c.. (test)gnome-session-b
test 3053 ..c.. (test)dbus-daemon
<2>.查看/lib/x86_64-linux-gnu/libc-2.27.so正在被哪些进程在使用
# fuser -uv /lib/x86_64-linux-gnu/libc-2.27.so
用户 进程号 权限 命令
/lib/x86_64-linux-gnu/libc-2.27.so:
test 2983 ....m (test)systemd
test 3022 ....m (test)gnome-session-b
test 3047 ....m (test)fcitx
test 3053 ....m (test)dbus-daemon
test 3073 ....m (test)dbus-daemon
<3>.查看/proc这个目录有哪些进程在使用
# fuser -uv /proc
用户 进程号 权限 命令
/proc: root kernel mount (root)/proc
test 8736 f.... (test)nacl_helper
test 8739 f.... (test)chrome
test 8789 f.... (test)chrome
test 10621 f.... (test)Typora
test 10654 f.... (test)Typora
<4>.那些进程在进行/proc文件系统的读取
# fuser -muv /proc
用户 进程号 权限 命令
/proc: root kernel mount (root)/proc
test 2983 f.... (test)systemd
test 3258 f.... (test)gvfs-udisks2-vo
test 3369 f.... (test)gsd-housekeepin
test 4185 f.... (test)gnome-software
test 4754 f.... (test)gvfsd-trash
test 8735 .rc.. (test)chrome
test 8736 frc.. (test)nacl_helper
<5>.杀死/home占用home目录的所有进程
# fuser -mki /home
lsof
1.查看那些进程占用/lib/x86_64-linux-gnu/libc-2.27.so
# lsof |grep /lib/x86_64-linux-gnu/libc-2.27.so
pidof
1.查看某个进程的pid
# pidof pulseaudio
11206