免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1180 | 回复: 0
打印 上一主题 下一主题

fuser命令在linux系统中用来根据文件或文件结构识别进程。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-29 16:30 |只看该作者 |倒序浏览

fuser 这个命令是我在查ORACLE错误的时候用到的一个命令,顺便搜集了点关于它的资料供大家分享一下。

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)  
Here is an example of fuser running under Linux:
linux# /usr/sbin/fuser //:     1r     1c     2r     2c     3r     3c     4r     4c252r   252c   275r   275c   286r   286c   300r   314r   328r   328c   342r342c   356r   356c   374r   374c   385r   385c   396r   396c   411r   411c412r   412c   413r   413c   414r   414c   415r   415c   416r   416c   417r417c   418r   418c   419r   419c   420r   420c   455r   470r   470c   485r485c   500r   500c   538r   538c   539r   539c   540r   540c   541r   541c542r   542c   543r   543c   544r   544c   546r   546c   548r   548c   551r551c   556r   569r   591r   597r   610r   612r   614r   614c   618r   626r628r   636r   646r  7090r  7090c  7092r  7243r  7288r  7288c  7290r  7303r

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/76389/showart_1157882.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP