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
.
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
.
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.
sys/proc_info.h
seems relatively self-explanatory in terms of interpreting the information available from the system calls, and the implementation of the system calls is available in the kernel open source if you want to understand more about how it all works. –
Bukharin © 2022 - 2024 — McMap. All rights reserved.