/usr/share/gocode/src/github.com/cloudfoundry/gosigar/examples/ps.go is in golang-github-cloudfoundry-gosigar-dev 0.0~git20150402.27.3ed7c74-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // Copyright (c) 2012 VMware, Inc.
package main
import (
"fmt"
"github.com/cloudfoundry/gosigar"
)
func main() {
pids := sigar.ProcList{}
pids.Get()
// ps -eo pid,ppid,stime,time,rss,state,comm
fmt.Print(" PID PPID STIME TIME RSS S COMMAND\n")
for _, pid := range pids.List {
state := sigar.ProcState{}
mem := sigar.ProcMem{}
time := sigar.ProcTime{}
if err := state.Get(pid); err != nil {
continue
}
if err := mem.Get(pid); err != nil {
continue
}
if err := time.Get(pid); err != nil {
continue
}
fmt.Printf("%5d %5d %s %s %6d %c %s\n",
pid, state.Ppid,
time.FormatStartTime(), time.FormatTotal(),
mem.Resident/1024, state.State, state.Name)
}
}
|