这里有很多帖子(例如https://unix.stackexchange.com/questions/217507/zombies-in-bash https://unix.stackexchange.com/questions/217507/zombies-in-bash)展示了如何在 bash 或 c 中创建僵尸进程。我想知道是否有办法在 Nodejs 中创建它们,所以当我这样做时ps ax | grep node
,有一行的命令部分是node <defunct>
.
非常感谢。
回答我自己的问题,以防对任何人有帮助。事实证明,在节点中做到这一点非常容易。运行以下脚本后,您可以执行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){};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)