MCPcopy Create free account
hub / github.com/MertJSX/folderhost / getChildPIDs

Function getChildPIDs

utils/service_utils/ram_management.go:92–134  ·  view source on GitHub ↗
(pid int)

Source from the content-addressed store, hash-verified

90}
91
92func getChildPIDs(pid int) []int {
93 var children []int
94
95 if runtime.GOOS == "linux" {
96 files, _ := os.ReadDir("/proc")
97 for _, f := range files {
98 if !f.IsDir() {
99 continue
100 }
101 p, err := strconv.Atoi(f.Name())
102 if err != nil {
103 continue
104 }
105
106 data, _ := os.ReadFile(fmt.Sprintf("/proc/%d/status", p))
107 for _, line := range strings.Split(string(data), "\n") {
108 if strings.HasPrefix(line, "PPid:") {
109 fields := strings.Fields(line)
110 if len(fields) >= 2 {
111 ppid, _ := strconv.Atoi(fields[1])
112 if ppid == pid {
113 children = append(children, p)
114 }
115 }
116 break
117 }
118 }
119 }
120 }
121
122 if runtime.GOOS == "darwin" {
123 cmd := exec.Command("pgrep", "-P", strconv.Itoa(pid))
124 out, _ := cmd.Output()
125 for _, line := range strings.Split(string(out), "\n") {
126 p, _ := strconv.Atoi(strings.TrimSpace(line))
127 if p > 0 {
128 children = append(children, p)
129 }
130 }
131 }
132
133 return children
134}
135
136func (sm *ServiceManager) GetAllServicesRAM() map[string]int64 {
137 sm.Mu.RLock()

Callers 1

getProcessTreeRAMFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected