I hope this is programming-related enough.
What exactly happens during the shutdown process of an Operating-System, let’s take Linux here as its open-source and there may be more knowledge around about this.
- (How) are the kernel threads terminated?
-
Does the power-supply stop supplying power (captain obvious) when the computer is in a “clear” state? What I mean with clear state is that there isn’t anything going on in the CPU anymore, etc.
-
Why do most operating systems take so long to shutdown? I mean hey, they don’t need to initialize something or even load resources into memory.
-
Why don’t operating systems go like “Hey, nevermind – let’s just terminate all the processes end just turn the power off”?
Well, sometimes the OS does just pull the plug. Give ‘reboot’ the right control arguments, and splat.
What if modifications to a file are in memory and not flushed to disk? You might want to get them out first.
What if some daemon process is partway through some complex update of a file? You might want it to finish.
What if a daemon needs to tell something else on the network that it is going away to arrange an orderly departure?
To deal with all of these, operating systems have orderly shutdown procedures. On linux, you can watch the sausages being unmade by looking in /etc/rcN.d, for N=0,1,2,3,4.
The symbolic links that begin with ‘K’ are the shutdown process.
One way or the other, at the end of the process, on modern hardware, the operating system turns off the power. What that means depends, of course, on the hardware.