Skip to content

Commit beb3d83

Browse files
authored
Merge pull request #4 from struCoder/dev
feat(dev): fix proc type when there is no pid
2 parents 8b46c6a + 5e29cda commit beb3d83

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pidusage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ func stat(pid int, statType string) (*SysInfo, error) {
103103

104104
procStatFileBytes, err := ioutil.ReadFile(path.Join("/proc", strconv.Itoa(pid), "stat"))
105105
splitAfter := strings.SplitAfter(string(procStatFileBytes), ")")
106-
if len(splitAfter) == 0 {
106+
107+
if len(splitAfter) == 0 || len(splitAfter) == 1 {
107108
return sysInfo, errors.New("can not foud this pid: " + strconv.Itoa(pid))
108109
}
109110
infos := strings.Split(splitAfter[1], " ")

0 commit comments

Comments
 (0)