how to kill a subprocess

C

cerr

Hi There,

I'm calling a python script from a php script which again calls a perl
script with subprocess.popen().
This seems to work fine so far only that once the python script
completed it is becoming a zombie because the perl script in the
background is still running... so before i exit the python script, i
would need to kill my perl subprocess.
How can i do so?
Thank you for hints & suggestions!
Ron
 
A

Alain Ketterlin

cerr said:
I'm calling a python script from a php script which again calls a perl
script with subprocess.popen().
This seems to work fine so far only that once the python script
completed it is becoming a zombie because the perl script in the
background is still running... so before i exit the python script, i
would need to kill my perl subprocess.
How can i do so?

x.terminate() (and then x.wait()) where x is the value returned by
subprocess.Popen().

-- Alain.

P/S: I'm not sure why the python process survives, and I think your use
of "zombie" is not correct (afaik a zombie is an exited process whose
parent hasn't called wait() yet)
 
C

cerr

x.terminate() (and then x.wait()) where x is the value returned by
subprocess.Popen().
Well, this is what I have:

writelog("starting GPS simulator")
commandlist=[GPSsim,proto,GPSfile]
writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2])
process=subprocess.Popen(commandlist)
writelog("GPS simulator started")
...
...
os.kill(process.pid,9)
os.wait()

but this is not working for me... :( any clues?
P/S: I'm not sure why the python process survives, and I think your use
of "zombie" is not correct (afaik a zombie is an exited process whose
parent hasn't called wait() yet)

This is what I have:

localhost cgi-bin # ps ax | grep py
11853 ? Z 0:00 [python2.6] <defunct>
12029 pts/1 S+ 0:00 grep --colour=auto py

The 'Z' you see there stands for Zombie
 
M

MRAB

x.terminate() (and then x.wait()) where x is the value returned by
subprocess.Popen().
Well, this is what I have:

writelog("starting GPS simulator")
commandlist=[GPSsim,proto,GPSfile]
writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2])
process=subprocess.Popen(commandlist)
writelog("GPS simulator started")
...
...
os.kill(process.pid,9)
os.wait()

but this is not working for me... :( any clues?
P/S: I'm not sure why the python process survives, and I think your use
of "zombie" is not correct (afaik a zombie is an exited process whose
parent hasn't called wait() yet)

This is what I have:

localhost cgi-bin # ps ax | grep py
11853 ? Z 0:00 [python2.6]<defunct>
12029 pts/1 S+ 0:00 grep --colour=auto py

The 'Z' you see there stands for Zombie
How about:

process.kill() # New in Python 2.6

or:

os.kill(process.pid, 9)

then:

process.wait()

or:

os.waitpid(process.pid, 0)
 
C

cerr

Well, this is what I have:
   writelog("starting GPS simulator")
   commandlist=[GPSsim,proto,GPSfile]
   writelog(commandlist[0]+" "+commandlist[1]+" "+commandlist[2])
   process=subprocess.Popen(commandlist)
   writelog("GPS simulator started")
   ...
   ...
   os.kill(process.pid,9)
   os.wait()
but this is not working for me... :( any clues?
This is what I have:
localhost cgi-bin # ps ax | grep py
11853 ?        Z      0:00 [python2.6]<defunct>
12029 pts/1    S+     0:00 grep --colour=auto py
The 'Z' you see there stands for Zombie

How about:

     process.kill() # New in Python 2.6

or:

     os.kill(process.pid, 9)

then:

     process.wait()

or:

     os.waitpid(process.pid, 0)

HI MRAB,

Thanks for your suggestion, changed my code now to:

process=subprocess.Popen(commandlist)
...
...
process.kill()
os.waitpid(process.pid, 0)
but it's not killing the process running. it still runs in the
background and i don't see any errors, we're running python 2.6.4
any more clues?

Thanks,
Ron
 
C

cerr

Am 10.09.2010 20:56, schrieb cerr:



You have said that the Python process becomes a zombie process. This
clearly tells me that the issue is in your PHP script. Seehttp://en.wikipedia.org/wiki/Fork-exec

No, the Perl becomes the zombie.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top