Private/Test-WatcherAlive.ps1
|
# Internal helper -- liveness check on the apply-watcher background process. # Returns $true if the PID file exists, parses as a positive int, AND a # matching process is currently running. False otherwise. function Test-WatcherAlive { param( [Parameter(Mandatory)][string]$WatcherPidFile ) if (-not (Test-Path $WatcherPidFile)) { return $false } try { $raw = (Get-Content $WatcherPidFile -Raw -ErrorAction Stop).Trim() if ($raw -notmatch '^\d+$') { return $false } return [bool](Get-Process -Id ([int]$raw) -ErrorAction SilentlyContinue) } catch { return $false } } |