Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

node.js父子进程间通讯

$
0
0

最近在学习node.js的child_process的文档,通过fork方法创建子进程的时,有个silent的配置选项

const fork = require('child_process').fork
const cp = fork('./sub.js', [], { silent: true })

如果将silent配置为了true,那么子进程的stdin/stdout/stderr将会pipe到父进程。

因为通过fork的方法去创建子进程的话,父子进程是可以通过ipc通道进行通讯的。

那么这个将stdin/stdout/stderr都pipe到父进程我想也是为了父子进程间的通讯吧?不过这样做实际上有什么用途以及实际场景呢?


Viewing all articles
Browse latest Browse all 14821

Trending Articles