mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 20:53:13 -06:00
28 lines
608 B
Python
28 lines
608 B
Python
|
import platform
|
||
|
import ctypes
|
||
|
import os
|
||
|
import signal
|
||
|
|
||
|
|
||
|
def kill_windows_process(pid):
|
||
|
PROCESS_TERMINATE = 1
|
||
|
SYNCHRONIZE=1048576
|
||
|
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, False, pid)
|
||
|
ctypes.windll.kernel32.TerminateProcess(handle, -1)
|
||
|
ctypes.windll.kernel32.WaitForSingleObject(handle, 1000)
|
||
|
ctypes.windll.kernel32.CloseHandle(handle)
|
||
|
|
||
|
def kill_unix_process(pid):
|
||
|
try:
|
||
|
os.kill(pid, signal.SIGKILL)
|
||
|
except OSError:
|
||
|
pass
|
||
|
|
||
|
def kill_process(pid):
|
||
|
if pid < 0:
|
||
|
return
|
||
|
if platform.system() == 'Windows':
|
||
|
kill_windows_process(pid)
|
||
|
else:
|
||
|
kill_unix_process(pid)
|