Advertisement
Guest User

killer.py

a guest
Jan 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. # linux, mac
  2. os.kill(pid, signal.SIGKILL)
  3. killedpid, stat = os.waitpid(pid, os.WNOHANG)
  4. if killedpid == 0:
  5. print >> sys.stderr, "ACK! PROCESS NOT KILLED?"
  6. # windows
  7. handle = subprocess.Popen("someprocess here", shell=False)
  8. subprocess.Popen("taskkill /F /T /PID %i"%handle.pid , shell=True)
  9. #also
  10. # Create a process that won't end on its own
  11. import subprocess
  12. process = subprocess.Popen(['python.exe', '-c', 'while 1: pass'])
  13. # Kill the process using pywin32
  14. import win32api
  15. win32api.TerminateProcess(int(process._handle), -1)
  16. # Kill the process using ctypes
  17. import ctypes
  18. ctypes.windll.kernel32.TerminateProcess(int(process._handle), -1)
  19. # Kill the proces using pywin32 and pid
  20. import win32api
  21. PROCESS_TERMINATE = 1
  22. handle = win32api.OpenProcess(PROCESS_TERMINATE, False, process.pid)
  23. win32api.TerminateProcess(handle, -1)
  24. win32api.CloseHandle(handle)
  25. # Kill the proces using ctypes and pid
  26. import ctypes
  27. PROCESS_TERMINATE = 1
  28. handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, process.pid)
  29. ctypes.windll.kernel32.TerminateProcess(handle, -1)
  30. ctypes.windll.kernel32.CloseHandle(handle)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement