2011-04-23 139 views

回答

0

這應該在任何Posix的外殼,包括bash的工作...

#!/bin/sh 
while :; do 
    echo starting command 
    while :; do 
    trap break SIGTERM 
    sleep 5; kill $$ # 5 second timeout 
    sleep 10 # replace this sleep with your real command 
    done 
    echo Command terminated, restarting... 
done 
+0

是不是有一些'&'失蹤並行執行,而不是一個接一個的命令? – 2011-04-23 21:08:21

1

有在我的Ubuntu名爲timeout命令。你可以試試這個:

timeout 1s yes 

這將使得過程是1秒後結束。

注意:使用此命令也可以指定信號作爲參數。

您也可以驗證時間constaint開始使用此命令的尊重:

time timeout 3s yes 
相關問題