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

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top