Api official document: http: //nodejs.cn/api/child_process.html
As we all know node.js model is based on single-threaded architecture, this design can bring efficient CPU utilization, but was unable to take advantage of multiple CPU cores, in order to solve this problem, node.js provides child_process module, through multiple processes to achieve utilization of multi-core CPU. child_process module provides four functions to create a child process, namely spawn, exec, execFile and fork.
The figure has demonstrated four ways different, but we'll explain the difference between them:
- the spawn : non node executing subprocesses, after providing a set of parameters, as a result of performing the return stream.
- execfile : non node executing subprocesses, after providing a set of parameters, as a result of performing the callback return.
- exec : non-execution of the child process node program, passing a string of shell command, after performing results are returned in the form of callback, and execFile
difference is exec can execute a bunch of shell commands directly. - the fork : child process is a program node, after providing a set of parameters, as a result of performing the return flow, with different spawn, fork a child process can only be performed to generate the application node. The following section describes which specific methods.
Unfinished. . .