0

On Linux and other POSIX (?) operating systems - how to get name and parent pid of given (by pid) process? Currently I'm reading /proc but OSX doesn't have it. On OSX I'm using libproc but that doesn't work on Linux:

int ret = proc_pidpath (pid, pathbuf, sizeof(pathbuf));
if ( ret <= 0 ) {
    _dbg("   %s\n", strerror(errno));
    return false;
}
Jerry Epas
  • 235
  • 2
  • 9

1 Answers1

1

Unfortunately, when it comes to process info, every OS does things differently. If you only need to know about user-launched apps, look into the NSWorkspace class's runningApplicationWithProcessIdentifier: method. Otherwise, you'll have to use a platform-specific sysctl as described here:

https://developer.apple.com/legacy/library/qa/qa2001/qa1123.html#//apple_ref/doc/uid/DTS10001671

See also this stack overflow question:

Programmatically check if a process is running on Mac

Community
  • 1
  • 1
dgatwood
  • 9,879
  • 1
  • 26
  • 49