RE: Terminate a python script from linux shell / bash script

Discussion in 'Python' started by Gros Bedo, Jul 10, 2008.

  1. Gros Bedo

    Gros Bedo Guest


    >>That's not how it works. If you kill one running python script it will not
    >>effect other python scripts. Each script has its own interpreter process
    >>running.


    >GB> So, is there a way from the Linux shell or a bash script to terminate
    >GB> just one specific Python script ?


    >>So just kill it.


    Yes I've seen that each python script calls its own instance of Python. But how to know which is the good one in bash ? Is there a command that gets the parameters of process, so I could use grep to select the one containing the name of my script ?
    _________________________________________________________________
    Votre contact a choisi Hotmail, l'e-mail nouvelle génération. Créez un compte.
    http://www.windowslive.fr/hotmail/default.asp
     
    Gros Bedo, Jul 10, 2008
    #1
    1. Advertising

  2. >>>>> Gros Bedo <> (GB) wrote:

    >GB> Yes I've seen that each python script calls its own instance of
    >GB> Python. But how to know which is the good one in bash ? Is there a
    >GB> command that gets the parameters of process, so I could use grep to
    >GB> select the one containing the name of my script ?


    The ps command will usually give you a list of the running processes with
    their argument, but using that is suboptimal.

    I suppose you start the process in the background, like: python myscript &.
    When you start the python script in bash (or any other process for that
    matter) in the background you can get the process id (pid) with $!
    (immediately after starting the process). Later on you can use this to kill
    the process:

    python myscript myargs &
    savepid=$!


    later: kill $savepid

    That is much better than trying to grep through the ps output.
    --
    Piet van Oostrum <>
    URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
    Private email:
     
    Piet van Oostrum, Jul 10, 2008
    #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. William Park

    (patch for Bash) GTK+2 + Bash

    William Park, Jul 11, 2005, in forum: XML
    Replies:
    3
    Views:
    2,331
    William Park
    Jul 14, 2005
  2. Gros Bedo
    Replies:
    2
    Views:
    1,370
    Piet van Oostrum
    Jul 10, 2008
  3. norseman
    Replies:
    0
    Views:
    588
    norseman
    Jul 10, 2008
  4. Gros Bedo
    Replies:
    0
    Views:
    446
    Gros Bedo
    Jul 13, 2008
  5. edwithad

    Bash shell to Python shell?

    edwithad, Sep 28, 2009, in forum: Python
    Replies:
    4
    Views:
    1,810
Loading...

Share This Page