# Listen to OS signals (/guides/process/os-signals)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 236 · updated: 2026-09-23 -->
Related: [Parse command-line arguments](/guides/process/argv.md), [Listen for CTRL+C](/guides/process/ctrl-c.md), [Spawn a child process and communicate using IPC](/guides/process/ipc.md), [Get the process uptime in nanoseconds](/guides/process/nanoseconds.md), [Read stderr from a child process](/guides/process/spawn-stderr.md), [Read stdout from a child process](/guides/process/spawn-stdout.md)

Bun supports the Node.js `process` global, including the `process.on()` method for listening to OS signals.

```ts
process.on("SIGINT", () => {
  console.log("Received SIGINT");
});
```

***

To run code when the process exits, listen for these events:

* [`"beforeExit"`](https://nodejs.org/api/process.html#event-beforeexit): Bun emits this event when the event loop empties.
* [`"exit"`](https://nodejs.org/api/process.html#event-exit): Bun emits this event when the event loop empties or when `process.exit()` is called.

Neither event is emitted when the process is killed by a signal it has no listener for. To run cleanup on a signal, listen for that signal and call `process.exit()` from the listener.

```ts
process.on("beforeExit", code => {
  console.log(`Event loop is empty!`);
});

process.on("exit", code => {
  console.log(`Process is exiting with code ${code}`);
});
```

***

See [Utils](/runtime/utils) for more utilities.
