判断LINUX进程是否存在

###################################################bash

#!/bin/bashspa

#判断进程是否存在,若是不存在就启动它进程

PIDS=`ps -ef |grep myprocess |grep -v grep | awk '{print $2}'`awk

if [ "$PIDS" != "" ]; thengrep

echo "myprocess is runing!"process

elsesudo

cd /root/ps

./myprocess

#运行进程

fi

###################################################

#!/bin/bash

#判断进程是否存在,若是不存在就启动它若是存在就重启它

PIDS=`ps -ef |grep myprocess |grep -v grep | awk '{print $2}'`

if [ "$PIDS" != "" ]; then

kill -9 $PIDS

#先关闭进程,在运行此进程

cd /root/myprocess

sudo ./myprocess

#从新运行进程

else

cd /root/myprocess

sudo ./myprocess

#运行进程

fi