アプリケーションが応答していないかどうかを確認するにはどうすればよいですか?


11

OSXで繰り返し応答なしの状態になり、強制終了する必要があるアプリケーションがあります。私はそれを自動化したいと思っていましたが、psでプロセスを検査したときに、Not Responding状態に対応するものは何もありません。私が見た状態インジケータが、などのアプリショーSが応答されているかどうか。

状態状態は、「RWNA」などの一連の文字で指定されます。最初の文字は、プロセスの実行状態を示します。

  • アイドル状態のプロセス(約20秒以上スリープ状態)にマークを付けます。
  • R実行可能なプロセスをマークします。
  • S約20秒未満スリープしているプロセスをマークします。
  • T停止したプロセスをマークします。
  • U無停止待機中のプロセスをマークします。
  • Zは、死んだプロセス(「ゾンビ」)をマークします。

アクティビティマネージャーのようにプロセスが応答していないかどうかを確認するにはどうすればよいですか?


私もAppleScriptソリューションを利用できます。

回答:


9

Not Responding状態はプロセスの状態ではなく、プロセスがウィンドウマネージャ/グラフィカルエンジンとの通信を停止しました。ループ、ソケット、リモートファイルなど、イベントを処理するメインループに戻るループに拘束される可能性があります。ウィンドウマネージャーは、イベントがキューに入れられていることに気づき、「応答なし」というラベルを付けます

ダミーのイベントをプロセスに送信する小さなX11プログラムを作成し、応答しない場合は終了する必要がある場合があります。


たぶん、UIレベルのアクセスとしてAppleScriptで何かを書くことでしょう。
Matthieu Riegler、

@MatthieuRiegler AppleScriptでそれをどのように行いますか?
C.ロス

他の回答に例を示しました。
Matthieu Riegler

4

以下は、UIスクリプトを使用したAppleScriptで、応答しないプロセスを探して強制終了します。

MavericksのActivity Monitorで動作します。ただし、これはUIスクリプトであり、Activity MonitorのUIが変更されたため、多少の変更を加えないと、古いOS Xでは機能しない可能性が高くなります。

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

その行でコンパイルエラーが発生しtell radio button 1 of radioます。私はそれを削除し、他のいくつかのもの(私は特定のプログラムを強制終了したいだけです)を調整し、実行時エラーを取得しました: 'エラー「システムイベントがエラーを取得しました:補助デバイスへのアクセスが無効になっています。」プロセス "アクティビティモニター"のウィンドウ1からの番号-1719
C.ロス

OSX Mavericksでそのスクリプトを実行しましたか?
Matthieu Riegler、

OSX 10.8、そうではありません。
C.ロス

変更後10.12.5で作業tell radio button 1 of radio group 1 of group 2 of toolbar 1 of window 1 to click
Charlie Gorichanaz '11

0

(コメントに収めるには長すぎるため、これを個別の回答として投稿してください)

元のスクリプトの@MatthieuRieglerへのクレジット。

これは10.12.6で機能し、元のスクリプトを少し変更したものです(私が自分で調査した後に@CharlieGorichanazのコメントを見ました)。


set textToSearchForInProcessName to "Not Responding"

--  Run Activity Monitor 
tell application "Activity Monitor" to activate

tell application "System Events" to tell process "Activity Monitor"
    --  Wait for the Activity Monitor window to open
    repeat until (exists window 1)
        delay 1
    end repeat
    --display notification "Window appeared"

    --  Wait for the Menubar to be present
    repeat until (exists menu 1 of menu bar item "View" of menu bar 1)
        delay 1
    end repeat
    --display notification "Menubar appeared"

    --  Make sure View -> My Processes is selected 
    click menu item "My Processes" of menu 1 of menu bar item "View" of menu bar 1

    --  Click the 'CPU View' button  ( **1 ) 
    click radio button 1 of radio group 1 ¬
        of group 2 of toolbar 1 ¬
        of window 1

    --  Working with the list of processes 
    tell outline 1 of scroll area 1 of window 1
        --  Looking for Not responding process  
        set notResponding to rows whose value of ¬
            first static text contains textToSearchForInProcessName

        repeat with aProcess in notResponding

            --  For each non responding process retrieve the PID 
            set pid to value of text field 1 of aProcess -- ( **2 )

            --  Kill that process using pid 
            if pid is not "" then do shell script ("kill -9 " & pid)
        end repeat
    end tell
end tell

** 1 macOS 10.12.xでは、ここに画像の説明を入力してくださいボタンのセット(CPU、メモリ、エネルギーなど)のgroup 2 of toolbar 1代わりにツールバーに追加のアイコンが含まれています group 1 of toolbar 1。そのアイコンがない場合(私は古いmacOSバージョンでは確認していません)、CPUなどのボタンがgroup 1 of toolbar 1

** 2 これは、アクティビティ列のPID列を別の位置にドラッグしたことがある場合に適用されます。PID列を左端の位置にドラッグしたので、この行で、インデックスを1次のように変更する必要がありました。

set pid to value of text field 1 of aProcess

列には、1から始まる左端から番号が付けられています。したがって、必要に応じて、上記の行で強調表示されているインデックスを適宜調整してください。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.