Resolve cyclic import and create a common helper func, NumProcs()
This commit is contained in:
parent
fcd296ea11
commit
a3f57b1314
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue