mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
42 lines
915 B
Plaintext
42 lines
915 B
Plaintext
---
|
|
title: Listen to OS signals
|
|
sidebarTitle: OS signals
|
|
mode: center
|
|
---
|
|
|
|
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");
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
If you don't know which signal to listen for, you listen to the umbrella `"exit"` event.
|
|
|
|
```ts
|
|
process.on("exit", code => {
|
|
console.log(`Process exited with code ${code}`);
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
If you don't know which signal to listen for, you listen to the [`"beforeExit"`](https://nodejs.org/api/process.html#event-beforeexit) and [`"exit"`](https://nodejs.org/api/process.html#event-exit) events.
|
|
|
|
```ts
|
|
process.on("beforeExit", code => {
|
|
console.log(`Event loop is empty!`);
|
|
});
|
|
|
|
process.on("exit", code => {
|
|
console.log(`Process is exiting with code ${code}`);
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
See [Docs > API > Utils](/runtime/utils) for more useful utilities.
|