Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2 つのプロセスを起動し、最初のプロセスが完了したときに 2 番目のプロセスを強制終了する bash スクリプトを作成したいと考えています。次に例を示します。
#fork 最初のプロセス プロデューサー& #fork 2 番目のプロセス 消費者& #プロデューサーが終了するのを待つ ... #消費者を殺す ...
これは醜くなる可能性があると感じていますが、非常に簡単な解決策があります。空欄を埋めるのを手伝ってください。
foo & pid_foo=$! bar & pid_bar=$! wait $pid_foo kill $pid_bar
しかし、おそらく実行することもできますfoo | bar(それが stdin/stdout 処理で機能する場合)。
foo | bar
#!/bin/bash #enable job control in script set -m producer & consumer & fg %1 kill %2