{"record":{"id":"88fd661d262d87e7","repo":"pranshuparmar/witr","slug":"process-d-not-found-w-88fd66","errorCode":null,"errorMessage":"process %d not found: %w","messagePattern":"process (.+?) not found: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/proc/process_freebsd.go","lineNumber":35,"sourceCode":"func ReadProcess(pid int) (model.Process, error) {\n\t// Reject PID 0 (and negatives): on FreeBSD `ps -p 0` returns the kernel\n\t// swapper, which is not a real userland target. Matches the other platforms.\n\tif pid <= 0 {\n\t\treturn model.Process{}, fmt.Errorf(\"invalid pid %d\", pid)\n\t}\n\tpidStr := strconv.Itoa(pid)\n\n\t// Format: pid(0) ppid(1) uid(2) jid(3) state(4) pcpu(5) rss(6) lstart(7-11) args(12+)\n\t// comm is excluded because it can contain spaces, which breaks strings.Fields parsing.\n\t// The display name is derived from args instead.\n\tcmd := exec.Command(\"ps\", \"-p\", pidStr,\n\t\t\"-o\", \"pid=\", \"-o\", \"ppid=\", \"-o\", \"uid=\", \"-o\", \"jid=\",\n\t\t\"-o\", \"state=\", \"-o\", \"pcpu=\", \"-o\", \"rss=\",\n\t\t\"-o\", \"lstart=\", \"-o\", \"args=\")\n\tcmd.Env = buildEnvForPS()\n\tout, err := cmd.Output()\n\tif err != nil {\n\t\treturn model.Process{}, fmt.Errorf(\"process %d not found: %w\", pid, err)\n\t}\n\n\tline := strings.TrimSpace(string(out))\n\tif line == \"\" {\n\t\treturn model.Process{}, fmt.Errorf(\"process %d not found\", pid)\n\t}\n\n\tfields := strings.Fields(line)\n\tif len(fields) < 12 {\n\t\treturn model.Process{}, fmt.Errorf(\"unexpected ps output format for pid %d: got %d fields in %q\", pid, len(fields), line)\n\t}\n\n\tppid, _ := strconv.Atoi(fields[1])\n\tuid, _ := strconv.Atoi(fields[2])\n\tjid := fields[3]\n\tstate := fields[4]\n\tcpuPct, _ := strconv.ParseFloat(fields[5], 64)\n\trssKB, _ := strconv.ParseFloat(fields[6], 64)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/pranshuparmar/witr/blob/dc4fa1da82d3e266fcbd928641b4f30b3077c64f/internal/proc/process_freebsd.go#L17-L53","documentation":"FreeBSD ReadProcess runs `ps -p <pid> -o ...`; a non-zero ps exit (normally because the PID does not exist) yields this error with the exec error wrapped via %w. It is the primary 'process is gone' signal on FreeBSD.","triggerScenarios":"ReadProcess on a PID that already terminated (ps exit 1), or exec failures such as ps missing from PATH, both surfaced wrapped in this message.","commonSituations":"Target exited between discovery and lookup; minimal jails/containers lacking ps; supervisor restarted the process with a new PID.","solutions":["Verify the PID exists (`ps -p <pid>`) before retrying; if not, the process is gone.","Retry promptly to minimize the exit race.","Inspect the wrapped error to distinguish 'No such process' from 'executable not found' (install/procps availability issue).","Inspect the parent process instead if the child exited; check for PID reuse with fresh data."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// FreeBSD: existence check before ReadProcess\nif out, err := exec.Command(\"ps\", \"-p\", strconv.Itoa(pid), \"-o\", \"pid=\").Output(); err != nil || len(strings.TrimSpace(string(out))) == 0 {\n    return fmt.Errorf(\"pid %d not running\", pid)\n}","typeGuard":null,"tryCatchPattern":"proc, err := proc.ReadProcess(pid)\nif err != nil {\n    if strings.Contains(err.Error(), \"not found\") {\n        // target exited: unwrap %w to confirm 'No such process'\n    }\n}","preventionTips":["Read the process promptly after PID discovery","Confirm ps exists in jails/containers where the tool runs","Unwrap the error to separate process-exit from environment failures"],"tags":["freebsd","process-exited","ps"],"backgroundTag":"process-not-found","analyzedSha":"dc4fa1da82d3e266fcbd928641b4f30b3077c64f","analyzedAt":"2026-09-01T12:17:08.767Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}