Skip to content

proc_pidinfo return value #1

@jief666

Description

@jief666

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 !!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions