README.md
1# js_sys_module Subsystems/Components
2
3- [Introduction](#Introduction)
4- [Directory](#Directory)
5- [Description](#Description)
6 - [Interface description](#Interface description)
7 - [Interface instructions](#Interface instructions)
8
9- [Related warehouse](#Related warehouse])
10
11## Introduction
12Process is mainly used to obtain the relevant ID of the process, obtain and modify the working directory of the process, exit and close the process. The childprocess object can be used to create a new process. The main process can obtain the standard input and output of the child process, send signals and close the child process.
13## Directory
14
15```
16base/compileruntime/js_sys_module/
17├── Class:PROCESS # class of PROCESS
18├── Uid # attribute of Uid
19├── Gid # attribute of Gid
20├── EUid # attribute of EUid
21├── EGid # attribute of EGid
22├── Groups # attribute of Groups
23├── Pid # attribute of Pid
24├── Ppid # attribute of Ppid
25├── chdir() # method of chdir
26├── uptime() # method of uptime
27├── kill() # method of kill
28├── abort() # method of abort
29├── on() # method of on
30├── tid # method of tid
31├── getStartRealtime() # method of getStartRealtime
32├── getAvailableCores() # method of getAvailableCores
33├── getPastCputime() # method of getPastCputime
34├── isIsolatedProcess() # method of isIsolatedProcess
35├── is64Bit() # method of is64Bit
36├── isAppUid() # method of isAppUid
37├── getUidForName() # method of getUidForName
38├── getThreadPriority() # method of getThreadPriority
39├── getSystemConfig() # method of getSystemConfig
40├── getEnvironmentVar() # method of getEnvironmentVar
41├── exit() # method of exit
42├── cwd() # method of cwd
43├── off() # method of off
44├── runCmd() # method of runCmd
45└─── Class:CHILDPROCESS # class of CHILDPROCESS
46 ├── close() # method of close
47 ├── kill() # method of kill
48 ├── getOutput() # method of getOutput
49 ├── getErrorOutput() # method of getErrorOutput
50 ├── wait() # method of wait
51 ├── killed # attribute of killed
52 ├── pid # attribute of pid
53 ├── ppid # attribute of ppid
54 └── exitCode # attribute of exitCode
55```
56
57## Description
58
59### Interface description
60| Interface name | description |
61| -------- | -------- |
62| const uid :number | returns the digital user ID of the process. |
63| const gid :number | returns the numeric group ID of the process. |
64| const euid :number | returns the numeric valid user identity of the process. |
65| const egid :number | returns the numeric valid group ID of the node.js process. |
66| const groups :number[] | returns an array with supplementary group ID. |
67| const pid :number | returns the PID of the process. |
68| const ppid :number | returns the PID of the parent process of the current process. |
69| chdir(dir:string) :void | change the current working directory of the node.js process. |
70| uptime() :number | returns the number of seconds the current system has been running. |
71| Kill(pid:number, signal:number) :boolean | send the signal to the identified process PID, and true means the sending is successful. |
72| abort() :void | cause the node.js process to exit immediately and generate a core file. |
73| on(type:string ,listener:EventListener) :void | used to store events triggered by users. |
74| exit(code:number):void | cause the node.js process to exit immediately. |
75| cwd():string | returns the current working directory of the node.js process. |
76| off(type: string): boolean | clear the events stored by the user. True means the clearing is successful. |
77| runCmd(command: string, options?: { timeout : number, killSignal : number \| string, maxBuffer : number }): ChildProcess |through runcmd, you can fork a new process to run a shell and return the childprocess object. The first parameter command refers to the shell to be run, and the second parameter options refers to some running parameters of the child process. These parameters mainly refer to timeout, killsignal and maxbuffer. If timeout is set, the child process will send a signal killsignal after timeout is exceeded. Maxbuffer is used to limit the maximum stdout and stderr sizes that can be received. |
78| wait(): Promise\<number> | is used to wait for the child process to run and return the promise object, whose value is the exit code of the child process. |
79| getOutput(): Promise\<Uint8Array> | used to get the standard output of the child process. |
80| getErrorOutput(): Promise\<Uint8Array> | used to get the standard error output of the child process. |
81| const tid:number | Returns the TID of the process. |
82| getStartRealtime() :number | Gets the real time elapsed (in milliseconds) from system startup to process startup. |
83| getAvailableCores() :number[] | Gets the CPU kernel available to the current process on the multi-core device. |
84| getPastCputime() :number | Gets the CPU time (in milliseconds) from the start of the process to the current time. |
85| isIsolatedProcess(): boolean | Check if the process is quarantined. |
86| is64Bit(): boolean | Check whether the process is running in a 64 bit environment. |
87| isAppUid(v:number): boolean | Checks whether the specified uid belongs to a specific application. |
88| getUidForName(v:string): number | Obtain the user group ID to which the user belongs according to the user name |
89| getThreadPriority(v:number): number | Gets the thread priority based on the specified TID. |
90| getSystemConfig(name:number): number | Gets the configuration of the system according to the specified system configuration name. |
91| getEnvironmentVar(name:string): string | Obtain the corresponding value according to the name of the environment variable. |
92| close(): void | used to close the running child process. |
93| kill(signal: number \| string): void | used to send signals to child processes. |
94| readonly killed: boolean | indicates whether the signal is sent successfully, and true indicates that the signal is sent successfully. |
95| readonly exitCode: number | indicates the exit code of the child process. |
96| readonly pid: number | represents the child process ID. |
97| readonly ppid: number | represents the main process ID. |
98
99### Interface instructions
100
101Example of using interface:
1021.uid()
103```
104uid(){
105 var res = Process.uid;
106}
107```
1082.gid()
109```
110gid(){
111 var result = Process.gid;
112}
113```
1143.euid()
115```
116euid(){
117 var and = Process.euid;
118}
119```
1204.egid()
121```
122egid(){
123 var resb = Process.egid;
124}
125```
1265.groups()
127```
128groups(){
129 var answer = Process.groups;
130}
131```
1326.pid()
133```
134pid(){
135 var result = Process.pid;
136}
137```
1387.ppid()
139```
140ppid(){
141 var result = Process.ppid;
142}
143```
1448.chdir()
145```
146chdir(){
147 Process.chdir("123456");
148}
149```
1509.uptime()
151```
152uptime(){
153 var num = Process.uptime();
154}
155```
15610.kill()
157```
158kill(){
159 var ansu = Process.kill(5,23);
160}
161```
16211.abort()
163```
164abort(){
165 Process.abort();
166}
167```
16812.on()
169```
170on(){
171 function add(num){
172 var value = num + 5;
173 return value;
174 }
175 Process.on("add",add);
176}
177```
17813.exit()
179```
180exit(){
181 Process.exit(15);
182}
183```
18414.Cwd()
185```
186Cwd(){
187 var result = Process.cwd();
188}
189```
19015.off()
191
192```
193off(){
194 var result = Process.off("add");
195}
196```
19716.runCmd()
198```
199runCmd(){
200 var child = process.runCmd('echo abc')
201 // killSignal can be a number or a string
202 var child = process.runCmd('echo abc;', {killSignal : 'SIGKILL'});
203 var child = process.runCmd('sleep 5; echo abc;', {timeout : 1, killSignal : 9, maxBuffer : 2})
204}
205```
20617.wait()
207```
208wait()
209{
210 var child = process.runCmd('ls')
211 var status = child.wait();
212 status.then(val => {
213 console.log(val);
214 })
215}
216```
21718.getOutput()
218```
219getOutput(){
220 var child = process.runCmd('echo bcd;');
221 var res = child.getOutput();
222 child.wait();
223 res.then(val => {
224 console.log(val);
225 })
226}
227```
22819.getErrorOutput()
229```
230getErrorOutput(){
231 var child = process.runCmd('makdir 1.txt'); // execute an error command
232 var res = child.getErrorOutput();
233 child.wait();
234 res.then(val => {
235 console.log(val);
236 })
237}
238```
23920.close()
240```
241close(){
242 var child = process.runCmd('ls; sleep 5s;')
243 var result = child.close()
244}
245```
24621.kill()
247```
248kill(){
249 var child = process.runCmd('ls; sleep 5s;')
250 var result = child.kill('SIGHUP');
251 child.wait();
252 var temp = child.killed;
253}
254```
25522.killed
256```
257{
258 var child = process.runCmd('ls; sleep 5;')
259 child.kill(3);
260 var killed_ = child.killed;
261 child.wait();
262}
263```
26423.exitCode
265```
266{
267 var child = process.runCmd('ls; sleep 5;')
268 child.kill(9);
269 child.wait();
270 var exitCode_ = child.exitCode;
271}
272```
27324.pid
274```
275pid
276{
277 var child = process.runCmd('ls; sleep 5;')
278 var pid_ = child.pid;
279 child.wait();
280}
281```
28225.ppid
283```
284ppid
285{
286 var child = process.runCmd('ls; sleep 5;')
287 var ppid_ = child.ppid;
288 child.wait();
289}
290```
29126.tid
292```
293tid(){
294 var ansu = Process.tid;
295}
296```
29727.isIsolatedProcess()
298```
299isIsolatedProcess(){
300 var ansu = Process.isIsolatedProcess()();
301}
302```
30328.isAppUid()
304```
305isAppUid(){
306 var ansu = Process.isAppUid(10000);
307}
308```
30929.is64Bit()
310```
311is64Bit(){
312 var ansu = Process.is64Bit();
313}
314```
31530.getUidForName()
316```
317getUidForName(){
318 var buf = "root";
319 var ansu = Process.getUidForName(buf);
320}
321```
32231.getEnvironmentVar()
323```
324getEnvironmentVar(){
325 var ansu = Process.getEnvironmentVar('USER');
326}
327```
32832.getAvailableCores()
329```
330getAvailableCores(){
331 var ansu = Process.getAvailableCores();
332}
333```
33433.getThreadPriority()
335```
336getThreadPriority(){
337 var result = Process.getTid();
338 var ansu = getThreadPriority(result);
339}
340```
34134.getStartRealtime()
342```
343getStartRealtime(){
344 var ansu = Process.getStartRealtime();
345}
346```
34735.getPastCputime()
348```
349getPastCputime(){
350 var ansu = Process.getPastCputime();
351}
352```
35336.getSystemConfig()
354```
355getSystemConfig(){
356 var _SC_ARG_MAX = 0;
357 var ansu = Process.getSystemConfig(_SC_ARG_MAX)
358}
359```
360## Related warehouse
361[js_sys_module](base/compileruntime/js_sys_module/readme.md)
362
363### License
364
365SYS is available under [Mozilla license](https://www.mozilla.org/en-US/MPL/), and the documentation is detailed in [documentation](https://gitee.com/openharmony/js_sys_module/blob/master/mozilla_docs.txt). See [LICENSE](https://gitee.com/openharmony/js_sys_module/blob/master/LICENSE) for the full license text.
README_zh.md
1# js_sys_module子系统/组件
2
3- [简介](#简介)
4- [目录](#目录)
5- [说明](#说明)
6 - [接口说明](#接口说明)
7 - [使用说明](#使用说明)
8
9- [相关仓](#相关仓])
10
11## 简介
12进程主要用于获取进程的相关ID,获取和修改进程的工作目录,退出和关闭进程。 childprocess 对象可用于创建新进程。 主进程可以获取子进程的标准输入输出,发送信号,关闭子进程。
13## 目录
14
15```
16base/compileruntime/js_sys_module/
17├── Class:PROCESS # PROCESS类
18├── Uid # Uid属性
19├── Gid # Gid属性
20├── EUid # EUid属性
21├── EGid # EGid属性
22├── Groups # Groups属性
23├── Pid # Pid属性
24├── Ppid # Ppid属性
25├── chdir() # chdir方法
26├── uptime() # uptime方法
27├── kill() # kill方法
28├── abort() # abort方法
29├── on() # on方法
30├── tid # tid方法
31├── getStartRealtime() # getStartRealtime方法
32├── getAvailableCores() # getAvailableCores方法
33├── getPastCputime() # getPastCputime方法
34├── isIsolatedProcess() # isIsolatedProcess方法
35├── is64Bit() # is64Bit方法
36├── isAppUid() # isAppUid方法
37├── getUidForName() # getUidForName方法
38├── getThreadPriority() # getThreadPriority方法
39├── getSystemConfig() # getSystemConfig方法
40├── getEnvironmentVar() # getEnvironmentVar方法
41├── exit() # exit方法
42├── cwd() # cwd方法
43├── off() # off方法
44├── runCmd() # runCmd方法
45└─── Class:CHILDPROCESS # class of CHILDPROCESS类
46 ├── close() # close方法
47 ├── kill() # kill方法
48 ├── getOutput() # getOutput方法
49 ├── getErrorOutput() # getErrorOutput方法
50 ├── wait() # wait方法
51 ├── killed # killed属性
52 ├── pid # pid属性
53 ├── ppid # ppid属性
54 └── exitCode # exitCode属性
55```
56
57## 说明
58
59### 接口说明
60| 接口名 | 说明 |
61| -------- | -------- |
62| const uid :number | 返回进程的数字用户 ID。 |
63| const gid :number | 返回进程的数字组 ID。 |
64| const euid :number | 返回进程的数字有效用户身份。 |
65| const egid :number | 返回 node.js 进程的数字有效组 ID。 |
66| const groups :number[] | 返回具有补充组 ID 的数组。 |
67| const pid :number | 返回进程的PID。 |
68| const ppid :number | 返回当前进程的父进程的PID。 |
69| chdir(dir:string) :void | 更改 node.js 进程的当前工作目录。 |
70| uptime() :number | 返回当前系统已经运行的秒数。 |
71| Kill(pid:number, signal:number) :boolean | 将信号发送到识别的进程PID,true表示发送成功。 |
72| abort() :void | 导致 node.js 进程立即退出并生成核心文件。 |
73| on(type:string ,listener:EventListener) :void | 用于存储用户触发的事件。 |
74| exit(code:number):void | 导致 node.js 进程立即退出。 |
75| cwd():string | 返回 node.js 进程的当前工作目录。 |
76| off(type: string): boolean | 清除用户存储的事件。 True 表示清算成功。 |
77| runCmd(command: string, options?: { timeout : number, killSignal : number \| string, maxBuffer : number }): ChildProcess |通过runcmd,你可以fork一个新进程来运行一个shell并返回childprocess对象。 第一个参数command指的是要运行的shell,第二个参数options指的是子进程的一些运行参数。 这些参数主要是指 timeout、killsignal 和 maxbuffer。 如果设置了timeout,则子进程会在超时后发送killsignal信号。 Maxbuffer 用于限制可以接收的最大 stdout 和 stderr 大小。 |
78| wait(): Promise\<number> | 用于等待子进程运行并返回promise对象,其值为子进程的退出码。 |
79| getOutput(): Promise\<Uint8Array> | 用于获取子进程的标准输出。 |
80| getErrorOutput(): Promise\<Uint8Array> | 用于获取子进程的标准错误输出。 |
81| const tid:number | 返回进程的 TID。 |
82| getStartRealtime() :number | 获取从系统启动到进程启动所经过的实时时间(以毫秒为单位)。 |
83| getAvailableCores() :number[] | 获取多核设备上当前进程可用的 CPU 内核。 |
84| getPastCputime() :number | 获取从进程开始到当前时间的 CPU 时间(以毫秒为单位)。 |
85| isIsolatedProcess(): boolean | 检查进程是否被隔离。 |
86| is64Bit(): boolean | 检查进程是否在 64 位环境中运行。 |
87| isAppUid(v:number): boolean | 检查指定的 uid 是否属于特定应用程序。 |
88| getUidForName(v:string): number | 根据用户名获取用户所属的用户组ID |
89| getThreadPriority(v:number): number | 根据指定的 TID 获取线程优先级。 |
90| getSystemConfig(name:number): number | 根据指定的系统配置名称获取系统的配置。 |
91| getEnvironmentVar(name:string): string | 根据环境变量的名称获取对应的值。 |
92| close(): void | 用于关闭正在运行的子进程。 |
93| kill(signal: number \| string): void | 用于向子进程发送信号。 |
94| readonly killed: boolean | 表示信号是否发送成功,true表示信号发送成功。 |
95| readonly exitCode: number | 表示子进程的退出代码。 |
96| readonly pid: number | 表示子进程ID。 |
97| readonly ppid: number | 代表主进程ID。 |
98
99### 使用说明
100
101各接口使用方法如下:
1021.uid()
103```
104uid(){
105 var res = Process.uid;
106}
107```
1082.gid()
109```
110gid(){
111 var result = Process.gid;
112}
113```
1143.euid()
115```
116euid(){
117 var and = Process.euid;
118}
119```
1204.egid()
121```
122egid(){
123 var resb = Process.egid;
124}
125```
1265.groups()
127```
128groups(){
129 var answer = Process.groups;
130}
131```
1326.pid()
133```
134pid(){
135 var result = Process.pid;
136}
137```
1387.ppid()
139```
140ppid(){
141 var result = Process.ppid;
142}
143```
1448.chdir()
145```
146chdir(){
147 Process.chdir("123456");
148}
149```
1509.uptime()
151```
152uptime(){
153 var num = Process.uptime();
154}
155```
15610.kill()
157```
158kill(){
159 var ansu = Process.kill(5,23);
160}
161```
16211.abort()
163```
164abort(){
165 Process.abort();
166}
167```
16812.on()
169```
170on(){
171 function add(num){
172 var value = num + 5;
173 return value;
174 }
175 Process.on("add",add);
176}
177```
17813.exit()
179```
180exit(){
181 Process.exit(15);
182}
183```
18414.Cwd()
185```
186Cwd(){
187 var result = Process.cwd();
188}
189```
19015.off()
191
192```
193off(){
194 var result = Process.off("add");
195}
196```
19716.runCmd()
198```
199runCmd(){
200 var child = process.runCmd('echo abc')
201 // killSignal can be a number or a string
202 var child = process.runCmd('echo abc;', {killSignal : 'SIGKILL'});
203 var child = process.runCmd('sleep 5; echo abc;', {timeout : 1, killSignal : 9, maxBuffer : 2})
204}
205```
20617.wait()
207```
208wait()
209{
210 var child = process.runCmd('ls')
211 var status = child.wait();
212 status.then(val => {
213 console.log(val);
214 })
215}
216```
21718.getOutput()
218```
219getOutput(){
220 var child = process.runCmd('echo bcd;');
221 var res = child.getOutput();
222 child.wait();
223 res.then(val => {
224 console.log(val);
225 })
226}
227```
22819.getErrorOutput()
229```
230getErrorOutput(){
231 var child = process.runCmd('makdir 1.txt'); // execute an error command
232 var res = child.getErrorOutput();
233 child.wait();
234 res.then(val => {
235 console.log(val);
236 })
237}
238```
23920.close()
240```
241close(){
242 var child = process.runCmd('ls; sleep 5s;')
243 var result = child.close()
244}
245```
24621.kill()
247```
248kill(){
249 var child = process.runCmd('ls; sleep 5s;')
250 var result = child.kill('SIGHUP');
251 child.wait();
252 var temp = child.killed;
253}
254```
25522.killed
256```
257{
258 var child = process.runCmd('ls; sleep 5;')
259 child.kill(3);
260 var killed_ = child.killed;
261 child.wait();
262}
263```
26423.exitCode
265```
266{
267 var child = process.runCmd('ls; sleep 5;')
268 child.kill(9);
269 child.wait();
270 var exitCode_ = child.exitCode;
271}
272```
27324.pid
274```
275pid
276{
277 var child = process.runCmd('ls; sleep 5;')
278 var pid_ = child.pid;
279 child.wait();
280}
281```
28225.ppid
283```
284ppid
285{
286 var child = process.runCmd('ls; sleep 5;')
287 var ppid_ = child.ppid;
288 child.wait();
289}
290```
29126.tid
292```
293tid(){
294 var ansu = Process.tid;
295}
296```
29727.isIsolatedProcess()
298```
299isIsolatedProcess(){
300 var ansu = Process.isIsolatedProcess()();
301}
302```
30328.isAppUid()
304```
305isAppUid(){
306 var ansu = Process.isAppUid(10000);
307}
308```
30929.is64Bit()
310```
311is64Bit(){
312 var ansu = Process.is64Bit();
313}
314```
31530.getUidForName()
316```
317getUidForName(){
318 var buf = "root";
319 var ansu = Process.getUidForName(buf);
320}
321```
32231.getEnvironmentVar()
323```
324getEnvironmentVar(){
325 var ansu = Process.getEnvironmentVar('USER');
326}
327```
32832.getAvailableCores()
329```
330getAvailableCores(){
331 var ansu = Process.getAvailableCores();
332}
333```
33433.getThreadPriority()
335```
336getThreadPriority(){
337 var result = Process.getTid();
338 var ansu = getThreadPriority(result);
339}
340```
34134.getStartRealtime()
342```
343getStartRealtime(){
344 var ansu = Process.getStartRealtime();
345}
346```
34735.getPastCputime()
348```
349getPastCputime(){
350 var ansu = Process.getPastCputime();
351}
352```
35336.getSystemConfig()
354```
355getSystemConfig(){
356 var _SC_ARG_MAX = 0;
357 var ansu = Process.getSystemConfig(_SC_ARG_MAX)
358}
359```
360
361## 相关仓
362[js_sys_module](base/compileruntime/js_sys_module/readme.md)
363
364### 许可证
365
366SYS在[Mozilla许可证](https://www.mozilla.org/en-US/MPL/)下可用,说明文档详见[说明文档](https://gitee.com/openharmony/js_sys_module/blob/master/mozilla_docs.txt)。有关完整的许可证文本,有关完整的许可证文本,请参见[许可证](https://gitee.com/openharmony/js_sys_module/blob/master/LICENSE)
367