$ ps -p 1 -o comm=systemd$ systemdPID 1PID 1234PID 1240hello.pyLinux kernel[Unit]Description=Hello service[Service]ExecStart=python3 /opt/hello.pyRestart=on-failure[Install]WantedBy=multi-user.targetwants/… python3[1234]: hello… python3[1234]: hello… python3[1240]: hellodaemon-reloadstartstatusSIGKILLenablestopSIGTERM
Back: user space (terminal, systemd, the service). Middle: the Linux kernelFront: files on disk (the unit file, the boot links folder, the journal)Tokens: commands, start sparks, signals, log lines and a boot linkUser space at the back: the terminal, systemd (process 1) and the hello service. The Linux kernel in the middle. Files on disk in front: the unit file, the boot links folder and the journal. systemd reads the unit file, starts the service through the kernel, sends its output to the journal, starts it again after a crash, links it in for every boot, and stops it when asked. The PIDs 1234 and 1240 are examples. Your machine picks its own numbers, and the journal lines start with the date and the computer's name, cut to "…" here.

systemd and unit files

  1. When Linux boots, the kernel starts one program first, as process 1. On Debian, Ubuntu, Fedora and most other distributions that is systemd. It starts the services, programs that run in the background, and watches them. ps -p 1 shows it.

Running a service

Crashes, boot and stop

What happens

;; step 1/10 · pid1
kernel   boots, then starts /sbin/init as process 1 (PID 1)
         on systemd systems /sbin/init is systemd
systemd  the service manager: starts, watches and stops
         services (programs with no window, in the background)
$ ps -p 1 -o comm=
systemd

The PIDs 1234 and 1240 are examples. Your machine picks its own numbers, and the journal lines start with the date and the computer's name, cut to "…" here. kill -9 is a last resort: the process cannot save its work or tidy up. To restart a service on purpose, use sudo systemctl restart hello instead.