Bun Listen to OS signals

Listen to OS signals

jarle Updated

File contents

Listen to OS signals

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

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

If you don't know which signal to listen for, you listen to the "beforeExit" and "exit" events.

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 for more useful utilities.

jarle/bun-skills/tree/main/skills/bun-guides-process-os-signals commit b5b755138a

Frequently asked questions

npx skillmds@latest add jarle/bun-listen-to-os-signals