> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 监听操作系统信号

Bun 支持 Node.js 的 `process` 全局对象，包括用于监听操作系统信号的 `process.on()` 方法。

```ts theme={null}
process.on("SIGINT", () => {
  console.log("收到 SIGINT");
});
```

***

如果你不确定要监听哪个信号，可以监听 [`"beforeExit"`](https://nodejs.org/api/process.html#event-beforeexit) 和 [`"exit"`](https://nodejs.org/api/process.html#event-exit) 事件。

```ts theme={null}
process.on("beforeExit", code => {
  console.log(`事件循环已清空！`);
});

process.on("exit", code => {
  console.log(`进程正在退出，退出码为 ${code}`);
});
```

***

参见 [工具](/runtime/utils) 了解更多实用工具。
