add support to kill container process by pid

This adds support for signalling a container process by pid.

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>

make Ps more extensible

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>

ps: windows support

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett
2017-05-09 15:50:02 -04:00
parent fae11b6673
commit ef158f8b5e
14 changed files with 1523 additions and 145 deletions

58
cmd/ctr/ps.go Normal file
View File

@@ -0,0 +1,58 @@
package main
import (
gocontext "context"
"fmt"
"os"
"text/tabwriter"
"github.com/containerd/containerd/api/services/execution"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
var psCommand = cli.Command{
Name: "ps",
Usage: "list processes for container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "id",
Usage: "id of the container",
},
},
Action: func(context *cli.Context) error {
id := context.String("id")
if id == "" {
return errors.New("container id must be provided")
}
psRequest := &execution.PsRequest{
ID: id,
}
containers, err := getExecutionService(context)
if err != nil {
return err
}
resp, err := containers.Ps(gocontext.Background(), psRequest)
if err != nil {
return err
}
w := tabwriter.NewWriter(os.Stdout, 10, 1, 3, ' ', 0)
fmt.Fprintln(w, "PID")
for _, ps := range resp.Ps {
if _, err := fmt.Fprintf(w, "%d\n",
ps.Pid,
); err != nil {
return err
}
if err := w.Flush(); err != nil {
return err
}
}
return nil
},
}