469,306 Members | 1,850 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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 3577
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Jacek Popławski | last post: by
6 posts views Thread by Dakkar | last post: by
reply views Thread by Shruti A via .NET 247 | last post: by
3 posts views Thread by kunal.kewalramani | last post: by
6 posts views Thread by laststubborn | last post: by
2 posts views Thread by tony.newsgrps | last post: by
4 posts views Thread by Thomas Nelson | last post: by
6 posts views Thread by Roger Heathcote | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.