Fuser
The fuser command shows the PIDs of processes currently accessing a given file, filesystem, or unix socket. In the default display mode, each file name is followed by a letter indicating the access type:
c 当前目录.
e 正在运行.
f 打开文件。 默认显示模式中省略f。
F 打开文件为了写入。 在默认显示模式下,F被省略。
r 根目录.
m mmap的文件或共享库.
Syntax
fuser [OPTIONS] name
-a, –all show all files specified on the command line. By default, only files accessed by at least one process are shown.
-k, –kill kill the processes accessing the file.
-i, –interactive ask for user confirmation before killing a process. Ignored if -k is not given.
-l, –list-signals list all known signal names.
-m NAME, –mount NAME show all processes using the given filesystem or block device
-M, –ismountpoint only carry out the request if NAME is a mount point; this can prevent you from accidentally killing the whole machine.
-w only kill processes that have write access. Ignored if -k is not given.
-n SPACE, –namespace SPACE select a different namespace (file, udp, tcp).
-s, –silent silent mode
-SIGNAL send the given signal instead of SIGKILL
-u, –user append the owning user’s username next to each PID.
-v, –verbose verbose mode.
Example
Show processes accessing this directory
fuser -v /opt/jupyterlab/
USER PID ACCESS COMMAND
/opt/jupyterlab: lfzyx 96365 ..c.. bash
root 123165 ..c.. sudo
root 123166 ..c.. su
root 123167 ..c.. bash
root 125752 ..c.. jupyterhub
root 125758 ..c.. node
Show processes accessing this filesystem or block device
fuser -v -m /mnt
fuser -v -m /dev/sdb1
USER PID ACCESS COMMAND
/dev/sdb1: root kernel mount /mnt
root 93433 F.... mount.ntfs
lfzyx 109588 ..c.. bash
lfzyx 110408 F.c.. md5sum
lfzyx 110421 F.c.. md5sum
The fuser command can also be used to detect processes using a network port
fuser -v -n tcp 8000
USER PID ACCESS COMMAND
8000/tcp: root 125758 F.... node
Kill processes currently accessing this filesystem or network port
fuser -k -m /mnt
fuser -k 123/tcp