//go:build !windows package store import ( "errors" "os" "syscall" ) // processAlive checks whether the given PID belongs to a running process. // On POSIX, kill(pid, 0) sends no signal but returns ESRCH if the PID is // dead, EPERM if alive-but-foreign-owned (still "alive" for our purposes). // // os.FindProcess never returns a non-nil error on Linux / macOS / *BSD // for any PID value — it just records the integer. The probe is purely // the Signal(0) result. We keep the FindProcess call to obtain the // *os.Process handle Signal needs; we don't branch on its error. func processAlive(pid int) bool { if pid <= 0 { return false } proc, _ := os.FindProcess(pid) if proc == nil { return false } err := proc.Signal(syscall.Signal(0)) if err == nil { return true } // EPERM = alive but not ours; ESRCH = dead. return errors.Is(err, os.ErrPermission) || errors.Is(err, syscall.EPERM) }