0

在分叉进程_channel的对象中有一个键名。process密钥包含以下内容

_channel: {
    fd: null,
    writeQueueSize: 0,
    buffering: false,
    onread: [Function],
    sockets: {
        got: {},
        send: {}
    }
}

node.js 的源代码说该setupChannel函数设置了 this ( _channel) 键。

我想知道假设要确定该进程是主进程还是分叉进程,我们需要检查_channel密钥是否存在是否正确?

还有 Node.js 源代码的文档吗?

4

1 回答 1

0

What I understand from your question is you want to be able to identify whether or not the current process is a child of any other process and if its able to send the message to the parent.

If its right then you can use the connected property of the process object, like:

if (process.connected) {
  // do something
}

According to the documentation

way to check if you can send messages is to see if the child.connected property is true.

It won't be present if the process doesn't have any parent, and it will be false if the child is already disconnected from the parent

Hope that helps :)

于 2013-07-10T06:20:53.447 回答