=Start=
缘由:
我知道在Linux下如何通过pid找到对应的inode信息,但是现在有一个需求就是通过inode找到对应的pid。
正文:
参考解答:
In general, to find what’s at the other end of a socket, you need to iterate through /proc. This can of course mean letting an existing tool such as netstat, lsof or ss do it for you.
The reason for this is that a socket can be opened by different processes. Once a process has opened a socket, it can fork, and the children can change their privileges and switch to different namespaces. It’s also possible to pass file descriptors from a process to an unrelated process, using anciliary data on a unix socket. So arbitrary processes can have the same socket open. There is no such thing as “the PID of a socket”, only “the PIDs of a socket”.
While this doesn’t prove that there’s no way to enumerate the PIDs given the socket, it would be very difficult to design such an interface, especially when you consider that non-root users don’t get to know when files are opened by processes running as a different user. Access through /proc enforces security via permissions, and I’m not aware of any other interface to get the same data. Also, fuser, lsof, netstat and ss all enumerate /proc; if there was another interface, I’d expect someone to use it. So I’m pretty sure that there’s no other way.
参考链接:
https://serverfault.com/questions/707490/how-to-determine-which-processes-have-most-inodes-opened #如何判断哪个进程打开的文件描述符最多?
=END=
《 “Linux下通过inode找pid” 》 有 4 条评论
Docker底层的内核知识——namespace
https://mp.weixin.qq.com/s/YtS0mz5Cw7oTSP97h0V1uA
osquery源码解读之分析process_open_socket
https://blog.spoock.com/2018/12/06/osquery-source-analysis-process-open-socket/
`
1. 说明
2. 使用说明
3. 分析
3.1. 获取pid信息
3.2. 获取进程对应的pid和fd信息
3.3. 获取进程对应的ns信息
3.4. 解析进程的net信息
3.5. 获取进程连接信息
4. 扩展
5. 总结
`
浅谈Cgroups
https://mp.weixin.qq.com/s/3a5k3YA6ALri3BrQWQbOpw
相关文章
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/ch01
https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/6/html/resource_management_guide/ch01
https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt
http://www.infoq.com/cn/articles/docker-kernel-knowledge-cgroups-resource-isolation
这几个示例,帮你深入理解 cgroup 中的 cpuset
https://mp.weixin.qq.com/s/jZN4U10NasdWiOPhiKaNbQ