{"record":{"id":"62d7f056482189e8","repo":"juicedata/juicefs","slug":"failed-to-execute-command-s-v-62d7f0","errorCode":null,"errorMessage":"failed to execute command `%s`: %v","messagePattern":"failed to execute command `(.+?)`: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/debug_unix.go","lineNumber":61,"sourceCode":"\t\tif err := json.Unmarshal(content, &cfg); err != nil {\r\n\t\t\tlogger.Warnf(\"failed to unmarshal config file: %v\", err)\r\n\t\t}\r\n\t\tif cfg.Pid != 0 {\r\n\t\t\ttmpPid = strconv.Itoa(cfg.Pid)\r\n\t\t}\r\n\t\treturn nil\r\n\t}, 3*time.Second)\r\n\r\n\tvar psArgs []string\r\n\tif tmpPid != \"\" {\r\n\t\tpid = tmpPid\r\n\t\tpsArgs = []string{\"/bin/sh\", \"-c\", fmt.Sprintf(\"ps -f -p %s\", pid)}\r\n\t} else {\r\n\t\tpsArgs = []string{\"/bin/sh\", \"-c\", fmt.Sprintf(\"ps -ef | grep -v grep | grep mount | grep %s\", mp)}\r\n\t}\r\n\tret, err := exec.Command(psArgs[0], psArgs[1:]...).CombinedOutput()\r\n\tif err != nil {\r\n\t\treturn \"\", \"\", \"\", fmt.Errorf(\"failed to execute command `%s`: %v\", strings.Join(psArgs, \" \"), err)\r\n\t}\r\n\tvar find bool\r\n\tvar ppid string\r\n\tlines := strings.Split(string(ret), \"\\n\")\r\n\tfor i := len(lines) - 1; i >= 0; i-- {\r\n\t\tline := lines[i]\r\n\t\tfields := strings.Fields(line)\r\n\t\tif len(fields) <= 7 {\r\n\t\t\tcontinue\r\n\t\t}\r\n\t\tcmdFields := fields[7:]\r\n\t\tfor _, arg := range cmdFields {\r\n\t\t\tif mp == arg {\r\n\t\t\t\tif find {\r\n\t\t\t\t\tnewCmd := strings.Join(fields[7:], \" \")\r\n\t\t\t\t\tnewUid, newPid, newPpid := strings.TrimSpace(fields[0]), strings.TrimSpace(fields[1]), strings.TrimSpace(fields[2])\r\n\t\t\t\t\tif newPid == ppid {\r\n\t\t\t\t\t\treturn uid, pid, cmd, nil\r","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/debug_unix.go#L43-L79","documentation":"On Unix, `getCmdMount` locates the JuiceFS mount process by running `ps -f -p <pid>` or `ps -ef | grep ... mount | grep <mp>` through `/bin/sh`. If `exec.Command(...).CombinedOutput()` returns an error (shell or ps cannot run, or ps exits non-zero), the command and error are wrapped with this message.","triggerScenarios":"Running `juicefs debug` on Unix when `/bin/sh` is missing, `ps` is not installed (e.g. minimal containers without procps), or `ps -f -p <pid>` fails because the pid vanished between listing and re-checking.","commonSituations":"Debugging inside a distroless/alpine container without `ps`; restricted seccomp blocking process exec; race where the mount process exits mid-debug.","solutions":["Install the `ps`/procps package in the container or debug from the host.","Ensure `/bin/sh` exists and is executable.","Re-run `juicefs debug`; a transient pid-exit race usually resolves on retry.","Check the wrapped `%v` error: 'executable file not found' means missing ps/sh; exit status 1 from `ps -f -p` means the pid no longer exists."],"exampleFix":"// before (minimal container)\n$ juicefs debug /jfs\nfailed to execute command `/bin/sh -c ps -ef ...`: exec: \"ps\": executable file not found\n// after\n$ apk add procps && juicefs debug /jfs","handlingStrategy":"validation","validationCode":"for _, bin := range []string{\"/bin/sh\", \"ps\"} {\n  if _, err := exec.LookPath(bin); err != nil {\n    return fmt.Errorf(\"%s missing; install procps\", bin)\n  }\n}","typeGuard":"null","tryCatchPattern":"err := runDebug(mp)\nif err != nil && strings.Contains(err.Error(), \"failed to execute command\") {\n  // 'executable file not found' -> install ps/sh; exit status -> retry (pid race)\n}","preventionTips":["Install procps/ps in minimal containers before debugging","Ensure /bin/sh exists and is executable","Retry once if the mount pid may have exited mid-scan"],"tags":["cli","process","exec"],"backgroundTag":"command-not-found","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}