未加星标

fuser命令使用示例-Linux

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

fuser 帮助管理员通过某个文件/ socket 找到正在使用它的进程,可以显示出当前哪个程序在使用哪个文件、目录、甚至网络端口,并给出程序进程的详细信息。

fuser 语法:

fuser [options] [file|socket] fuser [options] -SIGNAL [file|socket] fuser -l

查看哪个进程正在使用某个目录:

fuser . fuser /home/snail

输出正在访问 /home/snail 目录的进程 PID :


fuser命令使用示例-Linux

使用 -v 输出详细信息:


fuser命令使用示例-Linux

ACCESS 代表访问类型,类型如下:

c -当前目录 e -可执行文件 f -打开文件 F -写文件 r -root目录 m -共享库或mmap文件

查看哪个进程正在使用某个文件:

fuser -v -m ~/.bashrc
fuser命令使用示例-Linux

杀掉正在使用某个文件/ socket 的进程:

sudofuser -k . sudofuser -ki .# 交互式
fuser命令使用示例-Linux

默认通过发送 SIGKILL 杀掉进程,也可以使用 -SIGNAL 选项指定要发送的信号:

sudofuser --list-signals# 查看可使用的信号
fuser命令使用示例-Linux

例如,给所有访问 /boot 目录的进程发送 HUP 信号:

sudofuser -k -HUP /boot

更多信息,查看帮助:

man fuser FUSER(1)UserCommandsFUSER(1) NAME fuser - identifyprocessesusingfilesor sockets SYNOPSIS fuser [-fuv] [-a|-s] [-4|-6] [-c|-m|-n space] [ -k [-i] [-M] [-w] [-SIGNAL] ] name ... fuser -l fuser -V DESCRIPTION fuserdisplaysthePIDsofprocessesusingthespecifiedfilesorfile systems.In thedefault displaymode, each filenameis followedby a letterdenotingthetypeofaccess: ccurrentdirectory. eexecutablebeingrun. fopenfile.f is omittedin default displaymode. Fopenfilefor writing.F is omittedindefaultdisplay mode. rrootdirectory. mmmap'ed file or shared library. fuserreturns a non-zero return code if none of the specified files is accessed or in case of a fatal error.If at least one access hasbeen found, fuser returns zero. Inordertolookup processes using TCP and UDP sockets, the corre sponding name space has to be selected with the -n option.Bydefault fuserwill look in both IPv6 and IPv4 sockets.To change the default, behavior, use the -4 and -6 options.The socket(s) can be specified by thelocalandremoteport,and the remote address.All fields are optional, but commas in front of missing fields must be present: [lcl_port][,[rmt_host][,[rmt_port]]] Either symbolic or numeric values can be used for IP addresses and port numbers. fuseroutputsonlythePIDstostdout, everything else is sent to stderr. OPTIONS -a, --all Show all files specified on the command line.By default,only files that are accessed by at least one process are shown. -c Same as -m option, used for POSIX compatibility. -f Silently ignored, used for POSIX compatibility. -k, --kill Kill processes accessing the file.Unless changed with -SIGNAL, SIGKILL is sent.An fuser process never kills itself,butmay killotherfuserprocesses. TheeffectiveuserID of the process executing fuser issettoitsrealuserIDbefore attempting to kill. -i, --interactive Asktheuserforconfirmation before killing a process. This option is silently ignored if -k is not present too. -l, --list-signals List all known signal names. -m NAME, --mount NAME NAME specifies a file on a mounted file system or a block device thatismounted. Allprocesses accessing files on that file system are listed.If a directoryfileisspecified,itis automaticallychangedtoNAME/. to use any file system that might be mounted on that directory. -M, --ismountpoint Request will be fulfilled only if NAME specifiesamountpoint. Thisisan invaluable seatbelt which prevents you from killing the machine if NAME happens to not be a filesystem. -w Kill only processes which have writeaccess. Thisoptionis silently ignored if -k is not present too. -n SPACE, --namespace SPACE Selectadifferentnamespace. Thename spaces file (file names, the default), udp (local UDP ports), and tcp(localTCP ports)are supported.For ports, either the port number or the symbolic name can be specified.If there is noambiguity,the shortcut notation name/space (e.g. 80/tcp) can be used. -s, --silent Silentoperation.-u and -v are ignored in this mode.-a must not be used with -s. -SIGNAL Use the specified signal instead of SIGKILLwhenkillingpro cesses.Signals canbespecifiedeitherbyname(e.g. -HUP)orby number (e.g.-1).This option is silently ignored if the -k option is not used. -u, --user Append the user name of the process owner to each PID. -v, --verbose Verbosemode. Processesareshownin a ps-like style.The fields PID, USER and COMMAND are similar tops. ACCESSshows howthe process accesses the file.Verbose mode will also show when a particular file is being access as amountpoint,knfs exportorswapfile.In this case kernel is shown instead of the PID. -V, --version Display version information. -4, --ipv4 Search only for IPv4 sockets.This option must not be used with the -6 option and only has an effect with the tcp and udp names paces. -6, --ipv6 Search only for IPv6 sockets.This option must not be used with the -4 option and only has an effect with the tcp and udp names paces. -Reset all options and set the signal back to SIGKILL. FILES /proclocation of the proc file system EXAMPLES 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. RESTRICTIONS Processes accessing the same file or file system several timesinthe same way are only shown once. If the same object is specified several times on the command line, some of those entries may be ignored. fuser may only be able to gather partial informationunlessrunwith privileges. Asa consequence, files opened by processes belonging to other users may not be listed andexecutablesmaybeclassifiedas mapped only. Installingfuser SUID root will avoid problems associated with partial information, but may be undesirable for security and privacy reasons. udp and tcp name spaces, and UNIX domain sockets can't besearchedwith kernelsolderthan 1.3.78. Accessesbytheke

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: LinuxRESTTIFUSUIPv4CTIOPTIPv6
分页:12
转载请注明
本文标题:fuser命令使用示例-Linux
本站链接:http://www.codesec.net/view/483392.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(37)