Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # linux, mac
- os.kill(pid, signal.SIGKILL)
- killedpid, stat = os.waitpid(pid, os.WNOHANG)
- if killedpid == 0:
- print >> sys.stderr, "ACK! PROCESS NOT KILLED?"
- # windows
- handle = subprocess.Popen("someprocess here", shell=False)
- subprocess.Popen("taskkill /F /T /PID %i"%handle.pid , shell=True)
- #also
- # Create a process that won't end on its own
- import subprocess
- process = subprocess.Popen(['python.exe', '-c', 'while 1: pass'])
- # Kill the process using pywin32
- import win32api
- win32api.TerminateProcess(int(process._handle), -1)
- # Kill the process using ctypes
- import ctypes
- ctypes.windll.kernel32.TerminateProcess(int(process._handle), -1)
- # Kill the proces using pywin32 and pid
- import win32api
- PROCESS_TERMINATE = 1
- handle = win32api.OpenProcess(PROCESS_TERMINATE, False, process.pid)
- win32api.TerminateProcess(handle, -1)
- win32api.CloseHandle(handle)
- # Kill the proces using ctypes and pid
- import ctypes
- PROCESS_TERMINATE = 1
- handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, process.pid)
- ctypes.windll.kernel32.TerminateProcess(handle, -1)
- ctypes.windll.kernel32.CloseHandle(handle)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement