Why do operating systems have an option to shut down?

10

3

Windows 98 shutdown screen
(source: ytimg.com)

I want to know why operating systems require us to shut down using an option. Why can't I just power off with a mechanical switch?

Will I damage the hardware or corrupt my data if I constantly shut down a computer without using the OS option?

To clarify: I want to use a Intel Compute Stick as a media player connected to a projector, so it will be controlled by an electrical switch. Computer will only have the video running and won't be installed programs. The computer won't have internet access.

IAmJulianAcosta

Posted 2016-03-09T21:41:11.433

Reputation: 903

Question was closed 2016-03-10T15:01:17.260

30What did your research tell you? A quick Google search for "why do i need to shutdown my computer instead of pulling the power" will find numerous answers... And yes, you can damage your hardware, but the risks are low, but there is a definitely a chance of corrupting or losing data. – acejavelin – 2016-03-09T21:47:51.407

1If your hardware supports this and the system you're working with is completely accessing any storage in read only mode and the system is not operating hardware that must be shut down with some procedure (e.g. some TV tuner cards, modems, ... ), then there's no problem just cutting the power. Such systems are ... rather hard to find, though. – Daniel Jour – 2016-03-10T01:08:01.520

@Bob why are those not duplicates of this? – phuclv – 2016-03-10T03:15:42.827

@LưuVĩnhPhúc Because of the added bit about the Compute Stick. Though none of the answers here directly address that. (e.g. Some machines, especially embedded ones, might be less unhappy about sudden power loss and are designed to cope with it.) – Bob – 2016-03-10T03:19:29.470

1

Older hardware was less tolerant of sudden power loss. But modern hardware is tolerant of sudden power loss. Desktop systems tend to require an orderly shutdown. Embedded systems can be tolerant of sudden power loss. Embedded Linux often uses JFFS2 and UBIFS filesystems; "Both UBI (see here) and UBIFS are tolerant to power-cuts, and they were designed with this property in mind.". Note that these are read/writeable filesystems.

– sawdust – 2016-03-10T04:08:28.620

@DanielJour --"Such systems are ... rather hard to find, though." -- Not really. There are a lot of TVs, especially the "smart" variety (e.g. Panasonic, LG), and set-top boxes that use Linux or Android (look for GPL disclosure in the owner's manual). They have no user interface for proper shutdown, yet they don't complain about dirty shutdown when started.. – sawdust – 2016-03-10T04:32:07.887

@sawdust Indeed. What I was trying to refer to is that's not as easy to find (pre-built) operating system (images) for such uses. I had to build such systems a while back ... was using a customised Linux distribution run from an (mostly) in-ram squashfs. Regarding TVs and other such customer hardware: Some of these have a small energy storage to keep the main system running until it does a clean shut down. (When you turn them on and off repeatedly, this battery cannot recharge .. ;) ) – Daniel Jour – 2016-03-10T08:21:35.217

1@DrZoo it was (still is) identical in XP if you run it on a system without an ATX power supply. I used to use some test kit with a standard XP pro PC built in. – Chris H – 2016-03-10T11:29:15.057

1The 3B2' s power switch was a double-throw momentary contact switch. Pressing it in the "off" direction didn't cut the power. Instead, it sent a SIGPWR signal to the Unix system's init process, which would initiate a clean shutdown followed by a power down. The only way to do a hard power down, in case the OS wasn't being cooperative, was to yank out the power cord. – Mark Plotnick – 2016-03-10T12:29:11.963

Since none of the questions are answering the bit about the Compute Stick and rehashing the same things about shutting down, this is a duplicate a few times over – random – 2016-03-10T15:01:59.500

Shouldn't this just be closed? It clearly wasn't researched in any way, and is a duplicate of several other questions.If the asker wants to ask his real question, he should edit the title and all to reflect that. – Fulluphigh – 2016-03-10T15:10:12.393

Answers

41

It depends on what is happening with the system at the time you chose to suddenly cut the power. If the system is busy writing important data and you cut the power, you could potentially damage data, or corrupt the OS. A lot of things are going on that you don't really see. You mostly have to worry about something software related breaking when you do a hard reset. As far as the hardware, you shouldn't encounter any problems. Knock on wood

You do not want to make a habit bypassing the shutdown method and cutting the power. It would just be a matter of time until something becomes corrupt and causes you to have to reinstall the OS.

In some cases, a hard reset is the only choice that you have. If your computer locks up and you can't get it to do anything what other option is there?

The origin of this screen is from Windows 9X Systems, where the message is displayed when Windows has successfully shut down to MS-DOS but is not configured to return to the prompt (COMMAND.COM) again. On systems with proper ACPI support and ATX power supply, the PC may power down instead.

In any situation where you're going to do a hard reset, be sure to shout "I am the lord of electricity!!! at your PC. Show it who's boss.

DrZoo

Posted 2016-03-09T21:41:11.433

Reputation: 8 101

26The last line... sadly it doesn't have the same feeling when it is a virtual machine – Burgi – 2016-03-09T23:13:45.447

14@Burgi "I am the baron of electricty!!!*" - fixed? – corsiKa – 2016-03-09T23:40:30.897

5@Burgi "I am the king of bits!!!" – hBy2Py – 2016-03-10T04:42:58.863

"The origin of this screen is from Windows 9X Systems" -- that refers to the picture in the question. To be clear, Win9x is not the origin of the process of shutting down a system. (As one example, it pre-existed in OS/2.) – TOOGAM – 2016-03-10T04:49:28.400

5As to the hardware, my understanding is that pulling the power will cause a hard drive to do an "emergency park". While this normally prevents the drive from being damaged, hard drives are rated for a much smaller number of emergency parks than of regular (commanded) parks, so the drive may wear out more quickly. – Nate Eldredge – 2016-03-10T05:02:10.303

6On a modern, journaled filesystem, you will not have to reinstall the OS under normal circumstances. But you could plausibly lose lots of application data that you thought you saved to disk. – Kevin – 2016-03-10T05:10:05.217

3Handy feminine alternative: "I am the empress of electricity! Cower before me!!!" – Qaz – 2016-03-10T06:18:30.007

@TOOGAM To be fair, in a way, it always existed. For example, before turning off your computer, you'd usually manually save your work (often to a floppy :)) and possibly also exit whatever application was running. OS/2 and Windows made it part of the user contract, because the user no longer has any idea about what's actually happening in the background right now - tons of new levels of caching, driver lags, background services and automatic saving... But in the end, it's still just the equivalent of pressing F2 to save before turning off your computer. – Luaan – 2016-03-10T09:39:04.077

@TOOGAM It looks like OS/2, at least of similar vintage as Windows 95, was designed to be safe to power off using the power switch only (scroll down to the bottom of the linked page). That doesn't necessarily mean any software running wasn't doing anything to the disk, for example, but that's unrelated to the operating system.

– a CVn – 2016-03-10T10:49:23.200

@TOOGAM https://youtu.be/8ucCxtgN6sc?t=7m43s :D

– BlueCacti – 2016-03-10T15:00:35.227

27

Computers are designed to be fast. That may include cheating. For instance, when a computer is supposed to write data, computers might store data in RAM instead of writing it to a hard drive. This is done because RAM is much faster.

Shutting down tells the computer to flush the buffers, meaning to stop storing stuff in RAM, and prepare for the system to lose electrical power. If you actually lose electrical power before making sure that all such data is properly written, you may lose data.

Part of the details of the filesystem volume's structure are handled by the operating system's filesystem-handling code (sometimes called the filesystem driver). Often, the filesystems use tables. (Visually, you can think of these like charts.) Imagine if you were writing out a multiplication table, and it said:
2 4 6 8 10 12 14 1

First of all, every column has just one row. Multiplication problems are supposed to have three parts (two numbers that are multiplied (the multiplicand and multiplier) and an answer (the product)). Here all we are seeing is a bunch of single numbers, so we don't even have one full example of a multiplication product. What we have is useless.

Second, what we have is actually worse than useless. Sometimes, the only thing worse than missing information (causing you to make no progress while you figure out the information you need) is trusted misleading information that causes you to spend resources to proceed in a useless, bad direction. In this case, you have invalid data towards the end: a one instead of a 16. (The idea here is that the chart stopped being updated suddenly, before the entire number "16" was noted properly.) If you don't let the computer complete its charts correctly, then that can cause confusion. (If the computer is told to update some data, and it should write to position number sixteen... you don't want it to write to position number one!) The computer relies on tables quite similar in nature to this. Shutting down tells the operating system to try to wrap things up neatly, instead of leaving jobs half-finished.

Another example is virtual memory. If a computer runs out of RAM, it can use space on a hard drive to keep track of details. For instance, maybe you have a fifty page document in a word processor. The computer is keeping track of the fact that the word processor is open, and keeps track of the first 12 pages, but the remaining 38 pages are stored on the hard drive, in what is called "virtual memory". When you shut down, the computer will go through the entire process of shutting down programs, which will free up some RAM, and eventually use the "virtual memory" to properly handle the word processor. If you simply lost electrical power, then the word processor stops running (because everything stops). Then, when the computer starts up, it sees the virtual memory has the data from the 38 pages of the document that was opened in a word processor. The computer doesn't even know that the data was being used by a word processor. Shutting down allows such things to be taken care of while the computer is able to keep track of these details.

Compared to Windows 95, MS-DOS was more resilient (less prone to problems) when it came to sudden power outages. (Some of that increased vulnerability was because of Windows 95's abilities to multitask and handle virtual memory.) So the computer's susceptibility to invalid shutdowns, or even if an official shutdown procedure is required at all, is based on which operating system is being used. Most modern operating systems are designed to rely on requiring a proper shutdown, because operating systems are easier to design with such a requirement. There's no reason that has to be the case, and in fact, some operating systems nanobsd do allow a person to just power it off. As one example, a page on nanobsd says "Everything is read-only at run-time — It is safe to pull the power-plug." As another example, resflash's home page has a bullet point saying "Power can be safely lost at any time." So there is no reason why absolutely shutdowns have to be a requirement that operating system designers impose when they create the design of an operating system. Shutting down is just simply a requirement that is quite common.

TOOGAM

Posted 2016-03-09T21:41:11.433

Reputation: 12 651

1"Then, when the computer starts up, it sees the virtual memory has the data from the 38 pages of the document that was opened in a word processor." - it won't care, it will treat this as garbage data and not use it until it's overwritten it. (Because what would you expect to be there? It's never going to be anything useful) – user253751 – 2016-03-10T03:24:55.577

1"it won't care, it will treat this as garbage" -- right. That's why my very next sentence (after the one you quoted) said, "The computer doesn't even know that the data was being used by a word processor." It lost track of that fact. – TOOGAM – 2016-03-10T04:38:07.073

What I mean is that that doesn't cause any problems. – user253751 – 2016-03-10T10:13:49.450

"Most modern operating systems are designed ... easier to design with such a requirement". IMO this is an oversimplification. We can avoid shutdowns, but at very expensive cost. No caching, no way for background processes (servers, backup managers, updates) to be notified. Also modern hardware is no more used with PIO but with DMA, you tell the HDD and NIC to read data from RAM and they notify you when done. What if the power got lost in between the HDD is writing from its cache to its plates? Let the OS decide how much to delay the shutdown. It knows better. – Margaret Bloom – 2016-03-10T11:27:58.870

5

In the days of MS-DOS, killing power to the computer would generally cause the loss of any information which was held in RAM but not stored on disk, but would not affect information stored on disk. The act of storing information on disk, however, will often render the old information unreadable at least slightly before the new version is readable. Loss of power between the time the old version is destroyed and the new version of written would leave one without any version of the information. If the information in question is something like a directory structure, that could large areas of the disk essentially inaccessible.

If one is using software which write information to disk only when explicitly asked to do so, then provided one doesn't kill power immediately after asking the system to write to disk one shouldn't accidentally clobber any information on disk. Modern systems, however, often have one or more tasks that may start writing information to disk at times the user doesn't necessarily expect. If the system happened to start writing some information just before the user killed power, that could result in disk corruption and data loss.

Part of the purpose of selecting "shutdown" is to eliminate the possibility of the system spontaneously starting any actions that write data to disk just as the user is about to kill power. Any actions which don't get triggered before the "You may now shut down your computer" message is shown can't get triggered until after the system is restarted, so there's no danger of something happening just as the user pulls the plug.

supercat

Posted 2016-03-09T21:41:11.433

Reputation: 1 649

1Even in the DOS days, it was a really bad idea. If a file had been updated but the FAT had not been updated, then you'd get a corrupted file. – Dewi Morgan – 2016-03-10T01:55:28.320

1@DewiMorgan: In the DOS days there were utilities available for write-back caching, but every standalone version of DOS I can remember used write-through caching as its normal behavior. What would one do otherwise to notify the system one wanted to shut down? – supercat – 2016-03-10T02:13:53.543

3@DewiMorgan: I know some old hard drives had head-park utilities, but those were pretty much obsolete well before Windows 95 replaced DOS. – supercat – 2016-03-10T02:41:31.893

1supercat: Nah, MS-DOS didn't do such caching unless you ran software to do that, such as the bundled SmartDrv. How you would notify that the system was to shut down is to use SmartDrv/C. (I believe the default behavior, regarding write caching, was different between MS-DOS 5.0 and 6.22... I don't offhand remember if it was the 5.0->6.0 upgrade or a later upgrade that made the change). If memory serves me right, one of the later upgrades (starting from 6 or later) caused SmartDrv to automatically do that before letting Command.Com show the prompt again, so safe to power off when at prompt – TOOGAM – 2016-03-10T04:43:23.243

1@Supercat As I understand it, write-through caching protects a single block of data from corruption during a write. It does not protect two different blocks (FAT and file contents) from falling out of synch if the power is cut between writing one and the other. – Dewi Morgan – 2016-03-10T05:31:34.797

@DewiMorgan: Write-through caching implies that when a write is requested, it will be performed immediately, but if a subsequent request is made to read the data the system will use a cached copy of the data that was just written, as opposed to reloading the data from the media. – supercat – 2016-03-10T05:40:45.820

@Supercat: How does that prevent powering off from corrupting/desynching a written file, and the FAT, where power is turned off between the write-through to the file, and the write-through to the FAT? And how does it prevent a four-block file from being corrupted if only the first two blocks have been written before power-off? Write-through is good, trading performance for reliability to avoid power-interruption issues when writing a single block. But it's not a disk corruption panacea. – Dewi Morgan – 2016-03-10T18:26:59.073

@DewiMorgan: If one hits "save", all of the writes will complete before control returns to the application. If the user waits until the application indicates that the save is complete before killing power, why would anything get corrupted? – supercat – 2016-03-11T01:40:56.247

@Supercat Ah, I finally understand: your point is "if there's nothing being written to disk when the disk is powered off, then it's safe"... even though you don't mention this important proviso in your answer. And yes, that's true... but it's also blatantly obvious, a banal truism of no value. Also, that writes only happened when someone hit save wasn't a safe assumption even on a machine with floppies and no hard drives. – Dewi Morgan – 2016-03-11T15:17:21.250

@DewiMorgan: My point was that older systems would only start writing to disk in response to application request, which would generally occur in response to direct user action; all one had to do to make sure the system didn't start writing to disk before shutting down was refrain from actions (like hitting "save") that would trigger a disk write. If there are background tasks that can write to disk, however, that's no longer true--a point I didn't see mentioned in any other answers. – supercat – 2016-03-11T16:03:04.553

@DewiMorgan: While write caching issues are important, I don't think systems would have enabled write-back caching if that would be the sole factor making it unsafe to power down the system when it was simply "idle". – supercat – 2016-03-11T16:08:09.147

4

There are two main reasons that computer systems need an orderly shutdown:

Application state

Many applications have state that must be written to permanent storage. The obvious example is a database server, but even read-mostly applications such as Web or NTP servers may write logs or statistics which may be unintelligible if a write is interrupted.

It may be possible to alleviate this problem if the applications in question don't read or write files directly, but perform these operations via a transactional mechanism such as writing to a relational database.

Filesystem structure

As the operating system writes files on behalf of the applications, writes may be buffered until the disks catch up, meaning that applications' writes don't necessarily complete until quite some time afterwards. Power saving mechanisms tend to increase the delay here, so you have a trade-off between energy consumption and data safety.

Whilst data are being written to disk, there are points where the filesystem data are inconsistent. Modern filesystem implementations take care to minimise the periods, but they can't be eliminated entirely. For example, when a block is taken from the free list, there is a short window where it is neither allocated nor free. This consistency problem is why after an unclean shutdown, an OS will need to perform a filesystem check on the next boot, to examine all blocks and ensure they are correctly accounted for.

Journalling filesystems alleviate this to some extent, by recording intended changes into a log before actually performing them. Then the filesystem check can run much faster, by replaying all the complete log entries and discarding incomplete ones.

Filesystem consistency issues can be avoided by not having local disks, and NFS-mounting the root filesystem, but the loss of cached writes is still a problem for these systems. The only systems I'm willing to hard power-off without shutdown are those that have the disks mounted read-only (mostly embedded systems such as my Empeg Car music player, but also a couple of disk less web-browsing terminals I have lying around for visitors).

TL;DR

Data writes to permanent storage must be completed before power-off. If you have no writeable storage, then removing the power is low risk.

Toby Speight

Posted 2016-03-09T21:41:11.433

Reputation: 4 090

-1

because if some descriptor file is open it can corrupt a important file and leave the OS dead

Ricardo Luna

Posted 2016-03-09T21:41:11.433

Reputation: 11

15

Welcome to Super User. A common mistake new users make is to answer without details of how to actually resolves the issue. Answers should be detailed and include references, as needed. Please take a few minutes to edit your answer to include details of why your answer is valid. If you need some help, read How do I write a good answer?.

– CharlieRB – 2016-03-09T21:56:00.553