-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (64 loc) · 1.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"fmt"
"os"
"github.com/hellojukay/proc/cmdline"
"github.com/hellojukay/proc/environ"
"github.com/hellojukay/proc/fd"
"github.com/hellojukay/proc/network"
)
var (
enableEnv = false
enableNet = false
enableFile = false
enableCmd = false
pid = 0
)
func init() {
flag.BoolVar(&enableEnv, "e", false, "show process environment list")
flag.BoolVar(&enableNet, "n", false, "show process network connection infomation")
flag.BoolVar(&enableCmd, "c", false, "show process command line")
flag.BoolVar(&enableFile, "f", false, "list process open files")
flag.IntVar(&pid, "p", 1, "process pid")
flag.Parse()
}
func main() {
if enableEnv {
m, err := environ.GetEnv(pid)
if err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
}
environ.PrintEnv(m)
fmt.Print("\n")
}
if enableCmd {
c, err := cmdline.GetCmdLine(pid)
if err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
}
cmdline.PrintCmdLine(c)
fmt.Print("\n")
}
if enableFile {
files, err := fd.ReadFd(pid)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
for _, file := range files {
fmt.Printf("%-5s%-s\n", file.Fd, file.Link)
}
}
if enableNet {
netInfos, err := network.ReadNetInfo(pid)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
network.PrintNetInfo(netInfos)
fmt.Print("\n")
}
}