这里有很多帖子(例如 https://unix.stackexchange.com/questions/217507/zombies-in-bash )展示了如何在 bash 或 c 中创建僵尸进程。我想知道是否有办法在 Nodejs 中创建它们,所以当我这样做时 ps ax | grep node
,有一行的命令部分是 node <defunct>
.
非常感谢。
最佳答案
回答我自己的问题,以防对任何人有帮助。事实证明,在 Node 中做到这一点非常容易。运行以下脚本后,您可以执行 ps ax | grep node
您应该会看到一个带有 [node] <defunct>
的条目.
var cp = require('child_process');
if(process.send){ //this is a child process
process.exit();
}
//main process, so spawn a child process
cp.fork(__filename);
//this keeps the main process busy and unable to respond to child's exit, making child defunct
while(true){};
关于node.js - 如何在 Node.js 中创建僵尸/失效进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38863302/