MCPcopy
hub / github.com/evilsocket/opensnitch / getProcPids

Function getProcPids

daemon/procmon/find.go:87–110  ·  view source on GitHub ↗

getProcPids returns the list of running PIDs, /proc or /proc/ /task/ .

(pidsPath string)

Source from the content-addressed store, hash-verified

85
86// getProcPids returns the list of running PIDs, /proc or /proc/<pid>/task/ .
87func 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}

Callers 3

lookupPidInProcFunction · 0.85
TestGetProcPidsFunction · 0.85
BenchmarkGetProcsFunction · 0.85

Calls 4

sortPidsByTimeFunction · 0.85
CloseMethod · 0.65
NameMethod · 0.65
OpenMethod · 0.45

Tested by 2

TestGetProcPidsFunction · 0.68
BenchmarkGetProcsFunction · 0.68