Process
The process
object is a global object and can be accessed from anywhere.It is an instance of EventEmitter.
Process对象是glogal的一个属性,可以在任何地方访问,它也是事件发射的一个实例。
序号 | 名称 | 描述 |
1 | Event: 'exit' | Process退出是注册的事件。 |
2 | Event: 'uncaughtException' | 没有捕获的异常注册的事件。 |
3 | Signal Events | Process接收到一个信号注册的事件。 |
4 | process.stdout | 在标准输出设备输出流,console.log定义 |
5 | process.stderr | |
6 | process.stdin | 接收一个输入流 |
7 | process.argv | 命令行的参数数组。 $ node argv.js 1991 name=byvoid --v "Carbo Kuo" 参数为:第一个:node 第二个:argv.js 第三个:1991 第四个:name=byvoid --v 第五个:"Carbo Kuo" |
8 | process.execPath | process启动的路径. |
9 | process.execArgv | process执行的参数。 process.execArgv为:['--harmony'] |
10 | process.abort() | 退出 |
11 | process.chdir(directory) | 改变当前路径到directory指定的路径。 |
12 | process.cwd() | 返回当前路径。 |
13 | process.env | 用户环境对象。 |
14 | process.exit([code]) | code 指定的值结束process,code为0,标示正常结束(success),其它非正常结束(failure)。 |
15 | process.getgid() | Gets the group identity of the process.This is the numerical group id, not the group name. Note: this function is only available on POSIX platforms (i.e. not Windows) |
16 | process.setgid(id) | Sets the group identity of the process. (See setgid(2).) This accepts eithera numerical ID or a groupname string. If a groupname is specified, this methodblocks while resolving it to a numerical ID. Note: this function is only available on POSIX platforms (i.e. not Windows) |
17 | process.getuid() | Gets the user identity of the process. (See getuid(2).)This is the numerical userid, not the username. Note: this function is only available on POSIX platforms (i.e. not Windows) |
18 | process.setuid(id) | Note: this function is only available on POSIX platforms (i.e. not Windows) |
19 | process.getgroups() | Note: this function is only available on POSIX platforms (i.e. not Windows) Returns an array with the supplementary group IDs. POSIX leaves it unspecifiedif the effective group ID is included but node.js ensures it always is. |
20 | process.setgroups(groups) | Note: this function is only available on POSIX platforms (i.e. not Windows) Sets the supplementary group IDs. This is a privileged operation, meaning youneed to be root or have the CAP_SETGID capability. The list can contain group IDs, group names or both. |
21 | process.initgroups(user, extra_group) | Note: this function is only available on POSIX platforms (i.e. not Windows) Reads /etc/group and initializes the group access list, using all groups ofwhich the user is a member. This is a privileged operation, meaning you needto be root or have the CAP_SETGID capability.
Some care needs to be taken when dropping privileges. Example: |
22 | process.version | A compiled-in property that exposes NODE_VERSION . |
23 | process.versions | A property exposing version strings of node and its dependencies. |
24 | process.config | An Object containing the JavaScript representation of the configure optionsthat were used to compile the current node executable. This is the same asthe "config.gypi" file that was produced when running the ./configure script. |
25 | process.kill(pid, [signal]) | 发送一个信号给process. |
26 | process.pid | The PID of the process. |
27 | process.title | Getter/setter to set what is displayed in 'ps'. |
28 | process.arch | What processor architecture you're running on: 'arm' , 'ia32' , or 'x64' . |
29 | process.platform | What platform you're running on:'darwin' , 'freebsd' , 'linux' , 'sunos' or 'win32' |
30 | process.memoryUsage() | Returns an object describing the memory usage of the Node processmeasured in bytes. This will generate: |
31 | process.nextTick(callback) | On the next loop around the event loop call this callback.This is not a simple alias to setTimeout(fn, 0) , it's much moreefficient. It typically runs before any other I/O events fire, but thereare some exceptions. See process.maxTickDepth below. This is important in developing APIs where you want to give the user thechance to assign event handlers after an object has been constructed,but before any I/O has occurred. It is very important for APIs to be either 100% synchronous or 100%asynchronous. Consider this example: This API is hazardous. If you do this: then it's not clear whether This approach is much better: |
32 | process.maxTickDepth | |
33 | process.umask([mask]) | |
34 | process.uptime() | Number of seconds Node has been running. |
35 | process.hrtime() | Returns the current high-resolution real time in a You may pass in the result of a previous call to |
36 |