469,575 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

starting and stopping a program from inside a python script

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?

Jul 3 '06 #1
1 1479
You can store the pid of the process when started and later use it to kill it.

cheers,

On 3 Jul 2006 15:28:19 -0700, dfaber <de*******@gmail.comwrote:
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?

--
http://mail.python.org/mailman/listinfo/python-list

--
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
Jul 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Paul Hampton | last post: by
6 posts views Thread by David Klaffenbach | last post: by
9 posts views Thread by Peter Wu | last post: by
reply views Thread by Nick Coghlan | last post: by
15 posts views Thread by Nick Coghlan | last post: by
6 posts views Thread by tatamata | last post: by
6 posts views Thread by Andrew Poulos | last post: by
4 posts views Thread by durumdara | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.