473,721 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help to kill a process

Hi

Am new to python and need your help!!

this is my code snip.
within my python script I have the following commands..

<snip>

import os
....
os.system ("cd /home; ./TestTool &")
os.system ("cd /usr/; sh run.sh load.xml &")

<snip>

I need to kill these 2 process after a particular job is done.. is
there any way to get the pids of these process and if so how do i
invoke the kill command through os.system..

or else is there anyother way to do this...

thanks

Feb 7 '07 #1
3 6496
En Tue, 06 Feb 2007 22:59:40 -0300, <el*********@gm ail.comescribió :
this is my code snip.
within my python script I have the following commands..

<snip>

import os
...
os.system ("cd /home; ./TestTool &")
os.system ("cd /usr/; sh run.sh load.xml &")

<snip>

I need to kill these 2 process after a particular job is done.. is
there any way to get the pids of these process and if so how do i
invoke the kill command through os.system..

or else is there anyother way to do this...
If you're using Python>=2.4 you could use the subprocess module.

import subprocess
child1 = subprocess.Pope n(["./TestTool"], cwd="/home")
child2 = subprocess.Pope n(["sh","run.sh"," load.xml"], cwd="/usr")

Popen objects have a pid attribute. You don't have to use os.system to
kill them; use os.kill instead.
You'll notice that I leave out the final &, because I don't know how to
start a background process without using the shell. But I think you can
use: bg [pid], afterwards, to get the same result.

--
Gabriel Genellina

Feb 7 '07 #2
On Feb 6, 8:24 pm, "Gabriel Genellina" <gagsl...@yahoo .com.arwrote:
En Tue, 06 Feb 2007 22:59:40 -0300, <elrondru...@gm ail.comescribió :


this is my code snip.
within my python script I have the following commands..
<snip>
import os
...
os.system ("cd /home; ./TestTool &")
os.system ("cd /usr/; sh run.sh load.xml &")
<snip>
I need to kill these 2 process after a particular job is done.. is
there any way to get the pids of these process and if so how do i
invoke the kill command through os.system..
or else is there anyother way to do this...

If you're using Python>=2.4 you could use the subprocess module.

import subprocess
child1 = subprocess.Pope n(["./TestTool"], cwd="/home")
child2 = subprocess.Pope n(["sh","run.sh"," load.xml"], cwd="/usr")

Popen objects have a pid attribute. You don't have to use os.system to
kill them; use os.kill instead.
You'll notice that I leave out the final &, because I don't know how to
start a background process without using the shell. But I think you can
use: bg [pid], afterwards, to get the same result.

--
Gabriel Genellina- Hide quoted text -

- Show quoted text -
thx for the reply
os.kill worked fine for the first process.. for the second one the
kill managed to kill the shell but the application is still running..

is there any other work around for this..

thanks

Feb 7 '07 #3
En Wed, 07 Feb 2007 16:50:55 -0300, <el*********@gm ail.comescribió :
>import subprocess
child1 = subprocess.Pope n(["./TestTool"], cwd="/home")
child2 = subprocess.Pope n(["sh","run.sh"," load.xml"], cwd="/usr")

Popen objects have a pid attribute. You don't have to use os.system to
kill them; use os.kill instead.
You'll notice that I leave out the final &, because I don't know how to
start a background process without using the shell. But I think you can
use: bg [pid], afterwards, to get the same result.

thx for the reply
os.kill worked fine for the first process.. for the second one the
kill managed to kill the shell but the application is still running..
Don't use the shell, if possible, and replace whatever run.sh does with
python code.

--
Gabriel Genellina

Feb 8 '07 #4

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

Similar topics

6
7048
by: Bob Swerdlow | last post by:
My application starts up a number of processes for various purposes using: self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py") and then shuts them down when appropriate with os.kill(self.popen.pid, signal.SIGTERM) Everything works fine on MacOSX. However, I'm doing a port to Solaris (so I can run it on my web site) and find that the child processes are not stopping! Solaris is creating TWO new processes: one for the SHELL...
10
9777
by: Fred | last post by:
There is a setting in INIT.ORA that has the unintended side-effect of making sure the ALTER SYSTEM KILL SESSION command has immediate affect. Without this setting, I've seen some instances where the session reports as being KILLED in V$SESSION but is not physically removed until the instance is bounced. Does anyone remember this value offhand?
10
6176
by: Jako Menkveld | last post by:
I'm building a relatively simple client-server app. One of the functions of the client is to notify the server when it terminates, this all works fine. The problem comes in when the server is stopped before the client, in which case the client "hangs", waiting to talk to the server. This is how it works: Server: Starts listening on a tcp port, say 3000 (by registering a TcpServerChannel and invoking RegisterWellKnownServiceType). When...
3
6386
by: pattanawadee | last post by:
Deall All, Could anybody suggestion me How to kill all inherrit processes (sibling child,previous and parent process) in the case I know only child process id and user id, For example I strart to trace pid 124 of user A (uid = 100) and then I noticed that he doing something wrong so, I get process id now process id is 156 (supposed) then I want to kill all inherrit processes of user A (now I know only this process is 156 and uid is 100)...
1
3148
by: Manfred Braun | last post by:
Hi All, I am writing a tool, which should monitor some exe-processes, which are not very solid. Th main function is to re-start them, if they hung, but this is complicated. I can detect things like no longer generating IO or such properties and I use WMI to do that. I am also looking for attached subprocesses, which are one of the system debuggers. I wrote a test-program, which creates a divide by zero error after some seconds. I can...
0
2188
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a command button in the application. So the code goes something like this: psiBat = New ProcessStartInfo(arrRun.Item(0)(1)) psiBat.WindowStyle = ProcessWindowStyle.Hidden
4
20779
by: Richard Rossel | last post by:
Hi Fellows, I have a problem with process termination. I have a python code that apache runs through a django interface. The code is very simple, first, it creates a process with the subprocess.Popen call, and afterwards, (using a web request) the python code uses the PID of the previously created process(stored in a db) and kills it with an os.kill call using the SIGKILL signal. The creation of the process is ok, apache calls the...
4
7177
by: yxq | last post by:
Hello, I want to kill the Explorer process, after Explorer process has been killed, it will restart automatically immediately. How to disable it restart automatically? for example, in Windows Task Manager, you can kill explorer process, but it will not restart automatically. My code: ///////////////////////////////////////////// For Each ObjPro As Process In Process.GetProcessesByName("EXPLORER")
2
2503
by: =?Utf-8?B?WVhR?= | last post by:
Hello, In the parent process(A), run update function, and start the update process(B), in B process, kill A, then download and update files, then restart A. I want to know can the B process kill A process? Thank you
0
8844
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
8731
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
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
9218
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
9067
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5986
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
4755
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3191
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.