signal

Register callback functions to run when the process receives a POSIX signal — useful for graceful shutdown and config reloads. Import it with import signal.

Functions

FunctionSignatureDescription
onsignal.on(name: string, fn: function) → boolRegister fn() as a handler for the named signal; multiple handlers on the same signal fire in registration order on each delivery. Returns false if the name is unknown
offsignal.off(name: string) → boolRemove all handlers for that signal and stop watching it. Returns true if any were removed

Recognized names (case-sensitive): SIGINT (also int, interrupt), SIGTERM (term), SIGHUP (hup), SIGUSR1 (usr1), SIGUSR2 (usr2), SIGQUIT (quit), SIGPIPE (pipe), SIGCHLD (chld).

Example

import signal

// graceful shutdown on Ctrl-C or kill
signal.on("SIGINT", fn() {
  print("shutting down...")
})

// reload config on SIGHUP
signal.on("SIGHUP", fn() {
  print("reloading config")
})

// stop listening for a signal
signal.off("SIGHUP")
Standard library · View as Markdown · llms-full.txt