Check if a process with given PID is running. Args: pid: Process ID to check Returns: True if process exists, False otherwise
(pid: int)
| 343 | |
| 344 | |
| 345 | def process_exists(pid: int) -> bool: |
| 346 | """Check if a process with given PID is running. |
| 347 | |
| 348 | Args: |
| 349 | pid: Process ID to check |
| 350 | |
| 351 | Returns: |
| 352 | True if process exists, False otherwise |
| 353 | """ |
| 354 | try: |
| 355 | # os.kill with signal 0 doesn't actually kill the process, |
| 356 | # it just checks if we can send a signal to it |
| 357 | os.kill(pid, 0) |
| 358 | return True |
| 359 | except ProcessLookupError: |
| 360 | return False |
| 361 | except PermissionError: |
| 362 | # Process exists but we don't have permission to signal it |
| 363 | return True |
| 364 | except KeyboardInterrupt as ki: |
| 365 | handle_keyboard_interrupt(ki) |
| 366 | raise |
| 367 | except Exception: |
| 368 | return False |
| 369 | |
| 370 | |
| 371 | def docker_container_exists(container_name: str) -> Optional[str]: |