getProcPids returns the list of running PIDs, /proc or /proc/ /task/ .
(pidsPath string)
| 85 | |
| 86 | // getProcPids returns the list of running PIDs, /proc or /proc/<pid>/task/ . |
| 87 | func getProcPids(pidsPath string) []int { |
| 88 | f, err := os.Open(pidsPath) |
| 89 | if err != nil { |
| 90 | return []int{} |
| 91 | } |
| 92 | ls, err := f.Readdir(-1) |
| 93 | f.Close() |
| 94 | if err != nil { |
| 95 | return []int{} |
| 96 | } |
| 97 | ls = sortPidsByTime(ls) |
| 98 | |
| 99 | pidList := make([]int, 0, len(ls)) |
| 100 | for _, f := range ls { |
| 101 | if f.IsDir() == false { |
| 102 | continue |
| 103 | } |
| 104 | if pid, err := strconv.Atoi(f.Name()); err == nil { |
| 105 | pidList = append(pidList, []int{pid}...) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return pidList |
| 110 | } |