killproc.py 648 B

1234567891011121314151617181920212223
  1. import py
  2. import os, sys
  3. if sys.platform == "win32" or getattr(os, '_name', '') == 'nt':
  4. try:
  5. import ctypes
  6. except ImportError:
  7. def dokill(pid):
  8. py.process.cmdexec("taskkill /F /PID %d" %(pid,))
  9. else:
  10. def dokill(pid):
  11. PROCESS_TERMINATE = 1
  12. handle = ctypes.windll.kernel32.OpenProcess(
  13. PROCESS_TERMINATE, False, pid)
  14. ctypes.windll.kernel32.TerminateProcess(handle, -1)
  15. ctypes.windll.kernel32.CloseHandle(handle)
  16. else:
  17. def dokill(pid):
  18. os.kill(pid, 15)
  19. def kill(pid):
  20. """ kill process by id. """
  21. dokill(pid)