fuser:identify processes using files or sockets 通过文件或者套接字查询进程,友情链接:Linux lsof命令
常用参数及说明:更多详细信息可以参考man fuser页面
- -u:除了进程的PID之外,同时列出该进程的owner
- -v:列出更多的信息
- -m:后面接的文件名会主动上提到该文件系统的最顶层,对umount不成功很有帮助
例子:
1. 查询当前目录下的进程
[root@localhost test]# fuser -uv .
USER PID ACCESS COMMAND
.: root 3784 ..c.. (root)bash
root 3815 ..c.. (root)bash
root 9998 ..c.. (root)bash
root 28673 ..c.. (root)vi
ACCES列说明
:
- c:此程序在当前目录下
- e:当运行的时候可执行
- f:打开文件,默认状态下被忽略
- F:打开文件等待被写入,同f一样,默认状态下被忽略
- r:root directory,根目录
- m:可能为共享库
2. 查询正在使用文件的进程信息
[root@rhel6164 ~]# fuser -uv 文件名
[clef@rhel6164 ~]$ fuser -uv /home/clef/log.txt #用log.txt查看不到正在使用的进程
[clef@rhel6164 ~]$ fuser -uv /home/clef/.log.txt.swp #用.log.txt.swp可以查看到正在使用的进程
USER PID ACCESS COMMAND
/home/clef/.log.txt.swp:
clef 32744 F.... (clef)vim
3. 当umount不成功的时候,用fuser查询所占用文件系统的进程
[root@localhost test]# df -h /mnt/linux_share/ #/mnt/linux_share为mount的文件系统
Filesystem Size Used Avail Use% Mounted on
xx.xx.xx.xx:linux_share
299G 156G 144G 52% /mnt/linux_share
[root@localhost test]# umount /mnt/linux_share/ #当umount的时候提示设备正忙
umount: /mnt/linux_share: device is busy
umount: /mnt/linux_share: device is busy
[root@localhost test]# fuser -muv /mnt/linux_share/ #通过fuser查看正在占用该文件系统的进程
USER PID ACCESS COMMAND
/mnt/linux_share/: root 3815 ..c.. (root)bash