#timeout在后台执行接受的命令,并设定超时时间,超时后会把命令干掉
timeout(){
waitfor=$1
shift
command=$*
$command &
commandpid=$!
(sleep $waitfor;kill -9 $commandpid >/dev/null 2>&1)&
watchdogpid=$!
sleeppid=$(ps --ppid $watchdogpid |awk '{print $1}')
wait $commandpid
kill $sleeppid>/dev/null 2>&1
}
转载于:https://blog.51cto.com/darksun/963696