473,771 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2997
>>>>Gros Bedo <gr*******@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 <pi**@cs.uu.n l>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C 4]
Private email: pi**@vanoostrum .org
Jul 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3849
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or less - during my own installation of Python 2.3 on Fedora Core 1 Linux for a friend of mine). Anyway, HTH, L.
9
2079
by: TPJ | last post by:
First I have to admit that my English isn't good enough. I'm still studying and sometimes I just can't express what I want to express. A few weeks ago I've written 'Python Builder' - a bash script that allows anyone to download, compile (with flags given by user) and install Python and some external modules (e.g. wxPython, PyGTK, Numeric...). I use Python every day and when new version of Python (or some external module) is released, I...
8
2029
by: Jan Danielsson | last post by:
Hello all, How do I make a python script actually a _python_ in unix:ish environments? I know about adding: #!/bin/sh ..as the first row in a shell script, but when I installed python on a NetBSD system, I didn't get a "python" executable; only a "python2.4"
7
2243
by: Frank Potter | last post by:
I learned some python in windows. And now I've turned to linux. I read a book and it teaches how to write shell script with bash, but I don't feel like the grammar of bash. Since I know about python, I want to get a linux shell which use python grammar. I searched by google and I found pysh, which is not maintained any more. There's another script named pyshell, which is not likely what I'm searching for.
3
3862
by: Gros Bedo | last post by:
Hello :-) I have a question about Python and Linux shell. I have a python program which is permanently resident in the end-user system. I'm currently producing a RPM package, and it works nicely. The problem is that when I uninstall it, my program keeps running in the background, even if the files are deleted. I know I can terminate python shell directly, but this is not a good ideabecause the end-user may be working with another important...
0
2025
by: norseman | last post by:
Gros Bedo wrote: ============================== Yes. man ps explains try ps -AFL | grep then kill -9 found (check it more than twice) 1) If your script is known to hang use what another wrote: py s.py tokens & capture=$! (get the PID ready)
0
164
by: Gros Bedo | last post by:
Thank you guys for your help. My problem is that I project to use this command to terminate a script when uninstalling the software, so I can't store the PID. This command will be integrated in the spec file of the RPM package. Here's the script I'll use, it may help someone else: #!/bin/sh # PYTHON SCRIPT PROCESS KILLER by GBO v0.1 # This script will look for all the lines containing $SOFTWARENAME in the process list, and close them ...
5
1438
by: aha | last post by:
Hello All, I have a situation where I can count on a Python installation being available on a system, but I can't count on it being a version of Python needed by my application. Since my application has it's own version of Python installed with it how should I use the system Python to launch the version of Python that launches my Application. Yes, this is a convoluted process, but not all Pythons are built the same :) Right now I am...
4
7562
by: Stephen Cattaneo | last post by:
Hello all, I am attempting to execute an automated test (written in Python) via cron. I have to check the HOSTNAME variable as part of the test, oddly under cron the HOSTNAME environment variable is not in the os.environ dictionary. I know that cron runs in a subshell that does not have all of the normally set environment variables. HOSTNAME is not one of those variables, it is set even in cron's subshell. Why doesn't python get...
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.