diff --git a/man/runc-ps.8.md b/man/runc-ps.8.md index 694990a9..d6063471 100644 --- a/man/runc-ps.8.md +++ b/man/runc-ps.8.md @@ -2,7 +2,7 @@ runc ps - ps displays the processes running inside a container # SYNOPSIS - runc ps [command options] [ps options] + runc ps [command options] [-- ps options] # OPTIONS --format value, -f value select one of: table(default) or json diff --git a/ps.go b/ps.go index 3b462a0a..af261836 100644 --- a/ps.go +++ b/ps.go @@ -16,7 +16,7 @@ import ( var psCommand = cli.Command{ Name: "ps", Usage: "ps displays the processes running inside a container", - ArgsUsage: ` [ps options]`, + ArgsUsage: ` [-- ps options]`, Flags: []cli.Flag{ cli.StringFlag{ Name: "format, f", @@ -42,12 +42,21 @@ var psCommand = cli.Command{ return nil } - psArgs := context.Args().Get(1) - if psArgs == "" { - psArgs = "-ef" + // [1:] is to remove command name, ex: + // context.Args(): [containet_id ps_arg1 ps_arg2 ...] + // psArgs: [ps_arg1 ps_arg2 ...] + // + psArgs := context.Args()[1:] + + if len(psArgs) > 0 && psArgs[0] == "--" { + psArgs = psArgs[1:] } - output, err := exec.Command("ps", strings.Split(psArgs, " ")...).Output() + if len(psArgs) == 0 { + psArgs = []string{"-ef"} + } + + output, err := exec.Command("ps", psArgs...).Output() if err != nil { return err }