0

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

My name is
  • 47
  • 1
  • 1
  • 7
  • It's not clear why you want to do the `if` check? pkill won't write anything to stderr if there are no python process, so `restart` or the other two commands will execute without any issues. Unless you want to check for stopped processes or something weird, in which case you will need to read /proc/pid/state or something similar. – Reinstate Monica Please Dec 17 '13 at 11:01

1 Answers1

0

This should do the trick

if [ `ps -e | grep python | wc -l` -gt 1 ]
then
    pkill python
if
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241