1

In my Cocoa app I am detecting visible windows and getting PID of their owners. Then for ever PID I create NSRunningApplication object (using runningApplicationWithProcessIdentifier:) to get additional info (localized name, path, attributes etc.)

Everything works fine until I try to create NSRunningApplication with PID 88 which belongs (in my case) to Window Server. It just do not create that object and in accordance with Apple manual it returns nil - in other words: There is no process with that PID.

How is it possible? If it wouldn't exist I would't be able to get its PID and ps would't show it.

Any advice?

PhoenixS
  • 1,016
  • 1
  • 9
  • 23

2 Answers2

2

From the documentation (emphasis added):

Overview
NSRunningApplication is a class to manipulate and provide information for a single instance of an application. Only user applications are tracked; this does not provide information about every process on the system.

  • but what does "user application" mean? i have a user XPC mach process that cannot be tracked with NSRunningApplication – Peter Lapisu Oct 14 '14 at 12:54
  • A "user application" is, for example, any application which appears in the Dock when running. It's a process which has a GUI, etc. something the (normal end-) user can directly interact with. NOT a daemon process. –  Oct 14 '14 at 13:07
  • all right, but many of the "apps" returned don't have a GUI, nor they appear in dock (like helpers etc) – Peter Lapisu Oct 14 '14 at 13:43
1

The window server is not a user process. If it does not work with admin privileges then you won't be able to do so at all.

Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52
  • In other words - if I want to get info about not-my processes I have to do it another way - not using NSRunningApplication? – PhoenixS Dec 06 '11 at 16:28
  • did you find any solution? i have a similar problem http://stackoverflow.com/questions/26361106/nsworkspace-runningapplications-doesnt-return-my-xpc-mach-service – Peter Lapisu Oct 14 '14 at 12:53
  • @PeterLapisu "Only user applications are tracked; this does not provide information about every process on the system" try creating an app that runs on the same user as the process you are trying to get information from, send that data back to your app, I wouldn't see any other way doing it with cocoa. – Antwan van Houdt Nov 18 '14 at 19:00