Node.JS:查看进程为何仍在运行的工具?

发布于 2024-11-05 20:57:55 字数 257 浏览 0 评论 0原文

有没有办法查看哪些超时、间隔或异步操作(或无限循环)仍在运行并阻止我的进程结束?

到目前为止,我已经能够在没有这样的工具的情况下解决这个问题,但是这样的工具会非常方便,尤其是当这里的 Node.JS 项目开始变得更大时。

我正在考虑 Java 的 kill -3 ,它将堆栈跟踪打印到 stderr。您可以在任何时间对任何进程执行此操作,无论调试与否。我想要 Node.JS 的等效版本。 (我知道节点是异步单线程的,所以它的输出会有所不同)

Is there a way to see what timeouts, intervals or async operations (or endless loops) are still running and are stopping my process from ending?

I have been able to figure it out so far without such a tool, but such a tool would be very handy especially as the Node.JS projects here start to get bigger.

I am thinking of Java's kill -3 which prints a stack trace to stderr. You can do this for any process, any time, debug or no. I would like an equivalent for Node.JS. (I know that node is single threaded with async so it would output differently)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习惯成性 2024-11-12 20:57:55

模块 why-is-node-running 正是您所需要的。

 var log = require('why-is-node-running')
 setTimeout(function () {
   log() // logs out active handles that are keeping node running
 }, 100)

输出类似于:

There are 4 known handle(s) keeping the process running and 0 unknown
Known handles:
# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:6  - setInterval(function () {}, 1000)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()

# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () {

The module why-is-node-running is exactly the thing you need.

 var log = require('why-is-node-running')
 setTimeout(function () {
   log() // logs out active handles that are keeping node running
 }, 100)

And the output is something like:

There are 4 known handle(s) keeping the process running and 0 unknown
Known handles:
# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:6  - setInterval(function () {}, 1000)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()

# TCP
/Users/maf/dev/node_modules/why-is-node-running/example.js:7  - server.listen(0)
/Users/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()

# Timer
/Users/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文