| egid | number | Yes| No| Effective group identifier (EGID) of a process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| euid | number | Yes| No| Effective user identifier (EUID) of a process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| gid | number | Yes| No| Group identifier (GID) of a process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| uid | number | Yes| No| User identifier (UID) of a process.|
| egid | number | Yes| No| Effective group identifier (EGID) of the process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| euid | number | Yes| No| Effective user identifier (EUID) of the process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| gid | number | Yes| No| Group identifier (GID) of the process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| uid | number | Yes| No| User identifier (UID) of the process.|
| groups | number[] | Yes| No| Array with supplementary group IDs.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| pid | number | Yes| No| Process ID (PID) of a process.|
| ppid | number | Yes| No| Parent process ID (PPID) of a process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| tid<sup>8+</sup> | number | Yes| No| Thread ID (TID) of a process.|
| pid | number | Yes| No| Process ID (PID) of the process.|
| ppid | number | Yes| No| Parent process ID (PPID) of the process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| tid<sup>8+</sup> | number | Yes| No| Thread ID (TID) of the thread.|
## ProcessManager<sup>9+</sup>
## EventListener
Provides APIs for throwing exceptions during the addition of a process.
@@ -158,29 +136,58 @@ Obtains the value of an environment variable.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Environment variable name.|
| command | string | Yes| Shell command to run.|
| options | Object | No| Related parameters.|
**Table 1** options
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| timeout | number | No| Maximum running time (in milliseconds) of the child process. When the running time of the child process exceeds the value of this parameter, the parent process sends a **killSignal** to the child process to terminate it. The default value is **0**.|
| killSignal | number \| string | No| Signal sent to the child process when the running time of a child process exceeds the timeout period. The default value is **SIGTERM**.|
| maxBuffer | number | No| Maximum buffer size for the standard input and output of the child process. When the size is exceeded, the child process will be terminated. The default value is **1024 \* 1024**.|
| pid | number | Yes| No| PID of the child process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| ppid | number | Yes| No| PPID of the child process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| exitCode | number | Yes| No| Exit code of the child process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| killed | boolean | Yes| No| Whether the parent process successfully sends a signal to the child process to terminate it.<br>**System API**: This is a system API.<br>It is used only to test applications.|
### wait
## process.cwd
wait(): Promise<number>
cwd(): string
Waits until the child process ends. This method uses a promise to return the exit code of the child process.
Obtains the working directory of this process.
**System API**: This is a system API.
...
...
@@ -260,24 +257,20 @@ It is used only to test applications.
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the exit code of the child process.|
| string| Working directory obtained.|
**Example**
```js
letchild=process.runCmd('ls');
letresult=child.wait();
result.then(val=>{
console.log("result = "+val);
})
letpath=process.cwd();
```
### getOutput
## process.chdir
getOutput(): Promise<Uint8Array>
chdir(dir: string): void
Obtains the standard output of the child process.
Changes the working directory of this process.
**System API**: This is a system API.
...
...
@@ -285,81 +278,109 @@ It is used only to test applications.
| pid | number | Yes| PID of the process, to which the signal will be sent.|
| signal | number | Yes| Signal to send.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<Uint8Array> | Promise used to return the standard error output in a Uint8Array.|
| boolean | Returns **true** if the signal is sent successfully; returns **false** otherwise.|
**Example**
```js
letchild=process.runCmd('madir test.text');
letresult=child.wait();
child.getErrorOutput().then(val=>{
console.log("child.getErrorOutput= "+val);
})
letpres=process.pid
letresult=process.kill(28,pres)
```
### close
## process.exit<sup>(deprecated)</sup>
close(): void
exit(code: number): void
Closes the child process in running.
Terminates this process.
**System API**: This is a system API.
Exercise caution when using this API. After this API is called, the application exits. If the input parameter is not 0, data loss or exceptions may occur.
It is used only to test applications.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [exit<sup>9+</sup>](#exit9) instead.
Sends a signal to the specified child process to terminate it.
getUidForName(v: string): number
**System API**: This is a system API.
Obtains the process UID based on the process name.
It is used only to test applications.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getUidForName<sup>9+</sup>](#getuidforname9) instead.
Obtains the thread priority based on the specified TID.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getThreadPriority<sup>9+</sup>](#getthreadpriority9) instead.
@@ -416,7 +457,7 @@ Checks whether a UID belongs to this application.
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the UID is the application's UID; returns **false** otherwise.|
| boolean | Returns **true** if the UID belongs to the application; returns **false** otherwise.|
**Example**
...
...
@@ -425,32 +466,47 @@ let result = process.isAppUid(688);
```
## process.is64Bit<sup>8+</sup>
## process.getSystemConfig<sup>(deprecated)</sup>
is64Bit(): boolean
getSystemConfig(name: number): number
Checks whether this process is running in a 64-bit environment.
Obtains the system configuration.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getSystemConfig<sup>9+</sup>](#getsystemconfig9) instead.
Obtains the process UID based on the process name.
Obtains the value of an environment variable.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEnvironmentVar<sup>9+</sup>](#getenvironmentvar9) instead.
@@ -565,12 +643,13 @@ Obtains the system configuration.
**Example**
```js
let_SC_ARG_MAX=0
letpres=process.getSystemConfig(_SC_ARG_MAX)
letpro=newprocess.ProcessManager();
let_SC_ARG_MAX=0;
letpres=pro.getSystemConfig(_SC_ARG_MAX);
```
## process.getEnvironmentVar<sup>8+</sup>
### getEnvironmentVar<sup>9+</sup>
getEnvironmentVar(name: string): string
...
...
@@ -593,19 +672,18 @@ Obtains the value of an environment variable.
**Example**
```js
letpres=process.getEnvironmentVar("PATH")
letpro=newprocess.ProcessManager();
letpres=pro.getEnvironmentVar("PATH");
```
## process.runCmd
runCmd(command: string, options?: { timeout?: number, killSignal?: number | string, maxBuffer?: number }): ChildProcess
### exit<sup>9+</sup>
Forks a new process to run a shell command and returns the **ChildProcess** object.
exit(code: number): void
**System API**: This is a system API.
Terminates this process.
It is used only to test applications.
Exercise caution when using this API. After this API is called, the application exits. If the input parameter is not 0, data loss or exceptions may occur.
| timeout | number | No| Maximum running time (in ms) of the child process. When the running time of the child process exceeds the value of this parameter, the parent process sends a **killSignal** to the child process to terminate it. The default value is **0**.|
| killSignal | number \| string | No| Signal sent to the child process when the running time of a child process exceeds the timeout period. The default value is **SIGTERM**.|
| maxBuffer | number | No| Maximum buffer size for the standard input and output of the child process. When the size is exceeded, the child process will be terminated. The default value is **1024 \* 1024**.|
| pid | number | Yes| PID of the process, to which the signal will be sent.|
| boolean | Returns **true** if the signal is sent successfully; returns **false** otherwise.|
**Example**
```js
letchild=process.runCmd('ls',{maxBuffer:2});
letresult=child.wait();
child.getOutput.then(val=>{
console.log("child.getOutput = "+val);
})
letpro=newprocess.ProcessManager();
letpres=process.pid;
letresult=pro.kill(28,pres);
```
## process.abort
## ChildProcess
abort(): void
The **ChildProcess** object is a new child process and can be obtained by calling [process.runCmd](#processruncmd). The main process can obtain the standard input and output of the child process, send signals to the child process, and close the child process.
Aborts a process and generates a core file. This method will cause a process to exit immediately. Exercise caution when using this method.
| pid | number | Yes| No| PID of the child process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| ppid | number | Yes| No| PPID of the child process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| exitCode | number | Yes| No| Exit code of the child process.<br>**System API**: This is a system API.<br>It is used only to test applications.|
| killed | boolean | Yes| No| Whether the parent process successfully sends a signal to the child process to terminate it.<br>**System API**: This is a system API.<br>It is used only to test applications.|
## process.on
### wait
on(type: string, listener: EventListener): void
wait(): Promise<number>
Stores the events triggered by the user.
Waits until the child process ends. This method uses a promise to return the exit code of the child process.
**System API**: This is a system API.
...
...
@@ -668,33 +763,28 @@ It is used only to test applications.