如何在Node.js中创建僵尸/已终止进程? [英] How do you create zombie/defunct process in nodejs?

查看:171
本文介绍了如何在Node.js中创建僵尸/已终止进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有很多帖子(例如 https://unix.stackexchange.com/questions/217507/zombies-in-bash ),展示了如何在bash或c中创建僵尸进程.我想知道是否有一种方法可以在nodejs中创建它们,所以当我执行ps ax | grep node时,有一行命令段为node <defunct>.

There are many posts here (e.g. https://unix.stackexchange.com/questions/217507/zombies-in-bash) that shows how to create zombie processes in bash or c. I would like to know if there is a way to create them in nodejs so when I do ps ax | grep node, there's a line whose command section is node <defunct>.

非常感谢您.

推荐答案

回答我自己的问题,以防对任何人有帮助.事实证明,在节点中很容易做到这一点.运行以下脚本后,可以执行ps ax | grep node,并且应该看到带有[node] <defunct>的条目.

Answering my own questions in case it helps anyone. Turns out to be pretty easy to do it in node. After you run the following script, you can do a ps ax | grep node and you should see an entry with [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中创建僵尸/已终止进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆