3

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]];
Xaver Kapeller
  • 49,491
  • 11
  • 98
  • 86
baduga
  • 233
  • 1
  • 8

1 Answers1

0

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

Community
  • 1
  • 1
mahal tertin
  • 3,239
  • 24
  • 41
  • Seems libproc also does not give you CPU information on other processses. `proc_pid_rusage` works perfect to get cpu time, but if you activate the sandbox, you get only the cpu time of your self, regardless wich PID you give :( – Axel Zehden Oct 29 '15 at 09:19