よくcronで数秒ごとに処理したい場合に使用する。非同期での実行になる。
for i in `seq 0 5 59`; do ( sleep $i echo "$i Running" ) & done;
こちらもcronで多用する。実行時のコマンドライン引数も含めたプロセスを確認して、実行中のプロセスがなければ新しいプロセスを起動するような場合に使用する。
#!/bin/bash sec="123" test=$(ps xa 2>/dev/null | grep $sec 2>/dev/null) if [[ ! $test = *"top -d $sec"* ]]; then top -d $sec fi