How can I get information from a process that it is UI(User Interface) process or non-ui?
With UI process I mean, Finder, Dock, System UI server, or any other mac application which has UI interface and it is used by Window Server.
I want to determine this information from ProcessID.
I am using mac os x.
There is no way to determine based purely on the PID number what a specific process is. The reason for this: Process IDs are assigned (somewhat) sequentially from PID=1 on startup, and startup can be different for different systems. The process ID will also be reassigned if, for example, Finder or Dock crashes and has to be restarted.
If you can run a terminal command with a specific
pidthat you have, though, do this:You’ll get the filename of the process, which you can check against a list of ones you know are UI processes. For example, here is the output of certain
pscommands on my system for my current login session:And the following command will give you a list of processes in order of process ID, with only the name:
EDIT: You may be able to do what you ask, though it is convoluted. This answer mentions:
If you can obtain all the
CGWindows and their respectivepids, then you will know thepids of all UI applications without needing to runpsat all.Rahul has implemented the following code for this approach, which he requested I add to my answer: