Node.JS:查看进程为何仍在运行的工具? [英] Node.JS: Tool to see why process is still running?
问题描述
是否有办法查看哪些超时,间隔或异步操作(或无穷循环)仍在运行,并且正在阻止进程结束?
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?
到目前为止,即使没有这样的工具,我也能弄清楚,但是这样的工具非常方便,尤其是当这里的Node.JS项目开始变得越来越大时.
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.
我正在考虑Java的kill -3
,它将打印堆栈跟踪信息到stderr.您可以在任何时间,任何调试或否的情况下针对任何进程执行此操作.我想要一个等效的Node.JS. (我知道该节点是异步的单线程,因此它的输出会有所不同)
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)
推荐答案
模块为什么- 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 () {
这篇关于Node.JS:查看进程为何仍在运行的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!