2

here and here, they discuss how shuting down emacs deamon gracefully. Why is it important? One of the answers suggested pkill -TERM emacs, which does the job but apparently not gracefully. What is the problem with not shuting down emacs daemon gracefully? what can happen if I don't do it?

Thanks

Schach21
  • 412
  • 4
  • 21
  • I think it may be important to keep updated recent opened files list (or updated emacs history file) – david Apr 25 '20 at 18:07

1 Answers1

1

One of the answers suggested pkill -TERM emacs, which does the job but apparently not gracefully.

Notwithstanding that I would recommend using the process ID rather than pkill, that should be a graceful shut-down. The manual says:

The ‘kill-emacs’ function is normally called via the higher-level command ‘C-x C-c’ (‘save-buffers-kill-terminal’). *Note (emacs)Exiting::. It is also called automatically if Emacs receives a ‘SIGTERM’ or ‘SIGHUP’ operating system signal (e.g., when the controlling terminal is disconnected), or if it receives a ‘SIGINT’ signal while running in batch mode (*note Batch Mode::).

This behaviour was introduced in Emacs 24.1 (which post-dates the Q&A you've linked to).

** Exiting changes

*** Emacs now calls `kill-emacs' if it receives SIGTERM or SIGHUP, or if it receives a SIGINT signal in batch mode.

*** `kill-emacs-hook' is now also run in batch mode. Third-party code which adds to `kill-emacs-hook' should check if they do the right thing in batch mode.


As to why you wouldn't want a non-graceful shutdown, that's not really an Emacs question. Killing processes without allowing them any chance to clean up should always be a last resort. It's not difficult to imagine the problems which might result if a process was killed in the middle of writing a file, for instance.

phils
  • 71,335
  • 11
  • 153
  • 198