ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 【转】fuser命令

【转】fuser命令

原创 Linux操作系统 作者:杨奇龙 时间:2011-04-15 23:36:45 0 删除 编辑
fuser命令在linux系统中用来根据文件或文件结构识别进程。
使用权限:超级用户
语法格式:
  fuser [ -c | -d | -f ] [ -k | -K { SignalNumber | SignalName }] [ -u ] [ -x ] [ -V ]File ...
使用说明:
  此 fuser 命令列出了本地进程的进程号,那些本地进程使用 File 参数指定的本地或远程文件。
对于阻塞特别设备,此命令列出了使用该设备上任何文件的进程。
每个进程号后面都跟随一个字母,该字母指示进程如何使用文件。
c 将此文件作为当前目录使用。
e 将此文件作为程序的可执行对象使用。
r 将此文件作为根目录使用。
s 将此文件作为共享库(或其他可装载对象)使用。
进程号被写入标准输出(在进程号之间有空格的行中)。
一个换行符被写入标准错误(在每个文件操作数的最后一个输出之后)。其他所有输出被写入标准错误。
此 fuser 命令不会检测有 mmap 区域的进程,其中相关的文件描述符已从此被关闭。
主要参数:
  -c 包含 File 的文件系统中关于任何打开的文件的报告。
  -d 暗示使用了 -c 和 -x 标志。
关于任何与文件系统(自父目录删除的)无链接的打开文件的报告。
当与 -V 标志一起使用时,它也会报告被删除文件的节点号和大小。
-f 仅对文件的打开实例报告。
-K SignalNumber | SignalName 将指定信号发送到每个本地进程。
仅有 root 用户能终止另一用户的进程。信号可以指定为信号名称(如 -9)或 KILL(用于 SIGKILL 信号)。
SignalName 的有效值是 kill -l 命令所显示的那些值。
-k 将 SIGKILL 信号发送到每个本地进程。仅有 root 用户能终止另一用户的进程。
注:
fuser -k 或 -K 可能无法检测和杀死程序开始运行后立即创建的新进程。
-u 为进程号后圆括号中的本地进程提供登录名。
-V 提供详细输出。
-x 与 -c 或 -f 连用,报告除标准 fuser 输出以外的可执行的和可载入的对象。
应用实例:
  要列出使用 /etc/passwd 文件的本地进程的进程号,请输入:
fuser /etc/passwd
要列出使用 /etc/filesystems 文件的进程的进程号和用户登录名,请输入:
fuser -u /etc/filesystems
要列出正在使用已从给定文件系统删除的文件的全部进程,请输入:
fuser -d /usr
fuser -km /home
kills all   processes   accessing   the   file system /home in any way.
if fuser -s /dev/ttyS1; then :; else something; fi
invokes something if no other process is using /dev/ttyS1.
fuser telnet/tcp
shows all processes at the (local) TELNET port.
fuser [-a|-s] [-n space] [-signal] [-kimuv] name ...   [-]
[-n space] [-signal] [-kimuv] name ...
fuser -l
fuser -V
c    current directory.
e    executable being run.
f    open   file.   f is omitted in default display mode.
r    root directory.
m    mmap'ed file or shared library.
List Open Files: lsof and fuser-进程相关
The function of these commands is very similar. The goal is to determine what processes have certain files open. lsof is freeware
and thus freely compilable under all Unixes. It is available by default under Linux only.
The main difference between lsof and fuser is that lsof takes both files/filesystems and PIDs as arguments whereas fuser only
accepts files/filesystems.
lsof:
lsof stands for list open files. It lists information about files that are currently open by processes.
In the absence of any options, lsof lists all open files belonging to all active processes
To list all open files for login name ``abe'', or user ID 1234 you would use the -u option. To list files being used by process
456, process 123, or process 789, you would use the -p flag. Putting these criteria together, we would have a command that looks
like this:
lsof -p 456,123,789 -u 1234,abe
The command to list all open files on device /dev/hd4, would look like this:
lsof /dev/hd4
To find the process that has /u/abe/foo open, use:
lsof /u/abe/foo
fuser:
fuser is more widely available (under AIX, HP-UX, IRIX, Linux, Solaris, Tru64 UNIX, and others) and can only be run as root. It
displays the process ID numbers of processes using the specified files or file systems. In the default display mode, each file
name is followed by a letter denoting the type of access (these codes differ from vendor to vendor):
a if the process is using the file as its trace file in /proc (IRIX)
c if the process is using the file as its current directory
e if the process is using the file as the executable being run
f if the process is using the file as an open file (Linux)
m if the process is using the file as a mmaped or shared lib (Linux)
o if the process is using the file as an open file (IRIX, Solaris, Tru64 UNIX))
p if the process is using the file as the parent of its current directory (Tru64 UNIX)
r if the process is using the file as root directory
s if the process is using the file as a shared lib (AIX)
t if the process is using the file as its text file (Solaris)
y if the process is using the file as its controlling terminal (IRIX)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22664653/viewspace-692646/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
MySQL DBA NoSQL DEVOPS

注册时间:2009-10-07

  • 博文量
    1026
  • 访问量
    7843628