{"record":{"id":"be2ccfc8361af61a","repo":"go-delve/delve","slug":"could-not-attach-to-pid-d-already-being-debugged","errorCode":null,"errorMessage":"could not attach to pid %d: already being debugged by pid %d","messagePattern":"could not attach to pid (.+?): already being debugged by pid (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/debugger/debugger_linux.go","lineNumber":52,"sourceCode":"\t\t\t}\n\t\t\tif fi.Sys().(*syscall.Stat_t).Uid != uint32(os.Getuid()) {\n\t\t\t\treturn fmt.Errorf(\"Could not attach to pid %d: current user does not own the process\", pid)\n\t\t\t}\n\n\t\t\t// check if the process is already being traced\n\t\t\tstatusfh, err := os.Open(fmt.Sprintf(\"/proc/%d/status\", pid))\n\t\t\tif err != nil {\n\t\t\t\treturn fallbackerr\n\t\t\t}\n\t\t\tdefer statusfh.Close()\n\t\t\tscan := bufio.NewScanner(statusfh)\n\t\t\tconst tracerPidPrefix = \"TracerPid:\"\n\t\t\tfor scan.Scan() {\n\t\t\t\tline := scan.Text()\n\t\t\t\tif strings.HasPrefix(line, tracerPidPrefix) {\n\t\t\t\t\ttpid, _ := strconv.Atoi(strings.TrimSpace(line[len(tracerPidPrefix):]))\n\t\t\t\t\tif tpid != 0 {\n\t\t\t\t\t\treturn fmt.Errorf(\"could not attach to pid %d: already being debugged by pid %d\", pid, tpid)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn fallbackerr\n}\n","sourceCodeStart":34,"sourceCodeEnd":60,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/debugger/debugger_linux.go#L34-L60","documentation":"The target process is already being traced by another debugger: /proc/<pid>/status shows a non-zero TracerPid. A process can only have one ptrace tracer at a time, so the attach is rejected with the tracing debugger's pid.","triggerScenarios":"'dlv attach <pid>' while another delve/gdb/strace session already has the process attached (TracerPid: <tpid> in /proc/<pid>/status).","commonSituations":"Two developers attaching to the same dev server; a forgotten strace or previous delve session left attached; IDE debug session still open holding the process.","solutions":["Detach or close the other debugger session (its pid is in the error message)","Kill the other tracer process: kill <tracerPid>","Check with: cat /proc/<pid>/status | grep TracerPid before attaching","Retry attach once the TracerPid becomes 0"],"exampleFix":"// before\ndlv attach 12345 // already traced by pid 999\n// after (shell)\nkill 999\ndlv attach 12345","handlingStrategy":"validation","validationCode":"out, _ := os.ReadFile(fmt.Sprintf(\"/proc/%d/status\", pid))\nalreadyTraced := strings.Contains(string(out), \"TracerPid:\\t0\") == false","typeGuard":null,"tryCatchPattern":"err := debugger.Attach(pid, []string{}, nil)\nif err != nil && strings.Contains(err.Error(), \"already being debugged\") {\n    // detach/kill the tracer pid parsed from the message, then retry once\n}","preventionTips":["Check TracerPid in /proc/<pid>/status before attaching","Ensure previous debug sessions detach on exit (no orphan strace/gdb)","Serialize access to the debug target across the team/tooling","Automate cleanup of stale tracer processes"],"tags":["linux","ptrace","already-traced","attach"],"backgroundTag":"process-already-traced","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}