Cgroup

How to see the cgroup of a process

Learn how to find the control group (cgroup) of a process by using /proc, pidof, or ps.

Summary

The control group of a process can be retrieved from the /proc directory. We only need to know the PID of the process, which can be found using ps or pidof.

Usage

If we know that our PID is 1234, then showing the cgroup is as easy as using cat to see the contents of the ‘cgroup’ file.

How to see cgroup in ps output

Want to see the control group in the output of the ps command? Here is how to tune your command options to include that.

Summary

The ps command can show the control group of a process using the -o option, followed by the right column names.

Usage

To show processes and the control group, we can filter the output columns.

# ps -e -o pid,cgroup:64,args
    PID CGROUP                                                           COMMAND
      1 0::/init.scope                                                   /lib/systemd/systemd --system --deserialize 58
      2 -                                                                [kthreadd]
      3 -                                                                [rcu_gp]
<snip>
    576 -                                                                [xprtiod]
    634 0::/system.slice/dbus.service                                    @dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
    640 0::/system.slice/networkd-dispatcher.service                     /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
    645 -                                                                [nfsiod]
    653 0::/system.slice/systemd-logind.service                          /lib/systemd/systemd-logind
    696 0::/system.slice/system-getty.slice/getty@tty1.service           /sbin/agetty -o -p -- \u --noclear tty1 linux

In this example the PID is displayed, with the control group, and the command with its arguments. By specifying the width of 64 characters, we can properly see the full name of the control group.