node.js - 如何在 Node.js 中创建僵尸/失效进程?

标签 node.js linux bash zombie-process

这里有很多帖子(例如 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/

相关文章:

javascript - 将 Node.js 与 Symfony2 或 PHP 集成

node.js - 使用 Jest 测试异步函数抛出错误时获取 "function did not throw"

javascript - 通过 Github 进行身份验证(使用 everyauth)

linux - 我怎样才能在这个变量中得到这个值 [Linux Bash]

javascript - 类型错误 : Repository method is not a function (NestJS/TypeORM)

linux - GNU make - 让一个任务也做另一个任务

c++ - 指向对象类型的指针

linux - BASH while 循环和 qt-faststart

bash - 在bash循环中同步访问2个变量

linux - 如何正确格式化这个 bash if 语句?