What happens during OS shutdown?

I hope this is related to programming.

What exactly happens during the shutdown process of the operating system, let's take Linux here as open source, and there may be more about that.

  • (How) are core threads terminated?
  • Does the power supply cut off (captain obviously) when the computer is in a "clear" state? What I mean with clear state is that nothing else happens on the CPU, etc.

  • Why do most operating systems take so long to stop? I mean, they don't need to initialize anything or even load resources into memory.

  • Why are operating systems not like "Hey, never mind, let's just terminate all processes, just turn off the power after finishing"?

+2


source to share


4 answers


  • Well, sometimes the OS just pulls the plug. Give the "reload" the correct control arguments and splat.

  • What if changes to a file are stored in memory and not flushed to disk? You can get them first.

  • What if some daemon process goes through some tricky file update? You might want him to finish.

  • What if the daemons need to be told something else on the network that they are leaving in order to arrange an orderly departure?

To deal with all of this, operating systems have orderly shutdown procedures. On linux, you can observe how no sausages are applied by looking at /etc/rcN.d, for N = 0,1,2,3,4.



Symbolic links starting with "K" are the breakout process.

One way or another, at the end of the process, on modern hardware, the operating system turns off power. Of course it depends on the hardware.

+7


source


The latest version of Mac OS X, Show Leopard, actually does something pretty interesting: Applications must remain in a "stable" state where they can be terminated without warning. If this is not the case (while writing to disk), they have to tell the OS. Then, when you ask it to shutdown and all applications are in a "stable" state, the OS really just pulls the plug (after the obvious hardware shutdown is done, like writing all dirty pages to disk, the hard drive stops and parked, etc.).



Another reason most OSs sometimes take a long time to stop is this: you probably have a lot of applications that have not been used for a while and have therefore been replaced. To close them completely, the OS sends them a completion message. But in order for them to react to this and exit safely, they need to be swapped again. And this happens simultaneously with the fact that the disk is busy with other processes, writing their data to it ...

+4


source


  • Does the power supply cut off (captain obviously) when the computer is in a "clear" state? What I mean with clear state is that nothing else happens on the CPU, etc.

Once all processes are stopped and the file systems are unloaded, the kernel will send an ACPI signal to the BIOS, which will power down.

  • Why do most operating systems take so long to stop? I mean, they don't need to initialize anything or even load resources into memory.

When shutting down, many applications must store their current state in the file system for future executions, and the file system must flush changes from RAM to hard drive.

  • Why are operating systems not like "Hey, never mind, let's just terminate all processes, just turn off the power after finishing"?

Because you run the risk that applications do not store their data correctly and even damage their data. Even if this is not a problem, data may be incorrectly deleted from the file system cache to the hard disk, resulting in file system inconsistency.

You can read the recent EXT 4 / KDE 4 debacle where EXT 4 flushed file metadata down to file contents on disk and KDE 4 read, writing tons of small files in bursts. If you encounter a hard disconnect while writing, all your config files will be corrupted / FUBAR.

+3


source


I believe the OS calls ACPI or similar power management functions to execute the final shutdown command. If the computer does not support this, Linux will simply stop running and all networks will be disconnected.

The reason for the sudden power outage is as follows:

  • Some hardware needs to be turned off cleanly - for example. hard disk parking.
  • The user may have unsaved data - it is better to ask all applications to close.
0


source







All Articles