加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 教程文章 > Linux

有用的fuser命令: 显示socket的进程信息

时间:2014-07-05 10:44:45  来源:  作者:

fuser 概述

fuser命令是用来显示所有正在使用着指定的file, file system 或者 sockets的进程信息。

例一:

#fuser –m –u /mnt/usb1
/mnt/usb1:  1347c(root)  1348c(guido)  1349c(guido)

在例子一中,使用了-m和-u选项,用来查找所有正在使用/mnt/usb1的所有进程的PID已经该进程的OWNER,如1347c(root),其中1347是进程PID,root是该进程的OWNER。

fuser会显示正在使用指定的file,file system 或者 sockets的进程的PID。在默认的显示模式下,每个文件名之后会跟随一个字符,用来指示当前的访问类型。

如下所示:

current directory.
executable being run.
open file.
open file for writing.
root directory.
mmap'ed file or shared library

同时fuser 可以用来查找哪些进程正在使用指定的network port。

[root@bl25p-19 /]# fuser -v -n tcp 111

                           USER        PID   ACCESS   COMMAND
111/tcp:             rpc        2848   F....         portmap

 

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 process accessing a file. For example fuser -k /path/to/your/filename kills all processes accessing this directory without confirmation. Use -i for confirmation
-i 
interactive mode. Prompt before killing process
-v 
verbose.
-u 
append username
-a 
display all files
-m 
name specifies a file on a mounted file system or a block device that is mounted. All processes accessing files on that file system are listed. If a directory file is specified, it is automatically changed to name/. to use any file system that might be mounted on that directory. 

fuser is a UNIX command used to show which processes are using a specified file, file system, or unix socket. For example, to check process IDs and users accessing a USB drive:

 $ fuser -m -u /mnt/usb1
 /mnt/usb1:   1347c(root)  1348c(guido)  1349c(guido)

fuser displays the PIDs 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:

current directory.
executable being run.
open file.
open file for writing.
root directory.
mmap'ed file or shared library

fuser can also be used to check what processes are using a network port:

 $ fuser -v -n tcp 80
                      USER        PID ACCESS COMMAND
 80/tcp:              root       3067 F.... (root)httpd
                      apache     3096 F.... (apache)httpd
                      apache     3097 F.... (apache)httpd

fuser returns a non-zero code if none of the files are accessed or in case of a fatal error. If at least one access has succeeded, fuser returns zero. The output of "fuser" may be useful in diagnosing "resource busy" messages arising when attempting to unmount filesystems.

Options

-k 
kills all process accessing a file. For example fuser -k /path/to/your/filename kills all processes accessing this directory without confirmation. Use -i for confirmation
-i 
interactive mode. Prompt before killing process
-v 
verbose.
-u 
append username
-a 
display all files
-m 
name specifies a file on a mounted file system or a block device that is mounted. All processes accessing files on that file system are listed. If a directory file is specified, it is automatically changed to name/. to use any file system that might be mounted on that directory.

Also note that -k sends a SIGKILL to all process. Use the -signal to send a different signal. For a list of signals supported by the fuser run 'fuser -l'

Related commands

  • The list of all open files and the processes that have them open can be obtained through the lsof command.
  • The equivalent command on BSD operating systems is fstat(1)

 

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
在CentOS下搭建Android 开发环境
在CentOS下搭建Androi
轻松搭建属于自己的Ubuntu发行版
轻松搭建属于自己的Ub
利用SUSE Studio 打造自己的个性化Linux发行版
利用SUSE Studio 打造
那些采用PHP技术的IT大企业
那些采用PHP技术的IT大
相关文章
    无相关信息
栏目更新
栏目热门