偵測背景執行結束 - Linux

Table of Contents

我有個shell script 裡面執行了三個程式在背景執行
.......

program1 &
program2 &
program3 &

.......
想請問板上的各位高手,由於我接下來的動作,需要抓取
此三個程式結束所產生的檔案再進行處理,有沒有什麼方法
可以偵測到這些背景執行的程式已經結束了呢?

麻煩大家給點方法和提示! 謝謝~

--

All Comments

Yuri avatarYuri2012-01-01
man wait? 雖然我也不會,不過看起來是這個
Megan avatarMegan2012-01-03
試試看這樣:
./program1 &
wait $!; ./postporcess
Sarah avatarSarah2012-01-03
由於你一次要等3個process,用C寫一個負責fork/exec/wait的
Isla avatarIsla2012-01-08
小程式是最簡單的. 如果C或這部分的system call不熟,那就
在shell中用ps和grep定期檢查3個child process的pid是否仍
Rosalind avatarRosalind2012-01-11
在,只要任一個在,就sleep然後迴圈再檢查
Agatha avatarAgatha2012-01-14
感謝以上高手們的提示,我去試試看~
Sarah avatarSarah2012-01-18
一次等3個process用xargs會比較好...
Elma avatarElma2012-01-23
echo 'p1\np2\np3'|xargs -d \\n -n 1 -P 3 -i
bash -c {} &