I am trying to check if the process is running based on process name (test.py) , then exit
l = commands.getstatusoutput("ps aux |grep 'python2.7'| grep      
'test.py' | grep -v 'grep' | wc -l")
if int(l[1]) == 1:
    pid = commands.getstatusoutput("ps -ef |grep 'python2.7'|  grep 'test.py ' |awk '{print $2}'")
    print "the process 'test.py ' have running ,the pid is :"+str(pid[1])
    sys.exit(0)
else:
   print "not running"
Output:
georgetovrea@dev:/test$ python2.7  test.py 
the process 'test.py ' have running ,the pid is :26517
26542
then I try to check
 $ ps aux | grep agg_test
 georgetovrea 25181  0.0  0.0  10944   932 pts/9    S+   23:26   0:00 grep --color=auto test
the process is not running, I want to check if the process( test.py) have running ,then exit , but it's always print the process is running ,
How do I check the process have running ? Any suggestions? Thanks for any help.
 
    