> ## Documentation Index
> Fetch the complete documentation index at: https://bun-1dd33a4e-farm-de84d354-pm-sbom.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Listen to OS signals

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

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
process.on("SIGINT", () => {
  console.log("Received SIGINT");
});
```

***

To run code when the process exits, listen for the [`"beforeExit"`](https://nodejs.org/api/process.html#event-beforeexit) event, emitted when the event loop empties, and the [`"exit"`](https://nodejs.org/api/process.html#event-exit) event, emitted when the event loop empties or `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 theme={"theme":{"light":"github-light","dark":"dracula"}}
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.
