diff --git a/host/host_linux.go b/host/host_linux.go index e485ef4..6d5ece4 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -17,7 +17,6 @@ import ( "github.com/shirou/gopsutil/internal/common" common "github.com/shirou/gopsutil/internal/common" - "github.com/shirou/gopsutil/process" ) type LSB struct { @@ -59,9 +58,8 @@ func Info() (*InfoStat, error) { ret.Uptime = uptime(boot) } - procs, err := process.Pids() - if err == nil { - ret.Procs = uint64(len(procs)) + if numProcs, err := common.NumProcs(); err == nil { + ret.Procs = numProcs } return ret, nil diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 0a122e9..b3df722 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -1,3 +1,19 @@ // +build linux package common + +import "os" + +func NumProcs() (uint64, error) { + f, err := os.Open(HostProc()) + if err != nil { + return 0, err + } + + list, err := f.Readdir(-1) + defer f.Close() + if err != nil { + return 0, err + } + return uint64(len(list)), error +}