Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Killing process

Reply
Thread Tools

Killing process

 
 
Harlin Seritt
Guest
Posts: n/a
 
      04-30-2005
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?

 
Reply With Quote
 
 
 
 
Roger Upole
Guest
Posts: n/a
 
      04-30-2005
TerminateProcess takes a process handle, not a pid.
win32api.OpenProcess will give you a handle.

Roger

"Harlin Seritt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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 =---
 
Reply With Quote
 
 
 
 
Harlin Seritt
Guest
Posts: n/a
 
      04-30-2005
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

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      04-30-2005
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
 
Reply With Quote
 
Harlin Seritt
Guest
Posts: n/a
 
      04-30-2005
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.

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      04-30-2005
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
 
Reply With Quote
 
Harlin Seritt
Guest
Posts: n/a
 
      05-01-2005
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.

 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      05-02-2005
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
 
Reply With Quote
 
Roman Neuhauser
Guest
Posts: n/a
 
      05-18-2005
# http://www.velocityreviews.com/forums/(E-Mail Removed) / 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Killing Tomcat Process In Eclipse IDE Anshuman Java 0 01-04-2005 12:22 PM
Control Panel Not loading, only when killing the asp_wp.exe process GregO ASP .Net 0 07-20-2004 03:56 PM
Killing and Starting IIS and a VB.Net process using ASP.Net Shruti A via .NET 247 ASP .Net 0 05-15-2004 10:54 AM
Process killing Michael Johnson Sr. ASP .Net 0 02-10-2004 03:29 PM
killing a process in ms windows - newbie Sting C Programming 2 12-29-2003 10:13 AM



Advertisments