Skip to content

Commit 3744e2a

Browse files
Ian-ReadIan-Read
authored andcommitted
Intro
1 parent 7db5a78 commit 3744e2a

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

child-processes/index.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,47 @@ layout: default.njk
33
title: Child Processes
44
---
55

6-
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhäuser Gate. All those moments will be lost in time, like child processes.
6+
The `child_process` module provides the ability to spawn child processes. Whilst single-threaded, non-blocking performance in Node.js is great for a single process, but we can use `child_process` to handle the increasing workload in our applications.
7+
8+
Child processes are spawned in a manner that is similar, but not identical, to [popen(3)](http://man7.org/linux/man-pages/man3/popen.3.html) from Linux programming using the `child_process.spawn()` function.
9+
10+
11+
https://www.freecodecamp.org/news/node-js-child-processes-everything-you-need-to-know-e69498fe970a/
12+
13+
14+
15+
Using multiple processes is the best way to scale a Node application. Node.js is designed for building distributed applications with many nodes. This is why it’s named Node. Scalability is baked into the platform and it’s not something you start thinking about later in the lifetime of an application.
16+
17+
18+
19+
20+
21+
```
22+
23+
24+
As you probably know, our typical OS has different processes running in the background. Each process is being managed by a single-core of our CPU and will run a series of calculations each time it is being ticked. As such, we can’t take full advantage of our CPU using a single process, we would need a number of processes that is at least equal to the number of cores in our CPU. In addition, each process might be responsible for running a series of calculations of different logic, which will give the end user a better control over the CPU’s behavior.
25+
26+
27+
28+
Why is this module called child_process and not just process? First of all, not to confuse with the main process instance global.process, and second, the child process is derived from the main process, which means that both can communicate - the main process will hold streams for the child process’s std types and they will both share an ipc channel (“Inter Process Communication” channel; more on that further this article).
29+
30+
31+
32+
33+
34+
```
35+
36+
37+
`spawn`
38+
39+
40+
The first parameter is the path for an executable file that starts the process, and the second argument is the arguments that will be passed into the process.
41+
42+
43+
44+
45+
46+
47+
48+
More reading: [Node.js Child Processes: Everything you need to know
49+
](https://www.freecodecamp.org/news/node-js-child-processes-everything-you-need-to-know-e69498fe970a/)

0 commit comments

Comments
 (0)