参考文献

fuser

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# fuser -h
Usage: fuser [-fIMuvw] [-a|-s] [-4|-6] [-c|-m|-n SPACE]
[-k [-i] [-SIGNAL]] NAME...
fuser -l
fuser -V
Show which processes use the named files, sockets, or filesystems.

-a,--all display unused files too
-i,--interactive ask before killing (ignored without -k)
-I,--inode use always inodes to compare files
-k,--kill kill processes accessing the named file
-l,--list-signals list available signal names
-m,--mount show all processes using the named filesystems or
block device
-M,--ismountpoint fulfill request only if NAME is a mount point
-n,--namespace SPACE search in this name space (file, udp, or tcp)
-s,--silent silent operation
-SIGNAL send this signal instead of SIGKILL
-u,--user display user IDs
-v,--verbose verbose output
-w,--writeonly kill only processes with write access
-V,--version display version information
-4,--ipv4 search IPv4 sockets only
-6,--ipv6 search IPv6 sockets only
- reset options

udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]

示例

1
2
3
4
5
6
7
8
9
# 查看使用22端口的用户
fuser -va 22/tcp

# 列出所有访问home分区的用户
fuser -va /home

# 杀死所有访问/home目录的进程
fuser -k -TERM -m /home