判断进程是否存在的shell代码
时间:2014-06-23 03:15 来源:linux.it.net.cn 作者:IT网
判断进程是否存在,使用命令ps、grep、sed、awk。
代码chk_ps.sh:
代码如下:
#!/bin/bash
pid=`ps aux|grep -v grep|grep -v "test.sh"|grep $1|sed -n '1P' | awk '{print $2}'`
if [ -z $pid ];then
echo "there isn't this process!"
else
echo $pid
fi
(责任编辑:IT)
判断进程是否存在,使用命令ps、grep、sed、awk。 代码chk_ps.sh: 代码如下: #!/bin/bash pid=`ps aux|grep -v grep|grep -v "test.sh"|grep $1|sed -n '1P' | awk '{print $2}'` if [ -z $pid ];then echo "there isn't this process!" else echo $pid fi (责任编辑:IT) |