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
This returns all the user applications in a
NSArrayas instances ofNSRunningApplicationwhich has a propertyprocessIdentifier.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
activationPolicyproperty of theNSRunningApplicationyou could get the Windowed state. I modified theAppListcode to make it show only the windowed applications as shown below. This matches what the activity monitor shows.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
GetBSDProcessListand Carbon’sGetProcessInformationare not recommended anymore.