Spaces:
Sleeping
Sleeping
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() | |