有人已经在如何确定应用程序没有响应中提出了几乎相同的问题?(确定哪些进程没有响应是困难的部分,杀死它们很容易)。我在这里引用了一个相关的答案:
Not Responding 状态不是进程状态,而是进程已停止与窗口管理器/图形引擎通信。它可以被捆绑在一个循环中,挂在一个套接字上,远程文件,任何让它返回到处理事件的主循环的东西。窗口管理器注意到事件正在排队,因此将其标记为“无响应”
您可能需要编写一个小的 X11 程序来向进程发送虚拟事件,然后在它没有响应时将其杀死。
因此,确定哪些程序没有响应是不可能的,至少在不大量使用 AppleScript/X11 逻辑的情况下是不可能的。
如果你很好奇,这个 AppleScript 小片段(为 Mavericks 制作,可能不适用于其他任何东西)也发布在链接线程上,基本上识别所有无响应的程序,然后向KILL
它们发送信号:
tell application "Activity Monitor" to run --We need to run Activity Monitor
tell application "System Events" to tell process "Activity Monitor"
tell radio button 1 of radio group 1 of group 1 of toolbar 1 of window 1 to click --Using the CPU View
tell outline 1 of scroll area 1 of window 1 -- working with the list
set notResponding to rows whose value of first static text contains "Not Responding" -- Looking for Not responding process
repeat with aProcess in notResponding
set pid to value of text field 5 of aProcess -- For each non responding process retrieve the PID
if pid is not "" then do shell script ("kill -9 " & pid) -- KILL the PID.
end repeat
end tell
end tell
Run Code Online (Sandbox Code Playgroud)
但是,如果您已经确定了一个正在运行的应用程序,您可以使用 杀死它的所有实例sudo killall [AppName]
,例如sudo killall "Activity Monitor"
。pgrep [AppName]
例如pgrep "Google Chrome"
,您可以使用 标识单个应用程序的 PID ,并且可以使用 终止任何生成的 PID kill [PID]
。
小智 5
聚会有点晚了,但我已经编写了一个终端应用程序,可以为您执行此操作。它绕过了对活动监视器的 UI 脚本编写的需要,而是使用旋转转储报告来确定无响应的进程并为您自动终止它们。
https://github.com/cold-logic/killunresponsive
归档时间: |
|
查看次数: |
4753 次 |
最近记录: |