Skip to content

Commit e50c67e

Browse files
committed
Node process and child process
1 parent e42a610 commit e50c67e

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Node.js Process and Child Process
2+
3+
> [http://youtu.be/9o8B3L0-d9c](http://youtu.be/9o8B3L0-d9c)
4+
5+
Install [io.js](https://iojs.org/en/index.html).
6+
7+
Run `node index.js` to run the example.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var spawn = require('child_process').spawn
2+
3+
var bears = 0
4+
5+
bears += 1
6+
7+
if (process.argv[2] === 'child') {
8+
var net = require('net')
9+
var pipe = new net.Socket({ fd: 3 })
10+
pipe.write('killme')
11+
//console.log('child', bears)
12+
} else {
13+
var child = spawn(process.execPath, [__filename, 'child'], {
14+
stdio: [null, null, null, 'pipe']
15+
})
16+
child.stdio[3].on('data', function (data) {
17+
if (data.toString() === 'killme') {
18+
console.log('RIP')
19+
child.kill()
20+
}
21+
})
22+
//console.log('parent', bears)
23+
//child.stdout.pipe(process.stdout)
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "node-process-child-process",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js",
8+
"test": "node test.js"
9+
},
10+
"author": "Kyle Robinson Young <kyle@dontkry.com> (http://dontkry.com)",
11+
"license": "MIT"
12+
}

0 commit comments

Comments
 (0)