{"record":{"id":"5cf30f693140bfa0","repo":"abiosoft/colima","slug":"process-signal-0-returned-error-w","errorCode":null,"errorMessage":"process signal(0) returned error: %w","messagePattern":"process signal\\(0\\) returned error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/daemon/daemon.go","lineNumber":134,"sourceCode":"\t}\n\n\t// check if process is actually running\n\tp, err := os.ReadFile(info.PidFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading pid file: %w\", err)\n\t}\n\tpid, _ := strconv.Atoi(string(p))\n\tif pid == 0 {\n\t\treturn fmt.Errorf(\"invalid pid: %v\", string(p))\n\t}\n\n\tprocess, err := os.FindProcess(pid)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"process not found: %v\", err)\n\t}\n\n\tif err := process.Signal(syscall.Signal(0)); err != nil {\n\t\treturn fmt.Errorf(\"process signal(0) returned error: %w\", err)\n\t}\n\n\treturn nil\n}\n\nconst (\n\tpidFileName = \"daemon.pid\"\n\tlogFileName = \"daemon.log\"\n)\n\nfunc Info() struct {\n\tPidFile string\n\tLogFile string\n} {\n\tdir := dir()\n\treturn struct {\n\t\tPidFile string\n\t\tLogFile string","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/daemon/daemon.go#L116-L152","documentation":"The daemon liveness probe sends signal 0 (existence check, no actual signal delivered) to the pid read from the pid file. An error means errno ESRCH (no process with that pid — stale pid file, daemon died) or EPERM (process exists but belongs to another user — pid was recycled after a reboot or by another daemon). The wrapped syscall error distinguishes the two.","triggerScenarios":"Daemon exited or crashed but left daemon.pid behind; host rebooted and the stale pid now maps to a live process of another user (EPERM); daemon started under sudo so a non-root status check hits EPERM; pid recycling on long-lived hosts.","commonSituations":"Skipping `colima daemon stop` in favor of kill/reboot; daemon started with sudo and queried as regular user (or vice versa); stale daemon.pid surviving a colima upgrade or profile switch; an unrelated process adopting the same pid after reboot.","solutions":["Check the wrapped errno: ESRCH means stale pid file — remove dir()/daemon.pid and run `colima daemon start`; EPERM means another user's process holds the pid — likewise delete the stale pid file","Inspect the daemon log (dir()/daemon.log) for why the daemon exited","Avoid mixing sudo and non-sudo invocations of colima daemon"],"exampleFix":"# before\n$ colima daemon status\nprocess signal(0) returned error: no such process\n\n# after\n$ rm .../daemon.pid   # remove stale pid file\n$ colima daemon start\n$ colima daemon status","handlingStrategy":"validation","validationCode":"// probe liveness yourself before relying on daemon status\nfunc daemonAlive(pidFile string) bool {\n    b, err := os.ReadFile(pidFile)\n    if err != nil {\n        return false\n    }\n    pid, err := strconv.Atoi(strings.TrimSpace(string(b)))\n    if err != nil || pid <= 0 {\n        return false\n    }\n    proc, _ := os.FindProcess(pid)\n    return proc.Signal(syscall.Signal(0)) == nil\n}","typeGuard":null,"tryCatchPattern":"// distinguish stale-pid (ESRCH) from foreign-owner (EPERM)\nif err := status(); err != nil {\n    var errno syscall.Errno\n    if errors.As(err, &errno) {\n        switch errno {\n        case syscall.ESRCH: // stale pid file -> safe to remove\n        case syscall.EPERM: // pid recycled to another user -> also stale for us\n        }\n    }\n}","preventionTips":["Stop daemons through their stop command so pid files are cleaned up","Do not run colima daemon under sudo in one session and as user in another — mixed ownership triggers EPERM probes","After host reboots, expect stale pid files: wrap daemon startup in a check that removes a pid file whose pid is not alive"],"tags":["go","colima","daemon","pidfile","signals"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}