fuser displays the PIDs of processes usingthe specified files or file systems. In the default display mode, each filename is followed by a letter denoting the type of access:
# -)5、m :表示 mmap 过的文件或者共享库
c
current directory.
e
executable being run.
f
open file. f is omitted in default displaymode.
F
open file for writing. F is omitted indefault display mode.
r
root directory.
m
mmap'ed file or shared library.
fuser returns a non-zero return code ifnone of the specified files is accessed or in case of a fatal error. If atleast one access has been found, fuser returns zero.
In order to look up processes using TCP andUDP sockets, the corresponding name space has to be selected with the -noption. By default fuser will look in both IPv6 and IPv4 sockets. To change thedefault, behavior, use the -4 and -6 options. The socket(s) can be specified bythe local and remote port, and the remote address. All fields are optional, butcommas in front of missing fields must be present:
Either symbolic or numeric values can beused for IP addresses and port numbers.
# 注释;在端口方面,你可以用端口名或者数字表示
fuser outputs only the PIDs to stdout,everything else is sent to stderr.
# 注释:fuser 只输出 PID 到 stdout ,其他都送给 stderr
Options
-a
Show all files specified on the commandline. By default, only files that are accessed by at least one process areshown.
# 注释:-a 显示所有指定文件的情况,即使没有进程访问它们。
-c
Same as -m option, used for POSIXcompatibility.
-f
Silently ignored, used for POSIXcompatibility.
-k
Kill processes accessing the file. Unlesschanged with -signal, SIGKILL is sent. An fuser process never kills itself, butmay kill other fuser processes. The effective user ID of the process executingfuser is set to its real user ID before attempting to kill.
# 注释:-k 表示杀死访问指定文件的进程。默认发送 SIGKILL (-9)信号。fuser 进程永远不会杀死自己。
# 但可能杀死其他 fuser 进程。在尝试杀死进程前,fuser 会改变 euid 为 ruid
-i
Ask the user for confirmation beforekilling a process. This option is silently ignored if -k is not present too.
# 注释:-i 表示交互模式,在杀死进程前会提示。必须和 -k 合用
-l
List all known signal names.
# 注释:-l 列出所有已知的信号
-m
name specifies a file on a mounted filesystem or a block device that is mounted. All processes accessing files on thatfile system are listed. If a directory file is specified, it is automaticallychanged to name/. to use any file system that might be mounted on thatdirectory.
# 注释:-m 表示指定文件所在的文件系统或者块设备(处于 mount 状态)。所有访问该文件系统的进程都被列出。
# 假如指定了一个目录,则自动在后面加上 '/' 表示该挂载在该目录上的文件系统
-n space
Select a different name space. The namespaces file (file names, the default), udp (local UDP ports), and tcp (localTCP ports) are supported. For ports, either the port number or the symbolicname can be specified. If there is no ambiguity, the shortc utnotation name/Ispace (e.g. 80/tcp ) can be used.
# 注释:-n 指定 sockets 的协议类型。可以是 file(默认)、udp、tcp 。
# 你甚至可以使用'<port>/<proto>' 的简写方式,只要不存在异义的话
-s
Silent operation. -u and -v are ignored inthis mode. -a must not be used with -s.
# 注释:-s 表示安静模式。-u 和 -v 会被忽略,-a 不能和 -s 一起使用
-signal
Use the specified signal instead of SIGKILLwhen killing processes. Signals can be specified either by name (e.g. -HUP) orby number (e.g. -1). This option is silently ignored if the -k option is notused.
# 注释:-<signal> 指定信号
-u
Append the user name of the process ownerto each PID.
# 注释:-u 表示在 PID 后面加上进程的 owner
-v
Verbose mode. Processes are shown in aps-like style. The fields PID, USER and COMMAND are similar to ps. ACCESS showshow the process accesses the file. If the access is by the kernel (e.g. in thecase of a mount point, a swap file, etc.), kernel is shown instead of the PID.
# 注释:-v 表示 verbose 模式。进程以 ps 的方式显示,包括 PID、USER、COMMAND、ACCESS 字段
# 如果是内核访问的(例如 mount point、swap 文件),则显示为 kernel 而不是 pid
-V
Display version information.
-4
Search only for IPv4 sockets. This optionmust not be used with the -6 option and only has an effect with the tcp and udpnamespaces.
-6
Search only for IPv6 sockets. This optionmust not be used with the -4 option and only has an effect with the tcp and udpnamespaces.
-
Reset all options and set the signal backto SIGKILL.
# 注释:‘-’ 表示重置所有选项并把信号设置为 SIGKILL
Files
/proc location of the procfile system
Examples
fuser -km /home
kills all processesaccessing the file system /home in any way.
# 注释:fuser -km /home 杀死所有访问 /home 文件系统的进程
if fuser -s /dev/ttyS1; then :; elsesomething; fi
invokes something if noother process is using /dev/ttyS1.
fuser telnet/tcp
shows all processes atthe (local) TELNET port.
http://blog.sina.com.cn/s/blog_59af21260100tv1m.html
fuser 概述
fuser命令是用来显示所有正在使用着指定的file, file system 或者 sockets的进程信息。
例一:
在例子一中,使用了-m和-u选项,用来查找所有正在使用/mnt/usb1的所有进程的PID已经该进程的OWNER,如1347c(root),其中1347是进程PID,root是该进程的OWNER。
fuser会显示正在使用指定的file,file system 或者 sockets的进程的PID。在默认的显示模式下,每个文件名之后会跟随一个字符,用来指示当前的访问类型。
如下所示:
c
current directory.
e
executable being run.
f
open file.
F
open file for writing.
r
root directory.
m
mmap'ed file or shared library
同时fuser 可以用来查找哪些进程正在使用指定的network port。
fuser 的返回值:
fuser如果没有找到任何进程正在使用指定的file, filesystem 或 socket, 或者在查找过程中发生了fatal error,则返回non-zero 值。
fuser如果找到至少一个进程正在使用指定的file, filesystem 或 socket,则返回zero。 fuser 常用场景
fuser通常被用在诊断系统的“resource busy”问题,通常是在你希望umount指定的挂载点得时候遇到。如果你希望kill所有正在使用某一指定的file, file system or sockets的进程的时候,你可以使用-k option。
fuser –k /path/to/your/filename
这时fuser会向所以正在使用/path/to/your/filename的进程发送SIGKILL。如果你希望在发送之前得到提示,可以使用-i 选项。
fuser –k –i /path/to/your/filename fuser的其他有用的参数
-k
kills all processaccessing a file. For example fuser -k /path/to/your/filename kills all processes accessing thisdirectory without confirmation. Use -i for confirmation
-i
interactive mode. Promptbefore killing process
-v
verbose.
-u
append username
-a
display all files
-m
name specifies a file on a mounted filesystem or a block device that is mounted. All processes accessing files on thatfile system are listed. If a directory file is specified, it is automaticallychanged to name/. to use any file systemthat might be mounted on that directory.
http://www.cnblogs.com/yuboyue/archive/2011/07/18/2109838.html