Linux fuser命令

来源:互联网 发布:淘宝联盟首页 编辑:程序博客网 时间:2024/06/05 18:03

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 onxx.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 busyumount: /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
0 0