-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hi,
first of all, thanks for that ! That's exactly what I needed.
I think there is a little improvment :
replace the 2nd call to proc_pidinfo
proc_pidinfo(pid, PROC_PIDLISTFDS, 0, procFDInfo, bufferSize);
int numberOfProcFDs = bufferSize / PROC_PIDLISTFD_SIZE;
by
int returnedSize = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, procFDInfo, bufferSize);
int numberOfProcFDs = returnedSize / PROC_PIDLISTFD_SIZE;
Basically, you can't be sure that the second call will return the same value as the first call as files may have been opened or closed in between calls.
If you look at implementation of proc_pidfdlist (https://opensource.apple.com/source/xnu/xnu-792.13.8/bsd/kern/proc_info.c), they add 20 to buffer size, just in case few files are opened between call !
Thanks again !!!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels