0

Given the PID of a process, how can I check if it's a windowed process? I am looking for a solution on OSX.

Objective-C/ C solutions are wanted. I am on OSX Mountain Lion.

I am defining a windowed process as a process that can be seen when the "Windowed Processes" tab is selected in activity monitor. http://cl.ly/FeXR

4
  • This answer explains a process in raw win32 where you check each running window to see if it belongs to the process you want. Perhaps that helps?
    – chris
    Sep 6, 2012 at 18:28
  • @chris Thanks but I am looking for a solution for OSX in Objective-C or C.
    – fdh
    Sep 6, 2012 at 18:31
  • For whatever reason, despite the numerous times you said OSX, it never registered in my brain. Apologies. Perhaps there's a similar method for OSX.
    – chris
    Sep 6, 2012 at 18:40
  • @shellter You can't be serious? Did you take the time to read the other question? That question asks what defining characteristics applications with icons in Activity Monitor have in common. This question asks how to check if a process is a windowed process.
    – fdh
    Sep 6, 2012 at 22:59

1 Answer 1

2
[NSWorkspace runningApplications] 

This returns all the user applications in a NSArray as instances of NSRunningApplication which has a property processIdentifier.

Or you can use runningApplicationWithProcessIdentifier: directly to get the application with a specified PID.

Here is the sample code: http://developer.apple.com/library/Mac/#samplecode/AppList/Introduction/Intro.html

Through the activationPolicy property of the NSRunningApplication you could get the Windowed state. I modified the AppList code to make it show only the windowed applications as shown below. This matches what the activity monitor shows.

enter image description here

In particular, you are looking for the NSApplicationActivationPolicyRegular.

Note the restrictions however. This only works for user owned processes.

All other methods are deprecated and may not work in future. Methods like GetBSDProcessList and Carbon's GetProcessInformation are not recommended anymore.

3
  • I don't see how this answers my question. You have simply provided a way to retrieve all user owned processes; the only mention of checking if a process is windowed doesn't answer the question in any way.
    – fdh
    Sep 6, 2012 at 21:21
  • Have you even tried the code by yourself and read the documentation that I had pointed to? Anyway, I have updated my answer to reflect how to do that. Sep 7, 2012 at 8:32
  • The edit answer was very helpful! It works perfectly. Thank You for the help!
    – fdh
    Sep 8, 2012 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.