判斷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

相關文章
相關標籤/搜索