project_charles / pid_helper.py
sohojoe's picture
fix: ui_app will start charles_app when not in debug mode
2d6aefc
raw
history blame contribute delete
No virus
619 Bytes
import os
import platform
import psutil
def is_pid_running(pid: int) -> bool:
system = platform.system()
if system == "Linux" or system == "Darwin": # Linux or macOS
try:
os.kill(pid, 0)
return True
except OSError:
return False
elif system == "Windows":
try:
process = psutil.Process(pid)
return True
except psutil.NoSuchProcess:
return False
else:
raise NotImplementedError(f"Unsupported operating system: {system}")
def get_current_pid() -> int:
return os.getpid()