Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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

like image 474
fmoo Avatar asked Mar 23 '13 05:03

fmoo


People also ask

Which command is used to identify list of open files by a process?

The open source lsof command is also useful for providing information about files opened by processes, and files opened under specific user accounts.

How do you find the list of open files by a specific process in Linux?

The Linux lsof command lists information about files that are open by processes running on the system. The lsof command is an acronym for, “list of open files.” In this article I'll share some lsof command examples.


1 Answers

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.

like image 137
bdash Avatar answered Sep 17 '22 23:09

bdash