• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.