Besides your commands, other programs are running on the machine all the time: they were started without you. This step covers who starts them and how a program differs from a process.
A program is a file on disk: uname, for example, lives in /usr/bin/uname. Until it is started, it does nothing. A running program is a process: it has a number, its own memory, and a running time. One program can run as several processes at once.
The uname process lives for a fraction of a second: it prints the kernel release and exits. The shell is a process too, and it keeps running as long as the terminal is open. ps lists the processes of your terminal:
The list shows the bash shell and ps itself: while it was printing the list, it was running as well.
The other processes started when the machine booted, without you. Many of them are services: programs that run in the background and wait for work, such as requests to a website. Services are managed by systemd: it starts them at boot, restarts them after a crash, and stops them on command. A service needs no terminal.
nginx is this machine's web server. The output active means the service is running.
systemctl is-active nginx printed active. You close the terminal tab. What happens to the website?
-
Logging in does not touch the service: systemd started it when the machine booted, and it runs whether you are logged in or not. Right after login
systemctl is-active nginxprintsactive. -
systemd started nginx at boot; the terminal had nothing to do with it. Open the terminal again and
systemctl is-active nginxprintsactive. -
systemd starts the service; your shell never started it. What ends with the shell are programs still running in this terminal.
systemd started nginx at boot, and the service needs no terminal: the site works even when nobody is logged in. A systemd command or a crash can stop it — you check that with the same systemctl is-active nginx.
Key points
- A program is a file on disk; a process is a running copy of it with its own number.
- A service runs in the background with no terminal, and systemd starts and stops it.