I have a python script 'b.py' which prints out time ever 5 sec.
while (1):print "Start : %s" % time.ctime()time.sleep( 5 )print "End : %s" % time.ctime()time.sleep( 5 )
And in my a.py, I call b.py by:
def run_b():print "Calling run b"try:cmd = ["./b.py"]p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)for line in iter(p.stdout.readline, b''):print (">>>" + line.rstrip())except OSError as e:print >>sys.stderr, "fcs Execution failed:", e return None
and later on, I kill 'b.py' by:PS_PATH = "/usr/bin/ps -efW"
def kill_b(program):try:cmd = shlex.split(PS_PATH)retval = subprocess.check_output(cmd).rstrip()for line in retval.splitlines():if program in line:print "line =" + linepid = line.split(None)[1]os.kill(int(pid), signal.SIGKILL)except OSError as e:print >>sys.stderr, "kill_all Execution failed:", eexcept subprocess.CalledProcessError as e:print >>sys.stderr, "kill_all Execution failed:", erun_b()
time.sleep(600)
kill_b("b.py")
I have 2 questions. 1. why I don't see any prints out from 'b.py' and when I do 'ps -efW' I don't see a process named 'b.py'? 2. Why when I kill a process like above, I see 'permission declined'?
I am running above script on cygwin under windows.
Thank you.