fuser - identify processes using files or sockets
1.查询目录或文件的使用者
可以查询某个目录或文件是否被使用,被那个进程使用。
例如umount的时候,碰到设备忙的情况
alexsvr:/export/home # umount /export/home/
umount: /export/home: device is busy
umount: /export/home: device is busy
可以用下面的命令查询是那个进程在使用这个目录:
alexsvr:/export/home # fuser /export/home/
/export/home/: 16380c
alexsvr:/export/home # ps -ef|grep 16380
root 16380 16377 0 May10 pts/2 00:00:00 -bash
进程后的字母表明进程访问目录或文件的类型:
c current directory.
e executable being run.
f open file. f is omitted in default display mode.
F open file for writing. F is omitted in default display mode.
r root directory.
m mmap'ed file or shared library.
使用-v参数可以显示更详细的信息:
alexsvr:/export/home # fuser -v /export/home/
USER PID ACCESS COMMAND
/export/home/: root 16380 ..c.. bash
2.查询端口使用进程
alexsvr:/export/home # fuser -v -n tcp 22
USER PID ACCESS COMMAND
22/tcp: root 12319 F.... sshd
3.查询文件系统使用进程
alexsvr:/export/home # fuser -m /export/home/
/export/home/: 16380c
4.关闭进程
alexsvr:/export/home # fuser -v -k 进程名
fuser可以发送如下的信号:
nassvr:/export/home # fuser -l /export/home
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
UNUSED
kill的时候加上-i参数,则在杀死进程前需要进行确认。