473,386 Members | 1,679 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,386 software developers and data experts.

Killing process

I am using os.getpid() to get the pid value for a script running. I
store that value (as a string) to a file. Later when I try to kill that
pid (i pull this from the file as a string value) I get errors.

Using the following lines I get the subsequent error.

(pid is a string value)
win32api.TerminateProcess(int(pid), 0)

OR

ctypes.windll.kernel32.TerminateProcess(int(pid), 0)

Errors:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python23\lib\lib-tk\Tkinter.py", line 1345, i
return self.func(*args)
File "vngconsole.py", line 27, in StopVngSvc
win32api.TerminateProcess(int(pid), 0)
error: (6, 'TerminateProcess', 'The handle is invalid.')

How exactly do I kill a pid using a string value?

Jul 19 '05 #1
8 3701
TerminateProcess takes a process handle, not a pid.
win32api.OpenProcess will give you a handle.

Roger

"Harlin Seritt" <ha**********@yahoo.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
I am using os.getpid() to get the pid value for a script running. I
store that value (as a string) to a file. Later when I try to kill that
pid (i pull this from the file as a string value) I get errors.

Using the following lines I get the subsequent error.

(pid is a string value)
win32api.TerminateProcess(int(pid), 0)

OR

ctypes.windll.kernel32.TerminateProcess(int(pid), 0)

Errors:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python23\lib\lib-tk\Tkinter.py", line 1345, i
return self.func(*args)
File "vngconsole.py", line 27, in StopVngSvc
win32api.TerminateProcess(int(pid), 0)
error: (6, 'TerminateProcess', 'The handle is invalid.')

How exactly do I kill a pid using a string value?



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 19 '05 #2
Yeah I've kind of figured that. I was just wanting to know what I could
use to kill a pid that is a string value. Thanks though.

Harlin

Jul 19 '05 #3
Harlin Seritt wrote:
I am using os.getpid() to get the pid value for a script running. I
store that value (as a string) to a file. Later when I try to kill that
pid (i pull this from the file as a string value) I get errors. [...] File "vngconsole.py", line 27, in StopVngSvc
win32api.TerminateProcess(int(pid), 0)
error: (6, 'TerminateProcess', 'The handle is invalid.')


I believe the problem is you are assuming TerminateProcess() takes a
PID, when in fact it takes a "handle". See this recipe for some hints:
http://aspn.activestate.com/ASPN/Coo.../Recipe/347462
and
http://msdn.microsoft.com/library/de...ateprocess.asp
to learn more about the key function you're missing.

-Peter
Jul 19 '05 #4
I think I need something besides TerminateProcess(). Is there anyway
possible to terminate a process by just passing a string value to the
function? Honestly, I am not interesting in terminating a process by
its handle.

Jul 19 '05 #5
Harlin Seritt wrote:
I think I need something besides TerminateProcess(). Is there anyway
possible to terminate a process by just passing a string value to the
function? Honestly, I am not interesting in terminating a process by
its handle.


This is a bizarre request. Why can't you just call int() as you did in
your example to turn the string into a number? And if you can do that,
why would you have a problem using the *defined mechanism* to convert
from a PID to a handle, which is what the Windows API routine to kill
processes requires?

-Peter
Jul 19 '05 #6
I actually tried mapping the PID to an integer value and it still
didn't work. At any rate, I found another way to do it. Thanks anyways.

Jul 19 '05 #7
Harlin Seritt wrote:
I actually tried mapping the PID to an integer value and it still
didn't work. At any rate, I found another way to do it. Thanks anyways.


For those who might follow in your footsteps, it might be nice to
describe your solution... (and to reduce the likelihood somebody will
have to spend time repeating all those links and ideas again...)

Thanks,
-Peter
Jul 19 '05 #8
# ha**********@yahoo.com / 2005-05-01 05:07:27 -0700:
I actually tried mapping the PID to an integer value and it still
didn't work. At any rate, I found another way to do it. Thanks anyways.


What the kind people have been trying to get through is that the
win32api.TerminateProcess() does *NOT* take a pid (whether integer
or numeric string).

Got it?

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
Jul 19 '05 #9

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

Similar topics

10
by: Jacek Popławski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem is, that I need some timeout. I need to say for...
6
by: Dakkar | last post by:
How can i control my program when someone kill it's process from the taskmanager my dispose script is working well if i close the program manually but if i kill it from taskmanager its not working...
0
by: Shruti A via .NET 247 | last post by:
hello group I have recently started working on .Net platform. I am facing one problem in killing and starting process from my aspx page. I am able to kill and start the same process from vb.net...
3
by: kunal.kewalramani | last post by:
I'm opening an Excel file using ASP.NET, but Excel process remains it is not killed, I tried killing it by using Quit() that is also not working, if anybody have any solution for this please help me...
10
by: shiry | last post by:
Hi, I need to do some important cleanup before my console application exists. I used the console ctrl event. This is working well and it fires for all cases, including the CTRL_CLOSE_EVENT (if I...
6
by: laststubborn | last post by:
Hi everybody, We have a very large database and high transaction volume. Time to time these transactions are locking each other and decrease the performance of the database. Is there any way...
8
by: Rain | last post by:
Does anyone know how i can kill a process using C#? im developing an asp.net web application using C# and the asp.net process doesnt die even if the application has already exited. So i need to...
2
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try...
4
by: Thomas Nelson | last post by:
Hi, I'd like to start a program, run it for a while, then terminate it. I can do this on linux, but I'm new to working with windows. Here's my script: from subprocess import Popen from time...
6
by: Roger Heathcote | last post by:
sjdevnull@yahoo.com wrote: <snip> Fair point, but for sub processes that need to be in close contact with the original app, or very small functions that you'd like 100s or 1000s of it seems...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...
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.