- 论坛徽章:
- 0
|
好像要求但如果我top(自己的程序)要能结束并返回继续执行while循环
如果不能返回(如果只用top -b,不加参数);整个脚本就会不会停止
这段有点不知所云的
我想了下似乎应该是采用一种信号机制,
自己去fork exec, 设置个定时器,
到时后kill 要执行的程序
看下面的脚本能否满足你的要求,也是一个外部脚本无限循环,检查当前的 vi 进程运行是否超过 100 秒,是则 kill 掉,同时打印提示信息
- [n7css@monitor n7css]$ cat hard_limit.sh |grep -v '^$'
- #!/bin/bash
- while true ; do
- pid=$(pgrep -u n7css vi)
- for i in $pid ;do
- start_time=$(ps -o start_time $i |tail -n 1 |xargs -i date -d {} +%s)
- cur_time=$(date +%s)
- if [ $(( cur_time - start_time )) -ge 100 ] ;then
- echo "found [vi] process [ $i ] started at " $(date -d "1970-01-01 $start_time sec utc") ",kill it"
- /bin/kill $i
- sleep 5
- if ps $i >/dev/null ;then
- /bin/kill -9 $i
- fi
- fi
- done
- done
- [n7css@monitor n7css]$
复制代码
[ 本帖最后由 ailms 于 2007-7-30 23:16 编辑 ] |
|