Saturday, May 19, 2012

Shut Down Process Explained

I always wonder what is my computer doing when it takes long time to shut down? Incidentally I found a brief good explanation on reddit.

Just in case you're too lazy to click the link, I copied down the answer here:

The computer does many things when you shut down. This post is going to cover as many as I can think of.

One of the simplest and most important has to do with memory. The computer has to insure that anything that needs to be written to disk, is written to disk. If you don't do this, you could end up with corrupt or invalid files. If you want more detail than that, you're going to have to take a few years of computer science at a college level.

Your computer also runs some updates that cannot be run during operation, either because they directly involve the kernel, or a critical part of run time operations. Usually if your PC is taking forever to shut down, it's because these updates either a) take long or b) have messed up. Sometimes this can cause your PC to hang during shutdown.

Another thing your computer is doing is prepping itself for the next boot cycle. People like operating systems that can start really fast. So a way to get a computer to do this is to prepare a boot sector with information about what your computer tends to do on boot. Often the changes here are small ones. Information about what was used, how it was used, and what problems occurred are stored here.

Like I started to say with the last point, flags are set depending on problems your computer might have had during its last runtime. If you notice windows always has to "un-set" a flag that tells the PC to run chkdsk (check disk) on boot. This is because if your computer experiences a hard shutdown, you might have invalid files on disk. So your computer has to run the check disk operation. This flag is set to true on boot, and during a proper shutdown is set to false. There are many such flags.

If you have a RAID array, a proper shutdown is very important. RAID arrays, especially ones that require parity calculations (i.e. RAID 5) write to disk very slowly. To compensate for this DMA, or Direct Memory Access, is heavily utilized. This isn't the only time when DMA is used, but it is much greater than other instances. So when you copy a file onto your RAID 5 array, it doesn't directly move into the RAID array. Instead it is moved into system RAM, or a RAM module on your RAID chipset. Once it has been moved here, the RAID Chipset microprocessor will begin to move it to disk, performing the parity calculations for each individual bit. Even though the file has appeared to the user as being moved, it might not actually be valid on the disk yet. (Same explanation for the first point) When you do a regular shutdown of the PC, the computer will wait for the parity calculations to complete. If you perform a hard shutdown, the RAM will lose power and all the data that was still being moved to the RAID array will be lost. You'll often notice that expensive RAID cards (i.e. Intel) will come with an optional battery to keep the on-board RAM module powered in case of a hard shutdown. Your every-day home computer doesn't have this battery, and if you force a shutdown you'll lose the data.

Your computer will not shut down until all processes have terminated, and given their termination codes. Basically telling the OS that they have terminated with such and such final state. This is why sometimes your computer won't shut down until you've saved a document, or answered a prompt. A soft shutdown has a lower interrupt priority than some of these prompts. So the processes will wait until these prompts have been answered, before tending to the interrupt from the OS.

The last things I can think of are all small housecleaning tasks. Update the registry, change values in whatever system records system is being used.

That's pretty much all I can think of.

tl;dr The majority of what it's waiting for is memory to be validated, and updates.

Addition from another answer:

Writing to disk is slow. Writing to memory is fast. Sometimes the computer delays writing to disc and keeps things in memory to save time. When you shut down, it will have to write to disk the things it has been avoiding writing to disk.

It does this because a piece of data may change several times. If you write to disk every time it would be slow. So instead you keep it in memory and update that, and only write to disk when you have to.

Comments :

0 comments to “Shut Down Process Explained”


Published by COMPUTER STUFF supported by DVD Writer USB