starting and stopping a program from inside a python script

Discussion in 'Python' started by dfaber, Jul 3, 2006.

  1. dfaber

    dfaber Guest

    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?
    dfaber, Jul 3, 2006
    #1
    1. Advertising

  2. dfaber

    Amit Khemka Guest

    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 <> wrote:
    > 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.
    Amit Khemka, Jul 4, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rhino
    Replies:
    0
    Views:
    1,470
    Rhino
    Nov 15, 2003
  2. Paul Hampton
    Replies:
    0
    Views:
    340
    Paul Hampton
    Jul 3, 2003
  3. -intl.com
    Replies:
    1
    Views:
    359
    Martin Gregorie
    Oct 22, 2006
  4. Replies:
    8
    Views:
    307
    Ian Wilson
    Nov 10, 2006
  5. DevNull
    Replies:
    3
    Views:
    418
Loading...

Share This Page