简体   繁体   中英

Unable to find running application in Cocoa

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM