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

parent fcd296ea
......@@ -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
......
// +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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment