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

# 监听操作系统信号

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

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
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={"theme":{"light":"github-light","dark":"dracula"}}
process.on("beforeExit", code => {
  console.log(`事件循环已空！`);
});

process.on("exit", code => {
  console.log(`进程以代码 ${code} 退出`);
});
```

***

更多实用工具请参见 [文档 > API > 工具](/runtime/utils)。
