File size: 619 Bytes
2d6aefc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()