Object built-in object

ObjectChildProcess

child process object

1 2
var child_process = require("child_process"); var child = child_process.spawn("ls");

inheritance relationship

static properties

defaultMaxListeners

Integer, the default global maximum number of listeners

1
static Integer ChildProcess.defaultMaxListeners;

member properties

connected

Boolean, query whether the pipe with the child process is connected normally

1
readonly Boolean ChildProcess.connected;

pid

Integer, read the id of the process pointed to by the current object

1
readonly Integer ChildProcess.pid;

exitCode

Integer, query and set the exit code of the current process

1
readonly Integer ChildProcess.exitCode;

stdin

Stream, reads the standard input object of the process pointed to by the current object

1
readonly Stream ChildProcess.stdin;

stdout

Stream, reads the standard output object of the process pointed to by the current object

1
readonly Stream ChildProcess.stdout;

stderr

Stream, reads the standard error object of the process pointed to by the current object

1
readonly Stream ChildProcess.stderr;

onexit

Function, queries and binds process exit events, equivalent to on("exit", func);

1
Function ChildProcess.onexit;

onmessage

Function, query and bind child process message events, equivalent to on("message", func);

1
Function ChildProcess.onmessage;

member function

kill

Kill the process pointed to by the current object and pass the signal

1
ChildProcess.kill(Integer signal);

Call parameters:

  • signal: Integer, the signal passed

Kill the process pointed to by the current object and pass the signal

1
ChildProcess.kill(String signal);

Call parameters:

  • signal: String, the signal passed

join

Wait for the process pointed to by the current object to end and return the process end code

1
Integer ChildProcess.join() async;

Return results:

  • Integer, the end code of the process

disconnect

Close ipc pipe to child process

1
ChildProcess.disconnect();

send

Send a message to the current child process

1
ChildProcess.send(Value msg);

Call parameters:

  • msg: Value, specifies the message to send

usage

Query the memory occupied and time spent by the current process

1
Object ChildProcess.usage();

Return results:

  • Object, returns a report containing the time

The memory report produces results similar to the following:

1 2 3 4 5
{ "user": 132379, "system": 50507, "rss": 8622080 }

in:

  • user returns the time the process spent in user code, measured in microseconds (millionths of a second)
  • system returns the time the process spent in system code, expressed in microseconds (millionths of a second)
  • rss returns the current physical memory size occupied by the process

on

Bind an event handler to the object

1 2
Object ChildProcess.on(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object

1
Object ChildProcess.on(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

addListener

Bind an event handler to the object

1 2
Object ChildProcess.addListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object

1
Object ChildProcess.addListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

prependListener

Bind an event handler to the object's origin

1 2
Object ChildProcess.prependListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object's origin

1
Object ChildProcess.prependListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

once

Bind a one-time event handler to the object. The one-time handler will only be triggered once.

1 2
Object ChildProcess.once(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind a one-time event handler to the object. The one-time handler will only be triggered once.

1
Object ChildProcess.once(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

prependOnceListener

Bind an event handler to the object's origin

1 2
Object ChildProcess.prependOnceListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Bind an event handler to the object's origin

1
Object ChildProcess.prependOnceListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the value of the attribute will be used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

off

Unassign a function from the object processing queue

1 2
Object ChildProcess.off(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Cancel all functions in the object processing queue

1
Object ChildProcess.off(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

Unassign a function from the object processing queue

1
Object ChildProcess.off(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the value of the attribute is used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

removeListener

Unassign a function from the object processing queue

1 2
Object ChildProcess.removeListener(String ev, Function func);

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specify the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

Cancel all functions in the object processing queue

1
Object ChildProcess.removeListener(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

Unassign a function from the object processing queue

1
Object ChildProcess.removeListener(Object map);

Call parameters:

  • map: Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the value of the attribute is used as the event processing function

Return results:

  • Object, returns the event object itself to facilitate chain calls

removeAllListeners

Cancels all listeners for all events from the object's processing queue. If an event is specified, removes all listeners for the specified event.

1
Object ChildProcess.removeAllListeners(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

Cancels all listeners for all events from the object's processing queue. If an event is specified, removes all listeners for the specified event.

1
Object ChildProcess.removeAllListeners(Array evs = []);

Call parameters:

  • evs: Array, specify the name of the event

Return results:

  • Object, returns the event object itself to facilitate chain calls

setMaxListeners

The default limit on the number of listeners, for compatibility only

1
ChildProcess.setMaxListeners(Integer n);

Call parameters:

  • n: Integer, specify the number of events

getMaxListeners

Gets the default limit number of listeners, for compatibility only

1
Integer ChildProcess.getMaxListeners();

Return results:

  • Integer, returns the default limit quantity

listeners

Query the listener array for the specified event of the object

1
Array ChildProcess.listeners(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Array, returns the listener array for the specified event

listenerCount

Query the number of listeners for the specified event of the object

1
Integer ChildProcess.listenerCount(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return results:

  • Integer, returns the number of listeners for the specified event

Query the number of listeners for the specified event of the object

1 2
Integer ChildProcess.listenerCount(Value o, String ev);

Call parameters:

  • o: Value, specifies the object of the query
  • ev: String, specifies the name of the event

Return results:

  • Integer, returns the number of listeners for the specified event

eventNames

Query listener event name

1
Array ChildProcess.eventNames();

Return results:

  • Array, returns an array of event names

emit

Actively trigger an event

1 2
Boolean ChildProcess.emit(String ev, ...args);

Call parameters:

  • ev: String, event name
  • args: ..., event parameters will be passed to the event processing function

Return results:

  • Boolean, returns the event trigger status, returns true if there is a response event, otherwise returns false

toString

Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.

1
String ChildProcess.toString();

Return results:

  • String, returns the string representation of the object

toJSON

Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.

1
Value ChildProcess.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable