设为首页 加入收藏

TOP

Linux限制Shell执行时间
2014-11-24 07:23:51 来源: 作者: 【 】 浏览:0
Tags:Linux 限制 Shell 执行 时间

在Linux定时任务里面,有些任务执行很频繁,必须限制在多长时间内执行完毕,否则统计结果也没有意义,可以直接将其杀死。



timeout(){
waitfor=$1
shift
command=$*
$command &
commandpid=$!


(sleep $waitfor;kill -9 $commandpid >/dev/null 2>&1) &


watchdogpid=$!
wait $commandpid >/dev/null 2>&1
kill $watchdogpid >/dev/null 2>&1
}


———这里限制myshell.sh 执行10秒 通过函数 timeout执行myshell.sh即可
timeout 10 /home/hooh/test/myshell.sh >> /home/hooh/test/log.log


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇高效的Linux日志文件传输:rsync 下一篇Linux Bash编程基础

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·python数据分析岗的 (2025-12-25 10:02:21)
·python做数据分析需 (2025-12-25 10:02:19)
·成为一个优秀的pytho (2025-12-25 10:02:16)
·Java后端面试实习自 (2025-12-25 09:24:21)
·Java LTS版本有哪些 (2025-12-25 09:24:18)