- import os,sys,signal
- if verbose(): print "######## killpid pid = ", pid
- if sys.platform == "win32":
- import ctypes
- handle = ctypes.windll.kernel32.OpenProcess(1, False, int(pid))
- ctypes.windll.kernel32.TerminateProcess(handle, -1)
- ctypes.windll.kernel32.CloseHandle(handle)
- else:
- os.kill(int(pid),signal.SIGKILL)
+ import os, sys
+ if sig != 0:
+ if verbose(): print "######## killpid pid = ", pid
+ try:
+ if sys.platform == "win32":
+ import ctypes
+ if sig == 0:
+ # PROCESS_QUERY_INFORMATION (0x0400) Required to retrieve certain information about a process
+ handle = ctypes.windll.kernel32.OpenProcess(0x0400, False, int(pid))
+ if handle:
+ ret = 1
+ ctypes.windll.kernel32.CloseHandle(handle)
+ else:
+ ret = 0
+ if sig == 9:
+ # PROCESS_TERMINATE (0x0001) Required to terminate a process using TerminateProcess.
+ handle = ctypes.windll.kernel32.OpenProcess(0x0001, False, int(pid))
+ ret = ctypes.windll.kernel32.TerminateProcess(handle, -1)
+ ctypes.windll.kernel32.CloseHandle(handle)
+ pass
+ pass
+ else:
+ # Default: signal.SIGKILL = 9
+ os.kill(int(pid),sig)
+ ret = 1
+ pass