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

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

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

    >>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.
    >GBSo, is there a way from the Linux shell or a bash script to terminate
    >GBjust one specific Python script ?
    >>So just kill it.
    Yes I've seen that each python script calls its own instance of Python. Buthow 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éezun compte.
  • Piet van Oostrum

    #2
    Re: Terminate a python script from linux shell / bash script

    >>>>Gros Bedo <gros_bedo@hotm ail.com(GB) wrote:
    >GBYes I've seen that each python script calls its own instance of
    >GBPython. But how to know which is the good one in bash ? Is there a
    >GBcommand that gets the parameters of process, so I could use grep to
    >GBselect 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 <piet@cs.uu.n l>
    URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C 4]
    Private email: piet@vanoostrum .org

    Comment

    Working...