starting and stopping a program from inside a python script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dfaber

    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.s h') 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?

  • Amit Khemka

    #2
    Re: starting and stopping a program from inside a python script

    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 <deusfaber@gmai l.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.s h') 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?
    >
    --

    >

    --
    ----
    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.

    Comment

    Working...