Merge pull request #330 from LK4D4/recursive_pids
Get PIDs from cgroups recursively
This commit is contained in:
commit
2bec85d74b
|
@ -213,7 +213,7 @@ func (m *Manager) GetPids() ([]int, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return cgroups.ReadProcsFile(dir)
|
||||
return cgroups.GetPids(dir)
|
||||
}
|
||||
|
||||
func getCgroupData(c *configs.Cgroup, pid int) (*data, error) {
|
||||
|
|
|
@ -411,12 +411,11 @@ func (m *Manager) Freeze(state configs.FreezerState) error {
|
|||
}
|
||||
|
||||
func (m *Manager) GetPids() ([]int, error) {
|
||||
path, err := getSubsystemPath(m.Cgroups, "cpu")
|
||||
path, err := getSubsystemPath(m.Cgroups, "devices")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cgroups.ReadProcsFile(path)
|
||||
return cgroups.GetPids(path)
|
||||
}
|
||||
|
||||
func (m *Manager) GetStats() (*cgroups.Stats, error) {
|
||||
|
|
|
@ -193,7 +193,7 @@ func GetInitCgroupDir(subsystem string) (string, error) {
|
|||
return getControllerPath(subsystem, cgroups)
|
||||
}
|
||||
|
||||
func ReadProcsFile(dir string) ([]int, error) {
|
||||
func readProcsFile(dir string) ([]int, error) {
|
||||
f, err := os.Open(filepath.Join(dir, "cgroup.procs"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -322,3 +322,29 @@ func GetHugePageSize() ([]string, error) {
|
|||
|
||||
return pageSizes, nil
|
||||
}
|
||||
|
||||
// GetPids returns all pids, that were added to cgroup at path and to all its
|
||||
// subcgroups.
|
||||
func GetPids(path string) ([]int, error) {
|
||||
var pids []int
|
||||
// collect pids from all sub-cgroups
|
||||
err := filepath.Walk(path, func(p string, info os.FileInfo, iErr error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
dir, file := filepath.Split(p)
|
||||
if file == "cgroup.procs" {
|
||||
if iErr != nil {
|
||||
return iErr
|
||||
}
|
||||
cPids, err := readProcsFile(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pids = append(pids, cPids...)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return pids, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue