468,719 Members | 1,810 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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.
http://www.windowslive.fr/hotmail/default.asp
Jul 10 '08 #1
1 2658
>>>>Gros Bedo <gr*******@hotmail.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 <pi**@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Jul 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Logan | last post: by
8 posts views Thread by Jan Danielsson | last post: by
7 posts views Thread by Frank Potter | last post: by
5 posts views Thread by aha | last post: by
4 posts views Thread by Stephen Cattaneo | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.