473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 6471
En Tue, 06 Feb 2007 22:59:40 -0300, <el*********@gmail.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.Popen(["./TestTool"], cwd="/home")
child2 = subprocess.Popen(["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...@gmail.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.Popen(["./TestTool"], cwd="/home")
child2 = subprocess.Popen(["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*********@gmail.comescribió:
>import subprocess
child1 = subprocess.Popen(["./TestTool"], cwd="/home")
child2 = subprocess.Popen(["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
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...
10
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...
10
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...
3
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...
1
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...
0
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...
4
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...
4
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.