8.3.3 Kernel Control Groups (cgroups)
On a traditional SysV init system it is not always possible to clearly assign a process
to the service that spawned it. Some services such as Apache, spawn a lot of 3rd party
processes (e.g. CGI or Java processes), which themselves spawn more processes. This
makes a clear assignment difcult or even impossible. Additionally, a service may not
terminate correctly, leaving some of its children alive.
systemd solves this problem by placing each service into its own cgroup. cgroups
are a Kernel feature that allows aggregating processes and all their children into hierar-
chical organized groups. systemd names each cgroup after its service. Since a non-
privileged process it not allowed to “leave” its cgroup, this provides an effective way
to label all processes spawned by a service with the name of the service.
To list all processes belonging to a service, use the command systemd-cgls. The
result will look like the following (shortened) example:
Example 8.3:
List all Processes Belonging to a Service
~ # systemd-cgls --no-pager
user
root
1
2279 sshd: root@pts/0
2282 -bash
2541 systemd-cgls --no-pager
system
1 /sbin/init splash showopts
apache2.service
2535 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf -D SYSTEMD -k
start
2536 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf -D SYSTEMD -k
start
2537 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf -D SYSTEMD -k
start
2538 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf -D SYSTEMD -k
start
2539 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf -D SYSTEMD -k
start
2540 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf -D SYSTEMD -k
start
xdm.service
2250 /usr/bin/xdm
2253 /usr/bin/X -nolisten tcp -br vt7 -auth
/var/lib/xdm/authdir/authfiles/A:0-ii8Goo
2263 -:0
2276 /usr/bin/xconsole -notify -nostdin -verbose -exitOnFail
The systemd daemon 151