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?
The signals which are mentioned in the manuals are:
USR2 get the most attention, as you can customize the
effects of these. The following excerpts provide the details:
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.
-- 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.
‘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 example: (defun sigusr-handler () (interactive) (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 itself: (signal-process (emacs-pid) 'sigusr1)
To handle a SIGUSR1 signal, define an interactive function, and bind it to the ‘signal usr1’ event sequence:
(defun usr1-handler () (interactive) (message "Got USR1 signal")) (global-set-key [signal usr1] 'usr1-handler)
TERM are all relevant to the
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 below.
TSTP signal is mentioned in passing in