1、今天由于测试需要监控线程是否存在,主要是想看进程什么时候停止

shell脚本:

#!/bin/bash
filename=`date '+%Y-%m-%d'`
file=./thread_is_exist${filename}.csv
while true
do
cur_dateTime="`date +%Y-%m-%d,%H:%M:%S`";
# wc -l 返回进程格式个数
count=`ps -ef |grep /usr/lib/nds.jar|grep -v "grep" | wc -l`;
if [ 0 == $count ];then
  echo $cur_dateTime + 'mamagenment is not exist' >>${file}
else
  echo $cur_dateTime + 'management is exist'>>${file}
fi;
sleep 60
done

2、后台运行:

nohup ./test.sh &


3、停止后台运行

查看目前正在执行的进程,然后杀掉进程即可

ps aux|grep test.sh
kill -9 2573(进程pid)

标签: shell, 进程, 后台, grep, file, 监控, cur, exist

相关文章推荐

添加新评论,含*的栏目为必填