denniss
denniss

Reputation: 17589

Running /bin/ps with NSTask with App Sandboxing enabled

I have a cocoa app that needs to get a list of processes. After enabling app sandboxing, I get /bin/ps: Operation not permitted. Is there another way of doing this that's compatible with app sandboxing? I am running this via NSTask

Upvotes: 1

Views: 588

Answers (2)

mahal tertin
mahal tertin

Reputation: 3416

You can use [[NSWorkspace sharedWorkspace] runningApplications] to get a list of all processes. This will return an array of NSRunningApplications.

https://developer.apple.com/reference/appkit/nsworkspace https://developer.apple.com/reference/appkit/nsworkspace/1534059-runningapplications https://developer.apple.com/reference/appkit/nsrunningapplication

Upvotes: 1

tbodt
tbodt

Reputation: 16987

You can't run ps from the sandbox, because it is a set-uid root program.

There is no other documented way to get a process list. There is, however, an undocumented API described in libproc.h. I'm not sure if you can use it from the sandbox, but it's worth a try.

Upvotes: 1

Related Questions