cadrumo.core.pid_liveness module¶
Cross-platform PID-liveness probe shared by the crash-recoverable locks.
Both the bucket lockfile
(adapters.persistence.storage.bucket) and the auth-acquisition lock
(application.auth) reclaim a stale lock by asking the OS whether the
recorded holder PID is still a live process. This module is the single home
for that probe so the two lock subsystems cannot diverge on Windows
failure-mode handling: a probe failure other than “PID does not exist” MUST
be treated as alive, never as grounds to reclaim a lock this process cannot
actually inspect.
- pid_is_alive(pid)[source]¶
Return whether
pidis a live process, per a best-effort OS probe.Returns
Truewhen the OS reportspidas a live process andFalsewhen the OS reports it as gone (orpidis not a valid process id). A permission error probing the PID (it exists but belongs to another user, or this process lacks the query right) is treated as alive: from the caller’s perspective a lock held by that PID cannot be safely reclaimed.On Windows the probe distinguishes
ERROR_INVALID_PARAMETER(87, returned byOpenProcessfor a PID that no longer exists) from every otherOpenProcessfailure (access-denied against a foreign or protected process, a PID recycled onto a process this call cannot query, etc.). Only the former is treated as dead; every other failure is treated as alive so a lock is never wrongly reclaimed just because this process could not inspect its holder.