lsof how to get the process;s fd info?

https://github.com/apple-oss-distributions/lsof/blob/c48c28f51e82a5d682a4459bdbdc42face73468f/lsof/dialects/darwin/libproc/dproc.c#L753

proc_pidinfo(pid, PROC_PIDLISTFILEPORTS, 0, NULL, 0))

the retval of proc_pidinfo is always zero

how lsof works?

Answered by DTS Engineer in 826916022
Written by shihhuangti in 775302021
the retval of proc_pidinfo is always zero

The issue here is that you’re asking for PROC_PIDLISTFILEPORTS. That returns info about file ports, that is, Mach ports that wrap a file descriptor [1]. What you want is PROC_PIDLISTFDS, which lists the file descriptors.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] File ports are one of those things that, IMO, should be API but aren’t )-: You can learn more about them in Darwin.

Written by shihhuangti in 775302021
the retval of proc_pidinfo is always zero

The issue here is that you’re asking for PROC_PIDLISTFILEPORTS. That returns info about file ports, that is, Mach ports that wrap a file descriptor [1]. What you want is PROC_PIDLISTFDS, which lists the file descriptors.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] File ports are one of those things that, IMO, should be API but aren’t )-: You can learn more about them in Darwin.

lsof how to get the process;s fd info?
 
 
Q