bash:偵測程式pid消失後自動執行
測試小程式 當aplay pid消失後,程式會偵測到pid消失 然後再執行 pidof可以偵測程式的pid 無限while loop也可以這麼寫 #!/bin/sh aplay -D plughw:1 /mnt/shield/song.wav -v & arecord -D plughw:1 -r 48000 -c 2 -f s16_le /mnt/shield/test.wav & while : do pid1=$(pidof aplay) pid2=$(pidof arecord) echo aplay=$pid1 arecord=$pid2 if [ -z $pid1 ]; then kill -9 $pid2 rm -fr /mnt/shield/test.wav aplay -D plughw:1 /mnt/shield/song.wav -v & arecord -D plughw:1 -r 48000 -c 2 -f s16_le /mnt/shield/test.wav & else sleep 1 fi done