By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 2,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

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

P: n/a
>>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
Share this Question
Share on Google+
1 Reply


P: n/a
>>>>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.