设为首页 加入收藏

TOP

Linux限制Shell执行时间
2014-11-24 07:23:51 来源: 作者: 【 】 浏览:1
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编程基础

评论

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

·Java 学习线路图是怎 (2025-12-25 15:19:15)
·关于 Java 学习,有 (2025-12-25 15:19:12)
·有没有Java swing教 (2025-12-25 15:19:09)
·Start, Stop, and Di (2025-12-25 14:50:57)
·C语言入门教程:零基 (2025-12-25 14:50:54)