1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

use first-class funcs to fill Process information.

This commit is contained in:
Shirou WAKAYAMA 2014-04-24 18:41:46 +09:00
parent 1ecf1a011b
commit 19f52ebbf6

View File

@ -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.Done() wg.Add(len(funcs))
fillFromStat(pid, p) for _, f := range funcs{
}() go func(){
go func() { wg.Done()
defer wg.Done() f(pid, p)
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()
/* /*