Linuxで最初にすべての実行中のジョブを強制終了してから、すべての停止中のジョブを実行中のステータスに変更する方法に興味があります。私はたくさんグーグルしましたが、何も見つかりませんでした。kill $(jobs -ps)
実行中か停止中かにかかわらず、すべてのジョブを強制終了するコマンドに到達しました。これは私のjobs
出力です:
[1] 92231 Running tail -f myfile &
[2] 92232 Stopped tail -f myfile
[3] 92234 Stopped tail -f myfile
[4] 92236 Stopped tail -f myfile
[5] 92237 Running tail -f myfile &
[6] 92238 Stopped tail -f myfile
[7] 92239 Running tail -f myfile &
[8] 92240 Stopped tail -f myfile
[9] 92241 Stopped tail -f myfile
[10] 92243 Stopped tail -f myfile
[11] 92244 Stopped tail -f myfile
[12] 92245 Stopped tail -f myfile
[13] 92246 Stopped tail -f myfile
[14] 92247 Stopped tail -f myfile
[15] 92248 Stopped tail -f myfile
[16] 92249 Stopped tail -f myfile
[17] 92250 Stopped tail -f myfile
[18] 92251 Stopped tail -f myfile
[19] 92252 Stopped tail -f myfile
[20] 92253 Stopped tail -f myfile
[21] 92255 Stopped tail -f myfile
[22] 92256 Stopped tail -f myfile
[23] 92258 Stopped tail -f myfile
[24] 92259 Stopped tail -f myfile
[25] 92260 Stopped tail -f myfile
[26] 92261 Running tail -f myfile &
[27] 92262 Stopped tail -f myfile
[28] 92263 Stopped tail -f myfile
[29] 92264 Stopped tail -f myfile
[30] 92267 Stopped tail -f myfile
[31] 92268 Stopped tail -f myfile
[32] 92269 Stopped tail -f myfile
[33] 92270 Stopped tail -f myfile
[34] 92271 Stopped tail -f myfile
[35]- 92272 Stopped tail -f myfile
[36]+ 92273 Stopped tail -f myfile
最初に、すべての実行中のプロセスを強制終了し、次に、他の停止中のプロセスを実行中にする必要があります。
どうすればこの出力に到達できますか?私はforループについて考えていましたが、できるかどうかはわかりません。
最初にbashマニュアルのいくつかの便利なjobs
オプション:
-pジョブのプロセスグループリーダーのプロセスIDのみを一覧表示します。
-r実行中のジョブのみを表示します。
-s停止したジョブのみを表示します。
したがって、実行中のすべてのジョブを強制終了するには、次のようにします。
kill $(jobs -p -r)
停止したすべてのジョブを再開するには:
kill -SIGCONT $(jobs -p -s)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加