{"record":{"id":"9d78c9e7902dae04","repo":"go-delve/delve","slug":"setpgid","errorCode":null,"errorMessage":"setpgid","messagePattern":"setpgid","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/native/exec_darwin.c","lineNumber":69,"sourceCode":"\t\tif (n != 0) {\n\t\t\t// Child died, reap it.\n\t\t\twaitpid(pid, NULL, 0);\n\t\t\treturn -1;\n\t\t}\n\t\treturn pid;\n\t}\n\n\t// Fork succeeded, we are in the child.\n\tint pret, cret;\n\tchar sig;\n\n\tclose(fd[1]);\n\tread(fd[0], &sig, 1);\n\tclose(fd[0]);\n\n\t// Create a new process group.\n\tif (setpgid(0, 0) < 0) {\n\t\tperror(\"setpgid\");\n\t\texit(1);\n\t}\n\n\t// Set errno to zero before a call to ptrace.\n\t// It is documented that ptrace can return -1 even\n\t// for successful calls.\n\terrno = 0;\n\tpret = ptrace(PT_TRACE_ME, 0, 0, 0);\n\tif (pret != 0 && errno != 0) {\n\t\tperror(\"ptrace\");\n\t\texit(1);\n\t}\n\n\t// Change working directory if wd is not empty.\n\tif (wd && wd[0]) {\n\t\terrno = 0;\n\t\tcret = chdir(wd);\n\t\tif (cret != 0 && errno != 0) {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/native/exec_darwin.c#L51-L87","documentation":"fork_exec in the native macOS backend prints this via perror and exits when setpgid(0,0) fails while the child process is being prepared for debugging. The child must become its own process group so the debugger can deliver signals to it independently; failing here aborts the debuggee before exec, causing process launch to fail.","triggerScenarios":"Launching a program with dlv (native backend) on macOS when the child's setpgid(0,0) system call fails, typically due to session/process-group restrictions of the parent (e.g. job-control restrictions, restricted sandbox, or a process-group ID race).","commonSituations":"Launching delve from restricted environments (containers without proper process APIs, sandboxed IDE terminals); extremely resource-constrained systems; EPERM/EACCES from a hardened runtime or security agent.","solutions":["Check that the parent environment permits process-group creation (run delve from a normal shell/terminal rather than a heavily sandboxed context).","Inspect errno context on the machine (dmesg/sandbox logs) and any macOS security policies (SIP, MDM, sandbox profiles) blocking setpgid.","Ensure your macOS/SDK versions match what your delve build supports; rebuild delve with a current Xcode toolchain.","As a workaround, attach to an already-running process (dlv attach) instead of fork/exec launch."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure the environment allows creating process groups\nif err := syscall.Setpgid(0, 0); err != nil {\n\treturn fmt.Errorf(\"environment forbids setpgid: %w\", err)\n}\n// restore group if needed by your harness","typeGuard":"func isExecLaunchFailure(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"setpgid\")\n}","tryCatchPattern":"err := dlvClient.Launch(ctx, prog, args)\nif err != nil && strings.Contains(err.Error(), \"setpgid\") {\n\tlog.Printf(\"fork/exec launch blocked (setpgid): %v — try dlv attach or a less restricted environment\", err)\n\treturn fallbackToAttach()\n}","preventionTips":["Run delve from a normal shell/terminal, not heavily sandboxed or restricted CI contexts.","Keep macOS and Xcode toolchain updated; rebuild delve per release instructions.","Prefer `dlv attach` in environments with process restrictions.","Watch sandbox/EDR logs for denials when launches fail."],"tags":["macos","ptrace","process-launch","posix","native-backend"],"backgroundTag":"setpgid-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}