ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

fuser linux

2020-06-03 10:03:09  阅读:392  来源: 互联网

标签:processes default port fuser file linux sockets


  fuser  identify processes using files or sockets

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:

c current directory.  当前目录
e executable being run.  
f open file. f is omitted in default display mode.
F open file for writing. F is omitted in default display mode.
r root directory.
m mmap'ed file or shared library.

fuser returns 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
has been found, fuser returns zero.

 

fuser 在无进程访问指定files or sockets时,为了避免进程错误会返回non-zero结果,以此可作为脚本判断条件

 

In order to look up processes using TCP and UDP sockets, the corresponding name space has to be selected with the -n option. By
default fuser will 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 the local and remote port, and the remote address. All fields are optional, but commas in front of missing fields
must be present:

[lcl_port][,[rmt_host][,[rmt_port]]]

 

fuser可查询使用sockets的进程,使用namespace的概念

 

 F说明httpd进程对此sockets有写权限

 

 fuser只会把pid输出到stdout,其余信息输出到stderr

 

 上面是lsof显示结果,可作为对比

 

fuser可用远端ip或端口作为查询条件,但必须遵从特点格式,

[lcl_port][,[rmt_host][,[rmt_port]]]    前面省略的必须以,分隔

 

 192.168.31.109是windows客户端浏览器,可以看到本机与mgt服务器建立了两个sshd会话,其实就是打开两个pts终端

 

 

 ACCESS中的e表明/usr/bin/passwd是作为可执行程序被运行,我在另一个终端运行了passwd命令

 

 不加-v选项fuser默认不显示系统默认的挂载点,加-v后可看到ACCESS为mount,显示一条ACCESS为/mount的记录其PID为kernel,这是为什么/etc/fstab文件发生挂载错误,会进入emergency模式的原因,因为是在kernel级别产生了错误.

 

 上面为利用rc-local服务挂载的,同样ACCESS为mount,PID为kernel,但是挂载错误,不会导致系统崩溃

 

Either symbolic or numeric values can be used for IP addresses and port numbers.

fuser outputs only the PIDs to stdout, everything else is sent to stderr.

-k, --kill
Kill processes accessing the file. Unless changed with -SIGNAL, SIGKILL is sent. An fuser process never kills itself, but may
kill other fuser processes. The effective user ID of the process executing fuser is set to its real user ID before attempting
to kill.

结束访问目标文件的进程,默认发送SIGKILL信号,此信号不能被阻塞,处理,忽略,但是当前fuser进程不会杀死自己,可能杀死其他fuser进程

 

 

 

 /dev/sda3作为一个pv存在,上面承载了两个lv,必须直接指定lv才能显示正确结果

 

 

 打开一个tail进程访问trap.sh文件

 

 另一终端使用fuser查看,可看到tail对trap.sh有只读权限

 

 发送-TERM信号对使用trap.sh的tail进程

 

 

 

 

 

 HUP信号的情况

标签:processes,default,port,fuser,file,linux,sockets
来源: https://www.cnblogs.com/dissipate/p/13035642.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有