I'd like to know how GNU Emacs responds, by defaults, to such signals as HUP and USR1. Is this behavior documented in any manual? If so, where? If not, is there a place I could look in the source code?

1 Answer 1


The signals which are mentioned in the manuals are: SIGHUP, SIGINT, SIGTERM, SIGTSTP, SIGUSR1, SIGUSR2

USR1 and USR2 get the most attention, as you can customize the effects of these. The following excerpts provide the details:

C-hig (emacs)Checklist:

If you cannot get Emacs to respond to ‘C-g’ (e.g., because ‘inhibit-quit’ is set), then you can try sending the signal specified by ‘debug-on-event’ (default SIGUSR2) from outside Emacs to cause it to enter the debugger.

C-hig (elisp)Error Debugging:

-- User Option: debug-on-event If you set ‘debug-on-event’ to a special event (*note Special Events::), Emacs will try to enter the debugger as soon as it receives this event, bypassing ‘special-event-map’. At present, the only supported values correspond to the signals ‘SIGUSR1’ and ‘SIGUSR2’ (this is the default). This can be helpful when ‘inhibit-quit’ is set and Emacs is not otherwise responding.

C-hig (elisp)Misc Events:

‘sigusr1’ ‘sigusr2’ These events are generated when the Emacs process receives the signals ‘SIGUSR1’ and ‘SIGUSR2’. They contain no additional data because signals do not carry additional information. They can be useful for debugging (*note Error Debugging::).

 To catch a user signal, bind the corresponding event to an
 interactive command in the ‘special-event-map’ (*note Active
 Keymaps::).  The command is called with no arguments, and the
 specific signal event is available in ‘last-input-event’.  For

      (defun sigusr-handler ()
        (message "Caught signal %S" last-input-event))

      (define-key special-event-map [sigusr1] 'sigusr-handler)

 To test the signal handler, you can make Emacs send a signal to

      (signal-process (emacs-pid) 'sigusr1)

C-hig (elisp)Event Examples:

To handle a SIGUSR1 signal, define an interactive function, and bind it to the ‘signal usr1’ event sequence:

 (defun usr1-handler ()
   (message "Got USR1 signal"))
 (global-set-key [signal usr1] 'usr1-handler)

In addition, HUP, INT, and TERM are all relevant to the kill-emacs function:

C-hig (elisp)Killing Emacs:

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::).

-- Variable: kill-emacs-hook This normal hook is run by ‘kill-emacs’, before it kills Emacs.

 Because ‘kill-emacs’ 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 ‘kill-emacs-query-functions’, described

The TSTP signal is mentioned in passing in (elisp)Suspending Emacs.

  • For anyone else following this unfamiliar with the info system, you will need to go to the relevant entry, in parentheses, and then find the correct sub-heading. Jan 30, 2023 at 22:37
  • The key sequence that I included before (almost) every node enables you to jump to a named info node directly, from anywhere (or if you're already in an info buffer then just g is sufficient). If you use that, there's no need to "find" anything manually (unless any of the node names I used are no longer valid; and notwithstanding that browsing the info manuals manually isn't a bad idea in general :).
    – phils
    Jan 31, 2023 at 0:34
  • That said, the very best thing you can do if you're unfamiliar with using the info reader is to type C-h i t and work through the excellent info tutorial -- you'll learn lots of extremely useful things by doing that.
    – phils
    Jan 31, 2023 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.