The man page for scope says:
Unlike service units, scope units manage externally created processes, and do not fork off processes on its own.
On my RHEL server, I can see that gdm belongs to the gdm service. So does its child, gdm-simple-slave. gdm-simple-slave has created gdm-session-worker, but this process belongs to a scope, not the gdm service.
In light of this, what does "externally created process" mean, and what is the difference between a service and a scope?
For those readers who prefer code:
# systemctl status gdm
gdm.service - GNOME Display Manager
Loaded: loaded (/usr/lib/systemd/system/gdm.service; enabled)
Active: active (running) since Sun 2018-03-04 16:27:45 EST; 1 day 3h ago
Process: 1330 ExecStartPost=/bin/bash -c TERM=linux /usr/bin/clear > /dev/tty1 (code=exited, status=0/SUCCESS)
Main PID: 1307 (gdm)
CGroup: /system.slice/gdm.service
├─1307 /usr/sbin/gdm
├─1331 /usr/libexec/gdm-simple-slave --display-i...
└─1364 /usr/bin/Xorg :0 -background none -verbos...
# ps -ef|grep 1331
root 1331 1307 0 Mar04 ? 00:00:00 /usr/libexec/gdm-simple-slave...
root 2032 1331 0 Mar04 ? 00:00:00 gdm-session-worker ...
# systemctl status 2032
session-38.scope - Session 38 of user root
Loaded: loaded (/run/systemd/system/session-38.scope; static)
Drop-In: /run/systemd/system/session-38.scope.d
└─90-After-systemd-logind\x2eservice.conf, 90-After-systemd-user-sessions\x2eservice.conf, 90-Description.conf, 90-SendSIGHUP.conf, 90-Slice.conf
Active: active (running) since Sun 2018-03-04 21:12:08 EST; 22h ago
An externally created process is a process that was spawned by a process other than the systemd daemon running as PID 1.
For both a scope and a service, systemd will create the cgroups to allow you to manage the processes inside it as a whole. (For example, you can use
systemctl stop
to stop a scope and kill all processes inside it.)But with a service, systemd has the command-line to run and will run it in that environment.
With gdm-session-worker, for instance, that is not really possible, since it's supposed to be spawn by gdm-simple-slave... So in order to still keep a separate session for each gdm-session-worker, gdm will still communicate with systemd to ask it to create a new scope and then create that gdm-session-worker in that new scope.
I hope this answers your question... You have already found the systemd scope man page. If you want a more technical deep dive onto the API you might want to look into the New Control Group Interfaces, though perhaps an easier way to try it is using the
systemd-run --scope
command.