Access to process unique id

Hi Everyone,

In libproc, there is a flavour for proc_pidinfo() PROC_PIDUNIQIDENTIFIERINFO, which as the name suggests, returns a struct of values that uniquely identify a process - more reliably than a pid.

In particular, it seems to have a 64 bit value that appears to be unique forever (or at least until system restart), thus shouldn't suffer from pid reuse races.

The problem is that this interface is gated behind #ifdef PRIVATE, and as such is pretty much the antithesis of 'published api'. So I guess my question is, is there a 'legit' way of accessing this value (or an equivalent) ? The call seems to work fine, and the number appears unique..

thanks, nick

Thanks for the post, this is a great post and hope many developers jump into this thread and provide suggestions and opinions of the best way to accomplish that.

proc_pidinfo() PROC_PIDUNIQIDENTIFIERINFO looks something I haven't use to be honest. Using them in production code sounds risky because is subject to breakage in future macOS/iOS updates without warning? If your concern about PID reuse races you should not use PIDs at all.

If you are iterating over running processes or monitoring a specific process and want to ensure the PID hasn't been reused by a new process, the standard approach is to combine the PID with the process's start time, it is practically impossible for a PID to be reused in the exact same microsecond.

Albert
  Worldwide Developer Relations.

Access to process unique id
 
 
Q