Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ log, either periodically (probably best for long-running programs, allowing
you to clear the map, which in the case of a very buggy program could grow
indefinitely) or upon process exit (more convenient for scripts).

## Event: 'spawn'

Emitted whenever a process calls the internal `child_process.spawn()` and assign

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sentence is a little awkward.

Also, assigns.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would make it:

Emitted whenever a spawned child process is assigned a `pid`. 

the child a `pid`. This is useful for bookkeeping - especially for subsequent
calls to `process.kill()`, in case no reference to `child` was held and hence

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, not needed imo

`child.kill()` is not an option.

## Event: 'uncaughtException'

The `'uncaughtException'` event is emitted when an exception bubbles all the
Expand Down
1 change: 1 addition & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ ChildProcess.prototype.spawn = function(options) {
}

this.pid = this._handle.pid;
process.emit('spawn', this.pid);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do this in nextTick...

process.nextTick(() => process.emit('spawn', this.pid));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be in nextTick.


stdio.forEach(function(stdio, i) {
if (stdio.type === 'ignore') return;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-process-emit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run make lint

const sym = Symbol();

process.on('normal', common.mustCall((data) => {
Expand All @@ -20,3 +21,7 @@ process.emit(sym, 'symbolData');
process.emit('SIGPIPE', 'signalData');

assert.strictEqual(isNaN(process._eventsCount), false);

process.on('spawn', common.mustCall((pid) => {
assert.strictEqual(isNaN(pid), false);
}))