简体   繁体   English

热熔器如何以非root用户身份在套接字上报告?

[英]how does fuser report on sockets as non-root user?

I'm trying to use fuser to find the pids of processes I own which have certain TCP ports open. 我正在尝试使用定影器来查找我拥有的具有特定TCP端口打开的进程的pid。

In the fuser man page it says: 在热熔器手册页中说:

... The most common time this problem occurs is when looking for TCP or UDP sockets when running fuser as a non-root user. ...发生此问题的最常见时间是当以非root用户身份运行熔丝器时寻找TCP或UDP套接字。 In this case fuser will report no access. 在这种情况下,定影器将报告无访问权限。 ... ...

However, on my Ubuntu box, fuser does report sockets open for processes that I own, eg: 但是,在我的Ubuntu盒子上,fuser确实报告了我拥有的进程的套接字打开,例如:

perl -MIO::Socket 'IO::Socket::INET->new(Listen => 10, LocalPort => 3000)' & perl -MIO :: Socket'IO :: Socket :: INET-> new(Listen => 10,LocalPort => 3000)'&

fuser -n tcp 3000 热熔器-n TCP 3000

Question: how are things set up to allow this to happen? 问题:如何设置才能使这种情况发生? Is it a kernel config option? 它是内核配置选项吗?

Thanks! 谢谢!

Note: the question is: how are some linux distros configured so that fuser will report processes owning sockets when fuser is run as a normal user? 注意:问题是:如何配置一些Linux发行版,以便在以正常用户身份运行熔凝器时,熔凝器将报告拥有套接字的进程? One one Ubuntu distro "fuser -n tcp 3000" will report a process if I own the process, yet on another linux distro (I think Centos) it won't report the process even if I own it. 如果我拥有一个Ubuntu发行版“ fuser -n tcp 3000”,它将报告一个进程,但是在另一个Linux发行版(我认为是Centos)上,即使我拥有它也不会报告该进程。

fuser goes through the /proc file system ( proc(5) ) working through the /proc/[pid]/fd/ directory and checking the file descriptors. fuser遍历/proc文件系统( proc(5) ),遍历/proc/[pid]/fd/目录并检查文件描述符。 Processes owned by you have corresponding /proc entries again owned by you. 您拥有的进程又拥有自己的相应/proc条目。 This allows you to check your processes, but not others. 这使您可以检查自己的过程,但不能检查其他过程。

One very useful tool to see what given program is doing is strace(1) . strace(1)是一个非常有用的工具,它可以查看给定程序的工作方式。 For example, you can see what system calls, and with what arguments, are done by the fuser : 例如,您可以看到系统调用什么,以及用什么参数由fuser完成:

~$ strace fuser -n tcp 3000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM