-3

Gilles wrote an excellent reply about how Linux kernel shuts down at https://unix.stackexchange.com/a/122667/674

I was wondering how Linux OS shuts down (in cases of both systemvinit and systemd)? I am expecting something similar to the boot sequence of Linux OS. I am particularly wondering how the processes notify each other, by some signal like SIGTERM and SIGKILL, or some other interprocess communication way?

Thanks.

Related:

What is the difference between "when the operating system shuts down" and "when the kernel shuts down"?

When the operating system shuts down, how does a service manager know that it should sends SIGTERM and SIGKILL to its services?

closed as too broad by Scott, Mr Shunz, RalfFriedl, DarkHeart, Stephen Harris Dec 20 '18 at 0:51

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Maybe at a high level with only critical parts? – Tim Dec 18 '18 at 14:59
  • Don't be afraid. Since you mentioned it, I would refrain myself from doing so. – Tim Dec 18 '18 at 15:01
4

With both sysvinit and systemd, shutting the operating system down starts by notifying the init process (the process with pid 1) that the system should shut down (or reboot, or power off).

sysvinit does this by using the /run/initctl FIFO to communicate with init, asking it to switch to the corresponding runlevel. See the init manpage for a brief overview.

systemd supports a variety of ways to do this. Various signals can be used to request a shutdown, reboot, etc., in various flavours; it’s also possible to request this over d-bus (the busctl manpage explains how to explore that).

Once pid 1 has been asked to shut down, it follows its configuration and specification and goes through all the appropriate steps for it. This typically includes notifying all users that a shutdown is in progress, shutting down all the running services (in a managed way with systemd; using shutdown scripts in various forms with sysvinit), syncing the mounted file systems, possibly unmounting them, killing all remaining processes (with the usual TERM then KILL sequence), and finally calling the kernel’s reboot system call with the appropriate parameters.

This describes the general sequence. There are many more twists to all this, including access control (with Polkit), various available hooks, kexec, sudden power-off handling, CtrlAltDel handling... The systemd documentation covers many of these details.

  • Thanks. In manpages.debian.org/stretch/sysvinit-core/…, init also reacts to some signals. Does that mean we can communicate with init by sending some signals instead of using FIFO, asking it to switch to the corresponding runlevel? – Tim Dec 19 '18 at 2:06
  • /run/initctl is FIFO not socket. Let me know if I am wrong. – Tim Dec 19 '18 at 3:43
  • You can use certain signals to communicate with sysvinit’s init, but none of them are relevant here. You can’t use them to request an arbitrary runlevel change. – Stephen Kitt Dec 19 '18 at 5:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.