Debian Codegraph @

examples/ps.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5
6 "github.com/cloudfoundry/gosigar"
7 )
8
9 func main() {
10 pids := sigar.ProcList{}
11 pids.Get()
12
13 // ps -eo pid,ppid,stime,time,rss,state,comm
14 fmt.Print(" PID PPID STIME TIME RSS S COMMAND\n")
15
16 for _, pid := range pids.List {
17 state := sigar.ProcState{}
18 mem := sigar.ProcMem{}
19 time := sigar.ProcTime{}
20
21 if err := state.Get(pid); err != nil {
22 continue
23 }
24 if err := mem.Get(pid); err != nil {
25 continue
26 }
27 if err := time.Get(pid); err != nil {
28 continue
29 }
30
31 fmt.Printf("%5d %5d %s %s %6d %c %s\n",
32 pid, state.Ppid,
33 time.FormatStartTime(), time.FormatTotal(),
34 mem.Resident/1024, state.State, state.Name)
35 }
36 }