Is there a "safe shutdown" like on Windows?

I’ll ask again. What makes you think however you’re currently powering off your computer is doing so abruptly or unsafely?? Stop avoiding the question.

2 Likes

Truth be told, poweroff (but also XFCEs shutdown button which behaves exactly like poweroff) seems a bit brutal. I sometimes have VMs started and plenty of heavy and not so heavy apps running. Poweroff just kills everything in 1 to 2s. Sometimes video artifacts show on screen for a second or so. I have asked myself this question, if it’s actually safe, as in if there’s not some zeroes and ones hanging somewhere in some pipe somewhere that never make it to SSD.

In what way? The poweroff or shutdown commands won’t cause any filesystem corruption, if that is what you’re afraid of. It will send the terminate signal to all running processes or kill them if they do not obey. It will also close all open file streams, and unmount all filesystems, and when it’s done, it will power off the computer.

Whether an application saves its state to the drive is dependent on the application. Some will, some won’t, so if you have any unsaved work, it may not get written and thus be lost. That said, your filesystem will be safely unmounted and there will be no corruption to anything written on the drive.

1 Like

Yeah, system corruption is what I mean by not safe.

There are no poweroff commands that will cause filesystem corruption. The only way to try and have that happen is to yank the power cable (and even then, journaling filesystems are reasonably resilient).

OP still hasn’t defined what “safe shutdown” is, or why they think it’s not happening, and I’d really like to hear about that.

4 Likes

Same as what Kresimir said - system won’t corrupt. (running shutdown in the terminal is my standard way)

But it doesn’t seem like applications get a “peaceful” close signal. With firefox, if there were tabs open, they are restored on next boot, which certainly means firefox wasn’t given the usual “close” signal. Instead, some form of “kill” or “terminate” signal was passed.

Yeah, I rather like that. I guess it’s a reminiscence from my Windows days that will be with me forever. I hated how windows was making itself busy and letting me know when it was safe to shutdown. So I like how nothing can escape the almighty shutdown, and all that killing happens instantly :slight_smile: I think I’ve recently read somewhere you’re supposed to close all your applications before shutdown. Some Linux tut i can’t remember where. (I was like: “aint nobody got time for that”)

There is no need to do so, but as I’ve said above, different applications may handle interrupts differently. Some will save their state to the drive and gracefully exit when they receive the terminate signal (SIGTERM), some won’t. And some will outright disobey the terminate signal and will have to be killed (with SIGKILL, which does not give them any chance to save their state).

So, it depends on what your desired outcome is.


On KDE Plasma, there is a also “save session” option that makes the window manager remember all running applications before terminating them so that they can be launched on the next startup (trying to restore their state, if possible). It will also run any scripts you may have in ~/.config/plasma-workspace/shutdown/. This won’t happen if you shut down with the shutdown or poweroff commands.

If you’re interested in knowing how to shut down your computer from the terminal emulator on KDE Plasma in a way that is equivalent to using the GUI, read this post:

1 Like

Almost to 30 posts. If this gets to 35 and we still haven’t had clarification of this from post 1, I officially dub thee a help vampire for wasting everyone’s time with a made up problem.

2 Likes

Well, it’s not his fault we are chatting. He’s been gone for 35 minutes :slight_smile:

We’ll see what he replies when he comes back, before we condemn him to garlic and sunlight. In the meantime, we can get to 100 posts easily…

:vampire:t3:

3 Likes

They’ve already replied 5x since the question was proposed. It’s been asked at least 3x so far by two people. . .

1 Like

This is a problem, as OP will miss the question he needs to answer.

In this sort of situation I’d normally set a timer to re-open the thread in 30 minutes or an hour or so…

1 Like

Or we can remind him if he doesn’t read the entire thread (which he should, it’s his thread, I read all the posts in any threads I start).

Besides, it’s not a big deal if he doesn’t reply, I think we’ve covered pretty much everything interesting regarding shutdown anyway…

4 Likes

You probably got a notification about me quoting your post. (At least with the default notification settings) :wink:

Hopefully OP also has such notifications, that they click on.

(They’ve been quoted multiple times)

He might be referencing the slow shutdown that windows do that closes the services and stops when applications are prompted to be saved or taking time to close themselves.

Windows shutdown kind of write the last status of the system onto the disk so it can do a “fast boot next time”.

There are a lot of things happening during the shutdown process. Here are just a few examples:

  • Checking to see if any user applications have not been closed yet (like an unsaved document) and prompt the user if necessary
  • Stopping background services
  • Waiting for the termination signal from services and applications that are open or running
  • Flushing the cache to disk
  • Writing log files
  • All users are logged out
  • Ending the shell
  • Start installing Windows updates and tell the system to finish the update process during the next system start-up if necessary
  • Send the ACPI shutdown signal (this is what turns the machine off)

Source if needed.

Linux shutdown process.

  1. Go through reboot_notifier_list, which is a list of hooks that kernel components can register to execute code on power-down. Only a few drivers need to execute code at this stage, mostly watchdogs.
  2. Set the system_state variable.
  3. Disable usermode-helper, to ensure that no user code will be started anymore. (There can still be existing processes at this stage.)
  4. Call device_shutdown to release or power down all devices on the system. A lot of drivers hook into this stage.
    Note that any filesystems that are still mounted at this point are effectively forcibly unmounted. The caller of the system call takes responsibility for any clean unmounting.
  5. For power off only, if ACPI is configured in, possibly execute code to prepare going into ACPI state S5 (soft power off).
  6. In a multi-CPU machine, the code could be running on any CPU, whichever invoked the system call. migrate_to_reboot_cpu takes care to switch to one particular CPU and prevent the scheduler from dispatching code on other CPUs. After this point, only a single CPU is running.
  7. syscore_shutdown calls the shutdown method of registered syscore operations. I think this is mostly about disabling interrupts; few hooks have a shutdown method.
  8. Log an information message — the swan’s song.
  9. Finally go to rest in some machine-dependent way by calling machine_restart, machine_halt or machine_power_off.

Source if needed.

Like Windows Linux also do a graceful shutdown it’s faster because it doesn’t wait for disk read writes. And there are very few background services that need to be stopped in a Linux system.

I personally don’t think Linux shutdown is disruptive or damages anything it’s just faster and it’s for me a is a true shutdown compared to what Windows does.

2 Likes

safe + windows in same sentence ! pure sacrilege.

2 Likes

When all else fails…pull the :electric_plug: :rofl:

Thanks, but I like the speed. I want everything to dissolve into nothing in a blink of an eye. Don’t care at all to restore my sessions. Heck my sessions get so chaotic, sometimes after I finish a complex project I restart just to get everything back to zero. Sometimes this sends a murder message to the Windows VM, oh well, I can’t wait for windows to do its “graceful” get back into your box routine :slight_smile:

1 Like

You know the old Windows saying …when yer back up fails … and it will. Re-install!