node.js child process - difference between spawn & fork

前端 未结 3 1305
清歌不尽
清歌不尽 2020-12-02 04:36

This might seem like a basic question, but I could not find any documentation :

What is the difference between forking & spawning a node.js process? I have read

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 04:46

    • spawnchild_process.spawn launches a new process with a given command.
    • fork − The child_process.fork method is a special case of the spawn() to create child processes.

    The spawn() Method

    child_process.spawn method launches a new process with a given command. It has the following signature −

    child_process.spawn(command[, args][, options])
    

    Read more about options

    The spawn() method returns streams (stdout &stderr) and it should be used when the process returns a volume amount of data. spawn() starts receiving the response as soon as the process starts executing.

    The fork() Method

    child_process.fork method is a special case of spawn() to create Node processes. It has the following signature −

     child_process.fork(modulePath[, args][, options])
    

    The fork method returns an object with a built-in communication channel in addition to having all the methods in a normal ChildProcess instance.

提交回复
热议问题