Reputation: 3931
I am getting the list of running applications in Cocoa with the following code:
for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) {
MNSLog(@"%@",[app localizedName]);
}
However an application I started from a terminal session is not appearing in the list ('Terminal' is well appearing). The application was started from the same user which is executing the cocoa code.
Is my launched application under Terminal ? And in such a case how can I find its name and arguments ?
Running ps in another terminal session show my process properly.
Upvotes: 3
Views: 397
Reputation: 22930
You can use sysctl
or ps
command to get a list of all BSD processes. Have look at unable to detect application running with another user
Upvotes: 2
Reputation: 119031
Use an NSTask
to execute the ps
Shell command. You can check the ps
man page to determine which arguments you want to pass it based on the information you want to get back. Use NSPipe
and NSFileHandle
to get the results from the task.
If you want to do some filtering you can pipe the ps
output through grep
before your app picks up the result.
For your first question, I think NSWorkspace
can only see apps that use the window server so you will only see Terminal, not the executables that it is running internally.
Upvotes: 2