2

When you shut down a macOS system, it asks applications to exit one by one, and the system will not shut down unless all applications agree to exit (aka. there is no unsaved work) or until they are manually forced to exit.

When you shut down a Windows system, it gives you a grace period when you can see which apps are refusing to close. If it reminds you that you didn't save something, you can stop the shutdown during this grace period.

However, when you shut down a Linux system through the window manager, whether KDE or Gnome, it instantly shows a black screen, killing every process without checking if they're saved.

A lot of my work has been lost because of the lack of saving prompts during shutdown. Can I configure something on Linux that will show me unsaved applications before shutting down?

1 Answers1

2

Like the comments said, the shutdown script in Linux is designed to power off without checking for other running apps (and it has its benefits that way). If you really want to do some checks before powering off the machine, you need to write your own script to do it. For example, something like this:

#!/usr/bin/env bash

Applications to check before shutting down

apps='(nvim.*|calcurse|aerc)' # add your apps here

ps -eo pid,cmd | grep -E "[0-9]+ $apps" | while read pid process; do echo -n "$process is still running. Kill it? [Y/n] " read -r yn </dev/tty if [[ $yn =~ ^[Yy]?$ ]]; then kill $pid else exit 1 fi done && systemctl poweroff

This script retrieves all the running processes, matches them against the apps defined by apps, then prompts you to kill them. If you enter no to any of them, it exits immediately. Otherwise, it shuts down the system.

Put this file in your $PATH and make an alias to execute it when you run your normal shutdown command. For example, instead of running shutdown, add this to your bash aliases:

alias shutdown='my_shutdown_script.sh'

You can do the same thing with reboot too. Just modify the script to take an argument/flag. You get the idea :)

Edit: If (neo)vim is the only app you'd like to check, I recommend looking into mksession