Killing a process under Windows NT/2K

Ingo Blank spam at yourself.com
Fri Apr 26 09:29:59 EDT 2002


"Syver Enstad" <syver-en+usenet at online.no> schrieb im Newsbeitrag
news:ur8l2wsch.fsf at online.no...
> "Ingo Blank" <spam at yourself.com> writes:
>
> > Hi,
> >
> > I need to kill a process under Windows (NT/2K), whose PID is known.
> > Unfortunately os.kill() doesn't work under Windows.
> > How can I achieve this anyway?
> >
> > Thanks in advance
> >
>
> This might help. You have to have the win32all extensions installed,
> but so should *everybody* that uses python on win32 anyway.
>
> # Utility functions that should have been implemented in the os module
> import signal
> signal.SIGKILL = 120 # cludge: try to mimic the standard library kill
>
> def kill(pid, sig):
>     assert sig == signal.SIGKILL # cludge: try to mimic the standard
library kill
>     handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, pid)
>     win32api.TerminateProcess(handle, 1) # exit status
>
>
> def waitpid(pid):
>     handle =
win32api.OpenProcess(win32con.SYNCHRONIZE|win32con.PROCESS_QUERY_INFORMATION
, 0, pid)
>     win32event.WaitForSingleObject(handle, win32event.INFINITE)
>     exitCode = win32process.GetExitCodeProcess(handle)
>     return pid, exitCode
>

Thanks for your help, Syver!
That works perfectly...

--ingo

>
> Vennlig hilsen
>
> Syver Enstad





More information about the Python-list mailing list