Resolve cyclic import and create a common helper func, NumProcs()

This commit is contained in:
Sean Chittenden 2016-07-11 14:05:30 -04:00
parent fcd296ea11
commit a3f57b1314
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
2 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -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
}