2017-06-23 1 views
1

pk emacsなどのプログラムを強制終了するシェルスクリプトにpkという対話型関数を定義しましたが、複数のインスタンスが実行されている場合は、すべてを殺すか殺すためにピッド。Linuxの端末でGUIアプリケーションのウィンドウタイトルを表示するには

私の会社では私のCentOSのは古いですが、私のスクリプト機能pkに、私はコマンドとそのPIDをフィルタリングするpsを使用して、私の知る限りpsが、この場合には何のウィンドウタイトルを伝えていないので、私のEmacsの一つがフリーズする場合これは、時折起こります1つ以上の "/ usr/bin/emacs"を印刷するだけです。詳細はなく、私はkillする予定のPIDが凍っているかどうかわかりません。

「ウィンドウ - 私は、ウィンドウのタイトルをチェックして、プログラムを殺すためにSystem Activity(KDE)のようなシステムツールを使用することができます知っているが、私はpk機能を使用して、端末にプログラムを殺したい、そうpsのような任意のツールがあるけど示しますtitle + command + pid "ので、スクリプトでそのプログラムを強制終了することができます。

ターミナルからvimまたはemacsを使ってファイルを開くと、オプション付きのpsがファイルを表示するので、私はそのPIDの詳細を知っているので、どちらを殺すか知っているので、ここではウィンドウのタイトルはウィンドウタイトルのようにSystem Activity

もちろん、私が言ったように同じプログラムの複数のインスタンスのいずれかを殺す方法を誰かが知っていれば、Widowのタイトルが間違っている場合は、歓迎されます。

答えて

1

私はちょうど私が次の行で、凍結のemacsを殺すために私pk機能で使用できる別の解決策を見つけた:

kill -SIGUSR2 (xprop | grep -i pid | grep -Po "[0-9]+") 

あなたのマウスを使用したGUIプログラムをクリックしたとき(xprop...)部分はPIDを返します。 。

誰もが私のpk機能に興味がある場合は、ここではそれは(私は魚シェルを使用していますNOTEので、これは魚のスクリプト関数である)である:

function pk --description 'kill processes containg a pattern' 
    set done 1 
    set result (psg $argv[1] | wc -l) 
    if test $result = 0 
     echo "No '$argv[1]' process is running!" 
    else if test $result = 1 
     psg $argv[1] | awk '{print $2}' | xargs kill -9 
     if test $status = 123 # Operation not permitted 
      read -p 'echo "Use sudo to kill it? [y/N]: "' -l arg 
      if test "$arg" = "y" 
       psg $argv[1] | awk '{print $2}' | xargs sudo kill -9 
      end 
     end 
    else 
     psg $argv[1] 
     while test $done = 1 
      read -p 'echo "Kill all of them or specific PID? [y/N/pid]: "' -l arg 
      if test "$arg" = "y" 
       psg $argv[1] | awk '{print $2}' | xargs kill -9 
       if test $status -eq 123 # Operation not permitted 
        read -p 'echo "Use sudo to kill them all? [y/N]: "' -l arg2 
        if test "$arg2" = "y" 
         psg $argv[1] | awk '{print $2}' | xargs sudo kill -9 
        end 
       end 
       set done 0 
      else if test $arg -a "$arg" != "y" -a "$arg" != "n" 
       # the fist cond in test means you typed something, RET will not pass 
       if test (psg $argv[1] | awk '{print $2}' | grep -i $arg) 
        kill -9 $arg #2>/dev/null 
        if test $status -eq 1 # kill failed 
         read -p 'echo "Use sudo to kill it? [y/N]: "' -l arg2 
         if test "$arg2" = "y" 
          sudo kill -9 $arg 
         end 
        end 
        echo -e "Continue...\n" 
        usleep 100000 
        psg $argv[1] 
       else if test "$arg" = "p" 
        # This may be used for frozen emacs specifically, -usr2 or -SIGUSR2 
        # will turn on `toggle-debug-on-quit`, turn it off once emacs is alive again 
        # Test on next frozen Emacs 
        kill -SIGUSR2 (xprop | grep -i pid | grep -Po "[0-9]+") 
        # kill -usr2 (xprop | grep -i pid | grep -Po "[0-9]+") 
        return 
       else 
        echo "PID '$arg[1]' is not in the list!" 
        echo 
       end 
       set done 1 
      else 
       # RET goes here, means `quit` like C-c 
       set done 0 
      end 
     end 
    end 
end 
関連する問題