summaryrefslogtreecommitdiff
path: root/devdocs/elisp/killing-emacs.html
blob: 242152b60071f69bfaedb7f4e8a4ff10697472ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 <h4 class="subsection">Killing Emacs</h4>  <p>Killing Emacs means ending the execution of the Emacs process. If you started Emacs from a terminal, the parent process normally resumes control. The low-level primitive for killing Emacs is <code>kill-emacs</code>. </p> <dl> <dt id="kill-emacs">Command: <strong>kill-emacs</strong> <em>&amp;optional exit-data</em>
</dt> <dd>
<p>This command calls the hook <code>kill-emacs-hook</code>, then exits the Emacs process and kills it. </p> <p>If <var>exit-data</var> is an integer, that is used as the exit status of the Emacs process. (This is useful primarily in batch operation; see <a href="batch-mode">Batch Mode</a>.) </p> <p>If <var>exit-data</var> is a string, its contents are stuffed into the terminal input buffer so that the shell (or whatever program next reads input) can read them. </p> <p>If <var>exit-data</var> is neither an integer nor a string, or is omitted, that means to use the (system-specific) exit status which indicates successful program termination. </p>
</dd>
</dl>     <p>The <code>kill-emacs</code> function is normally called via the higher-level command <kbd>C-x C-c</kbd> (<code>save-buffers-kill-terminal</code>). See <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Exiting.html#Exiting">Exiting</a> in <cite>The GNU Emacs Manual</cite>. It is also called automatically if Emacs receives a <code>SIGTERM</code> or <code>SIGHUP</code> operating system signal (e.g., when the controlling terminal is disconnected), or if it receives a <code>SIGINT</code> signal while running in batch mode (see <a href="batch-mode">Batch Mode</a>). </p> <dl> <dt id="kill-emacs-hook">Variable: <strong>kill-emacs-hook</strong>
</dt> <dd>
<p>This normal hook is run by <code>kill-emacs</code>, before it kills Emacs. </p> <p>Because <code>kill-emacs</code> can be called in situations where user interaction is impossible (e.g., when the terminal is disconnected), functions on this hook should not attempt to interact with the user. If you want to interact with the user when Emacs is shutting down, use <code>kill-emacs-query-functions</code>, described below. </p>
</dd>
</dl> <p>When Emacs is killed, all the information in the Emacs process, aside from files that have been saved, is lost. Because killing Emacs inadvertently can lose a lot of work, the <code>save-buffers-kill-terminal</code> command queries for confirmation if you have buffers that need saving or subprocesses that are running. It also runs the abnormal hook <code>kill-emacs-query-functions</code>: </p> <dl> <dt id="kill-emacs-query-functions">User Option: <strong>kill-emacs-query-functions</strong>
</dt> <dd><p>When <code>save-buffers-kill-terminal</code> is killing Emacs, it calls the functions in this hook, after asking the standard questions and before calling <code>kill-emacs</code>. The functions are called in order of appearance, with no arguments. Each function can ask for additional confirmation from the user. If any of them returns <code>nil</code>, <code>save-buffers-kill-emacs</code> does not kill Emacs, and does not run the remaining functions in this hook. Calling <code>kill-emacs</code> directly does not run this hook. </p></dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Killing-Emacs.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Killing-Emacs.html</a>
  </p>
</div>