Getting process info for other processes?

I'd like to be able to do the equivalent of getrusage(3) for some of our other processes. These are daemons, so they're not connected in any way. Obviously, Activity Monitor and top can do the things I want, but I'm not Apple. 😄

I went down a maze of twisty APIs, all a-Mach, and have decided to ask.

(We're trying to keep track of the processes in the field. We also want to know what's going on if a process has stopped responding but hasn't died. I suppose I could, absolute worst case, periodically send getrusage(3) info to the monitoring process.)

Answered by DTS Engineer in 814840022

Check out proc_pid_rusage in <libproc.h>.

Share and Enjoy

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

Check out proc_pid_rusage in <libproc.h>.

Share and Enjoy

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

Yay that works!

But how can I get thread count? I can't seem to use task_for_pid() (even with an Info.plist that has SecTaskAccess set to true).

Accepted Answer
But how can I get thread count?

Don’t use task_for_pid for this. These days it’s so tightly restricted that it’s only useful for development tools.

Instead, continue down the <libproc.h> route. Specifically, look at the pti_threadnum value returned by proc_pidinfo with either the PROC_PIDTASKINFO or PROC_PIDTASKALLINFO flavour.

Share and Enjoy

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

D'oh! No man pages so I wasn't sure what flavor was supposed to be -- I ended up looking at some XNU code but clearly didn't check all the cases. Thanks!

As always, @DTS Engineer is extremely helpful.

Getting process info for other processes?
 
 
Q