shell控制超时时间,自动退出
Bash
timeout()
{
waitfor=3
command=$*
$command &
commandpid=$!
( sleep $waitfor ; kill -9 $commandpid >/dev/null2>&1)&
watchdog=$!
sleeppid=$PPID
wait $commandpid >/dev/null2>&1
kill $sleeppid >/dev/null2>&1
}