From: Tom Hromatka Date: Mon, 17 May 2021 14:15:59 +0000 (+0000) Subject: cgroup.py: Add method to get pids in a cgroup X-Git-Tag: v2.0.3~11^2^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a1671cb2eb4d1e6b973b93856c317fec319e037;p=thirdparty%2Flibcgroup.git cgroup.py: Add method to get pids in a cgroup Add a method, get_pids_in_cgroup(), that will return the pids in a given cgroup. Signed-off-by: Tom Hromatka --- diff --git a/ftests/cgroup.py b/ftests/cgroup.py index 32b9530e..dd9f0aff 100644 --- a/ftests/cgroup.py +++ b/ftests/cgroup.py @@ -814,3 +814,19 @@ class Cgroup(object): return config.container.run(cmd, shell_bool=True) else: return Run.run(cmd, shell_bool=True) + + @staticmethod + def get_pids_in_cgroup(config, cgroup, controller): + mounts = Cgroup.get_cgroup_mounts(config) + + for mount in mounts: + if mount.controller == controller: + proc_file = os.path.join(mount.mount_point, cgroup, "cgroup.procs") + cmd = ['cat', proc_file] + + if config.args.container: + return config.container.run(cmd, shell_bool=True) + else: + return Run.run(cmd, shell_bool=True) + + return None