Killing a process under Windows NT/2K

Syver Enstad syver-en+usenet at online.no
Fri Apr 26 08:36:05 EDT 2002


"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


-- 

Vennlig hilsen 

Syver Enstad



More information about the Python-list mailing list