I am using EXWM on Arch as my windows manager. Substantially my startx launches exec dbus-launch --exit-with-session emacs so I am running only emacs and living inside it. I would like to define a function shutdown to properly handle the shutdown of my computer terminating every process in a graceful way. This function has to:

  1. Execute (save-some-buffers)
  2. Check in every frame if there are running processes that I've personally started
  3. Ask if I want to continue
  4. Send SIGHUP to each of these process
  5. Check if those process have quit, if not send them a stronger signal
  6. Exit emacs
  7. Shutdown the computer

I want to kill processes with SIGHUP, which is the signal (kill-buffer) sends, because using (save-buffer-kill-emacs) kills them too brutally. For example Chromium always asks me if I want to restore previous session, whereas killing Chromium with SIGHUP makes it restore the correct session the next time I start it. I want to properly quit emacs before shutting down the computer because if I use (shell-command "shutdown now") it prevents emacs to correctly run every exit-hook (for example it doesn't remove the desktop-file.lock of (desktop-save-mode). My workaround for this problem is to schedule a shutdown 3 seconds in the future, so emacs can properly quit, but it is not very elegant.

How can I do?

  • Any reason you can't just add an exit-hook that runs (shell-command "shutdown now") between steps 5 and 6? – Jack Jan 10 '17 at 21:25
  • That could be a solution, but I have to be sure that there aren't any hooks after the one that runs shutdown now – sbozzolo Jan 11 '17 at 16:12
  • With (add-hook 'kill-emacs-hook '(shell-command "shutdown now")) the command is executed as first. How can I rearrange the order? – sbozzolo Jan 12 '17 at 11:46
  • 1
    do (add-hook 'kill-emacs-hook '(shell-command "shutdown now") t) instead. the t is an optional argument for "append" – Jack Jan 12 '17 at 19:32
  • Now it's working as expected. And how can I change the signal I send to processes? – sbozzolo Jan 14 '17 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.