use first-class funcs to fill Process information.

pull/4/head
Shirou WAKAYAMA 11 years ago
parent 1ecf1a011b
commit 19f52ebbf6

@ -16,29 +16,25 @@ const (
PRIO_PROCESS = 0 // linux/resource.h
)
type fillFunc func(pid int32, p *Process) (error)
func NewProcess(pid int32) (*Process, error) {
p := &Process{
Pid: int32(pid),
}
// Fill Process information from fillFuncs
var wg sync.WaitGroup
wg.Add(4)
go func() {
funcs := []fillFunc{fillFromStat, fillFromStatus, fillFromfd, fillFromCmdline}
wg.Add(len(funcs))
for _, f := range funcs{
go func(){
wg.Done()
fillFromStat(pid, p)
}()
go func() {
defer wg.Done()
fillFromStatus(pid, p)
}()
go func() {
defer wg.Done()
go fillFromfd(pid, p)
}()
go func() {
defer wg.Done()
go fillFromCmdline(pid, p)
f(pid, p)
}()
}
wg.Wait()
/*

Loading…
Cancel
Save