From f524e7f8c7c3b2af65bd08399c6f19527865957d Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Fri, 7 Oct 2016 14:04:43 +0200 Subject: [PATCH] cgroups.7: Add some details to discussion of cgroup.procs file Signed-off-by: Michael Kerrisk --- man7/cgroups.7 | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/man7/cgroups.7 b/man7/cgroups.7 index 12ebbd30d..13d50fa19 100644 --- a/man7/cgroups.7 +++ b/man7/cgroups.7 @@ -236,20 +236,37 @@ A new cgroup is created by creating a directory in the cgroup filesystem: mkdir /sys/fs/cgroup/cpu/cg1 This creates a new empty cgroup. -Processes may be moved to this cgroup by writing -their PIDs into the cgroup's + +A process may be moved to this cgroup by writing its PID into the cgroup's .I cgroup.procs file: echo $$ > /sys/fs/cgroup/cpu/cg1/cgroup.procs -The same file can be read to obtain a list of the processes -that are currently in -.IR cg1 . +Only one PID at a time should be written to this file. + +Writing the value 0 to a +.IR cgroup.procs +file causes the writing process to be moved to the corresponding cgroup. + When writing a PID into the .IR cgroup.procs , all threads in the process are moved into the new cgroup at once. +Within a hierarchy, a process can be a member of exactly one cgroup. +Writing a process's PID to a +.IR cgroup.procs +file automatically removes it from the cgroup of +which it was previously a member. + +The +.I cgroup.procs +file can be read to obtain a list of the processes that are +members of a cgroup. +The returned list of PIDs is not guaranteed to be in order. +Nor is it guaranteed to be free of duplicates. +(For example, a PID may be recycled while reading from the list.) + In cgroups v1 (but not cgroups v2), an individual thread can be moved to another cgroup by writing its thread ID (i.e., the kernel thread ID returned by