Monitor a process, if have run for more than 2 mins,kill it. 博客分类: Shell
程序员文章站
2024-03-13 08:59:57
...
#!/bin/bash -l process_name='phantomjs' long_term=1 pids=` ps -ef | grep -i "$process_name" | grep -v 'grep' | awk '{print $2;}'` if [ "$pids" == "" ]; then echo "no phantomjs running" >/dev/null exit 0 fi for pid in $pids; do echo $pid etimes_min=` ps -p $pid -o etime=|awk -F":" '{print($(NF-1))}'` etimes_min=`echo $etimes_min | sed 's/^0//'` echo $etimes_min,$long_term if [ "$etimes_min" -gt "$long_term" ]; then kill -9 $pid >/dev/null timestamp=`date '+%Y%m%d %H:%M'` echo "$timestamp: killed $pid for $process_name, for it took more than 2 minus" >> "kill-long-term-phantomjs-processes.log" fi done
上一篇: Java中八种基本数据类型的默认值
下一篇: 手动解除k8s对ceph rbd的挂载