import os def get_cpuset_info(cgroup_path): """Retrieves cpuset information for a given cgroup path.""" info = {} files_to_check = [ 'cpuset.cpus', 'cpuset.mems', 'cpuset.cpus.effective', 'cpuset.mems.effective', 'cpuset.cpus.exclusive', 'cpuset.cpus.exclusive.effective', 'cpuset.cpus.partition' ] for filename in files_to_check: filepath = os.path.join(cgroup_path, filename) if os.path.exists(filepath) and os.access(filepath, os.R_OK): try: with open(filepath, 'r') as f: info[filename] = f.read().strip() except Exception as e: info[filename] = f"Error reading: {e}" # else: # info[filename] = "Not found or not readable" # Uncomment if you want to explicitly show missing files return info def main(): cgroup_root = '/sys/fs/cgroup' print(f"Recursively retrieving cpuset information from {cgroup_root} (cgroup v2):\n") for dirpath, dirnames, filenames in os.walk(cgroup_root): # Skip the root cgroup directory itself if it's not a delegate # and only process subdirectories that might have cpuset info. # This is a heuristic; if you want to see info for the root too, remove this if. # if dirpath == cgroup_root: # continue cpuset_info = get_cpuset_info(dirpath) if cpuset_info: # Only print if we found some cpuset information print(f"Cgroup: {dirpath.replace(cgroup_root, '') or '/'}") for key, value in cpuset_info.items(): print(f" {key}: {value}") print("-" * 30) # Separator for readability if __name__ == "__main__": main()