...
1
2
3 package main
4
5 import (
6 "fmt"
7 "os"
8 "text/tabwriter"
9
10 "github.com/Microsoft/hcsshim/internal/appargs"
11 "github.com/Microsoft/hcsshim/internal/shimdiag"
12 "github.com/urfave/cli"
13 )
14
15 var listCommand = cli.Command{
16 Name: "list",
17 Usage: "Lists running shims",
18 ArgsUsage: "[flags]",
19 Flags: []cli.Flag{
20 cli.BoolFlag{
21 Name: "pids",
22 Usage: "Shows the process IDs of each shim",
23 },
24 },
25 Before: appargs.Validate(),
26 Action: func(ctx *cli.Context) error {
27 pids := ctx.Bool("pids")
28 shims, err := shimdiag.FindShims("")
29 if err != nil {
30 return err
31 }
32
33 w := new(tabwriter.Writer)
34 w.Init(os.Stdout, 0, 8, 0, '\t', 0)
35
36 if pids {
37 fmt.Fprintln(w, "Shim \t Pid")
38 }
39
40 for _, shim := range shims {
41 if pids {
42 pid, err := getPid(shim)
43 if err != nil {
44 return err
45 }
46 fmt.Fprintf(w, "%s \t %d\n", shim, pid)
47 } else {
48 fmt.Fprintln(w, shim)
49 }
50 }
51 w.Flush()
52 return nil
53 },
54 }
55
View as plain text