Paulo Lopes
Paulo Lopes

Reputation: 5801

How node IPC works between 2 processes

Using nodejs fork you can perform IPC between the parent process and the child process. Previously I was under the impression that the child process would have an extra environment variable with a file descriptor. I printed the process env but I can't see any variable with a file Id, I don't see any open sockets either, so my question is how does node IPC works behind the scenes?

Upvotes: 2

Views: 2039

Answers (1)

jfriend00
jfriend00

Reputation: 707786

so my question is how does node IPC (for forked processes) works behind the scenes

The source code for fork uses a Pipe object internally. Looking further into that Pipe object, it is a wrapper over the libuv Pipe object. Then, looking into libuv, it's Pipe abstraction is a domain socket on Unix and a named pipe on Windows.

Now, since this is all undocumented implementation details, there's nothing that says it has to always be done this way in the future - though one would not expect it to change unless there was a really good reason.

Upvotes: 5

Related Questions