如何判断进程是否在用户界面进程中?
如何从进程中获取它是 UI(用户界面)进程还是非 ui 进程的信息?
我所说的 UI 进程是指 Finder、Dock、系统 UI 服务器或任何其他具有 UI 界面且由 Window Server 使用的 Mac 应用程序。
我想从 ProcessID 确定此信息。
我正在使用 mac os x。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无法仅根据 PID 编号来确定特定进程是什么。原因是:进程 ID 在启动时从 PID=1 开始按顺序分配(某种程度上),并且不同系统的启动可能不同。例如,如果 Finder 或 Dock 崩溃并且必须重新启动,进程 ID 也将被重新分配。
不过,如果您可以使用您拥有的特定 pid 运行终端命令,请执行以下操作:
您将获得进程的文件名,您可以根据您知道的 UI 列表进行检查流程。例如,以下是我的系统上当前登录会话的某些
ps
命令的输出:以下命令将为您提供按进程 ID 顺序排列的进程列表,仅包含名称:
< em>编辑:你也许能够按照你的要求去做,尽管它很复杂。 这个答案提到:
如果你能获取所有的
CGWindow
和它们各自的pid
,那么你不需要运行就能知道所有UI应用的pid
ps
根本没有。Rahul 已为此方法实现了以下代码,他要求我将其添加到我的答案中:
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
pid
that 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
ps
commands 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
CGWindow
s and their respectivepid
s, then you will know thepid
s of all UI applications without needing to runps
at all.Rahul has implemented the following code for this approach, which he requested I add to my answer:
有点复活这个...但是对于 macOS,要获取 UI 的各种元素的进程 ID,您可以使用 lsappinfo 因为也许是 Tiger?联机帮助页显示 2013 年 4 月,但我认为是在提出这个问题的时候,而且可能更早。该命令应以当前拥有 loginwindow 进程的用户身份运行。
Kind of resurrecting this one... But for macOS, to get the process ids of various elements of the UI, you can use lsappinfo since maybe Tiger? The manpage says April, 2013, but I think it was around at the time of this question being asked and probably earlier. The command should be run as the user who currently owns the loginwindow process.
尝试以下操作。
Try the following.
根据 darvidsOn 的说法,以下是您问题的答案。
只需将您拥有的 processid 与数组项进行比较即可获得所需的结果。
On the lines of darvidsOn, below is the answer to your question.
Just compare the processid you have against the array items to get the desired result.