There is a key named _channel in the process object of a forked process. The key contains the following
_channel: {
fd: null,
writeQueueSize: 0,
buffering: false,
onread: [Function],
sockets: {
got: {},
send: {}
}
}
The source code of node.js says that the setupChannel function sets this (_channel) key.
I want to know would it be right to assume that to identify whether this process is master or forked one, we need to check if _channel key exist?
Also is there a documentation for Node.js source code?
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.connectedproperty 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 :)