Kill python process with pkill python

2019-09-08 14:36发布

问题:

i want to stop python process in a script, but in the first time i don't have any process running but i should pass with my function restart :

function restart() {
   stop
   start
}
function start (){
exec ./server --db_host=.......
} 
function stop (){
pkill python
}

the problem is when i execute restart its blocked, so can you suggest me how to have a control like this

if [i have python process runing];then pkill python

thanks

回答1:

This should do the trick

if [ `ps -e | grep python | wc -l` -gt 1 ]
then
    pkill python
if