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:
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() {
|
||||
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)
|
||||
}()
|
||||
funcs := []fillFunc{fillFromStat, fillFromStatus, fillFromfd, fillFromCmdline}
|
||||
|
||||
wg.Add(len(funcs))
|
||||
for _, f := range funcs{
|
||||
go func(){
|
||||
wg.Done()
|
||||
f(pid, p)
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user