# signal

> Register POSIX signal handlers (SIGINT, SIGTERM, etc.) with callback functions.

# 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

| Function | Signature | Description |
| --- | --- | --- |
| `on` | `signal.on(name: string, fn: function) → bool` | Register `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 |
| `off` | `signal.off(name: string) → bool` | Remove 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

```goost
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")
```