[英]How can I programmatically get the list of open file descriptors for a given PID on OS X?
Everything I've seen says to use lsof -p
, but I'm looking for something that doesn't require a fork/exec. 我见过的所有内容都说使用
lsof -p
,但我正在寻找一些不需要fork / exec的东西。
For example on Linux one can simply walk /proc/{pid}/fd
. 例如在Linux上,可以简单地走
/proc/{pid}/fd
。
You can use proc_pidinfo
with the PROC_PIDLISTFDS
option to enumerate the files used by a given process. 您可以将
proc_pidinfo
与PROC_PIDLISTFDS
选项一起使用,以枚举给定进程使用的文件。 You can then use proc_pidfdinfo
on each file in turn with the PROC_PIDFDVNODEPATHINFO
option to get its path. 然后,您可以使用
proc_pidfdinfo
依次在每个文件与PROC_PIDFDVNODEPATHINFO
选项来获得它的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.