starting and stopping a program from inside a python script

D

dfaber

Aloha!
I want to terminate a process/program from within a python script.

For example,
if I have a program say foo.sh that starts running, then I can run it
from within a python script using
os.popen('foo.sh') which starts a program/process say 'bar'

At some point later, I want to kill 'bar'. Currently, I start off the
process and then when the python script exits, the process 'bar' is
still running and I have to issue ps -ef | grep 'bar' and then kill
it.

Is there any better way of doing this?
 
A

Amit Khemka

You can store the pid of the process when started and later use it to kill it.

cheers,

Aloha!
I want to terminate a process/program from within a python script.

For example,
if I have a program say foo.sh that starts running, then I can run it
from within a python script using
os.popen('foo.sh') which starts a program/process say 'bar'

At some point later, I want to kill 'bar'. Currently, I start off the
process and then when the python script exits, the process 'bar' is
still running and I have to issue ps -ef | grep 'bar' and then kill
it.

Is there any better way of doing this?


--
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top