我知道我可以这样做,ps -aux | xargs kill
但我想列出所有未响应的任务的PID(“活动监视器”中的红色)。我可以在终端中执行什么命令来列出这些红色的,无响应的任务,并自动终止它们。
有人已经在“如何确定应用程序是否没有响应?”中提出了几乎相同的问题。(确定哪些进程不响应是困难的部分,杀死它们很容易)。我在这里引用了一个相关的答案:
“无响应”状态不是进程状态,而是进程已停止与窗口管理器/图形引擎的通信。可以将它绑在一个循环中,挂在套接字,远程文件上,任何使它返回到处理事件的主循环的东西都可以。窗口管理器注意到事件正在排队,因此将其标记为“未响应”
您可能需要编写一个小的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
但是,如果你已经确定要充当了一个应用程序,你可以杀死它的所有实例sudo killall [AppName]
,例如sudo killall "Activity Monitor"
。您可以使用标识单个应用程序的PID pgrep [AppName]
,例如pgrep "Google Chrome"
,也可以使用杀死所有生成的PID kill [PID]
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句