use first-class funcs to fill Process information.

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

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

Loading…
Cancel
Save