ChildProcess
Instances of the ChildProcess
represent spawned child processes.
Instances of ChildProcess
are not intended to be created directly. Rather, use the {@link spawn}, {@link exec},{@link execFile}, or {@link fork} methods to create instances of ChildProcess
.
Since
v2.2.0
Inheritors
Properties
The subprocess.signalCode
property indicates the signal received by the child process if any, else null
.
The subprocess.spawnargs
property represents the full list of command-line arguments the child process was launched with.
A sparse array of pipes to the child process, corresponding with positions in the stdio
option passed to {@link spawn} that have been set to the value 'pipe'
. subprocess.stdio[0]
, subprocess.stdio[1]
, and subprocess.stdio[2]
are also available as subprocess.stdin
, subprocess.stdout
, and subprocess.stderr
, respectively.
Functions
events.EventEmitter
Closes the IPC channel between parent and child, allowing the child to exit gracefully once there are no other connections keeping it alive. After calling this method the subprocess.connected
and process.connected
properties in both the parent and child (respectively) will be set to false
, and it will be no longer possible to pass messages between the processes.
Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbol
s.
Returns the current max listener value for the EventEmitter
which is either set by emitter.setMaxListeners(n)
or defaults to {@link defaultMaxListeners}.
When an IPC channel has been established between the parent and child ( i.e. when using {@link fork}), the subprocess.send()
method can be used to send messages to the child process. When the child process is a Node.js instance, these messages can be received via the 'message'
event.
By default EventEmitter
s will print a warning if more than 10
listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners()
method allows the limit to be modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
By default, the parent will wait for the detached child to exit. To prevent the parent from waiting for a given subprocess
to exit, use the subprocess.unref()
method. Doing so will cause the parent's event loop to not include the child in its reference count, allowing the parent to exit independently of the child, unless there is an established IPC channel between the child and the parent.