How can I programmatically get the list of open file descriptors for a given PID on OS X?

最后都变了- 提交于 2019-12-04 23:35:41

问题


Everything I've seen says to use lsof -p, but I'm looking for something that doesn't require a fork/exec.

For example on Linux one can simply walk /proc/{pid}/fd.


回答1:


You can use proc_pidinfo with the PROC_PIDLISTFDS option to enumerate the files used by a given process. You can then use proc_pidfdinfo on each file in turn with the PROC_PIDFDVNODEPATHINFO option to get its path.



来源:https://stackoverflow.com/questions/15583563/how-can-i-programmatically-get-the-list-of-open-file-descriptors-for-a-given-pid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!