- 论坛徽章:
- 0
|
花了些时间,如果还行或不行的话,告诉我,谢
- #!/bin/bash
- # killptime.sh
- # Wed 17 Dec 2008 01:41:38 PM h
- declare -a arr
- if [ $# -lt 2 ]
- then
- echo "Usage: $0 name running_time escape_pid"#英文不好
- echo " name: the name of processes you want to kill" #进程名
- echo " running_time: run more than this will be killed,use seconds as unit" #运行时间
- echo " escape_pid: the pid of which you do not want to kill"#不想杀的进程
- echo " all will be killed ,if no special"#不指定,全杀
- exit 1
- fi
- while true
- do
- arr=( $(ps h -C "$1" -o pid,start,comm) )
- i=0
- while [[ ${arr[$i]} != "" ]]
- do
- t_time=$((`date +%s`-`date -d"${arr[$i+1]}" +%s`))
- echo $t_time
- if [[ $t_time -gt $2 && x$3 != x${arr[$i]} ]]
- then
- kill -9 ${arr[$i]}
- fi
- # echo ${arr[$i]}
- # echo ${arr[$i+1]}
- # echo ${arr[$i+2]}
- ((i += 3))
- done
- sleep 5 #这个值是不是也由参数指定好些?
- done
复制代码 |
|