I'm trying to get process list with bash "ps" command via NSTask on OS X.
When I turn on App Sandbox, application crashes and I got this error in console:
14.06.14 2:16:35,426 sandboxd[356]: ([74340]) MyApp(74340) deny forbidden-exec-sugid
Is there any solution for this problem?
Fragment of code:
NSTask *topTask = [NSTask new];
[topTask setLaunchPath:@"/bin/ps"];
[topTask setArguments:[NSArray arrayWithObjects:
@"-eo", @"pid,pcpu,rss,comm", // output columns
nil]];
ps
is a setuid root process and, as such, can't be run from within the sandbox.
What you can have inside the sandbox is pid, rss, comm
but not pcpu
from [[NSWorkspace sharedWorkspace] runningApplications]
which will give you an NSArray of NSRunningApplication
You can probably achieve equivalent functionality with libproc () or sysctl. Similar question for statistics
Depending what you'd like to achieve, here's an interesting link on observing processes: TN2050