• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2021 Huawei Device Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7*     http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16/**
17* The process is mainly used to obtain the relevant ID of the process, obtain and modify
18* the working directory of the process, exit and close the process.
19* @since 7
20* @syscap SystemCapability.Utils.Lang
21* @import import url from '@ohos.process';
22*/
23
24declare namespace process {
25    /**
26    * The childprocess object can be used to create a new process.
27    * @since 7
28    * @syscap SystemCapability.Utils.Lang
29    * @systemapi Hide this for inner system use
30    */
31    export interface ChildProcess {
32        /**
33        * return pid is the pid of the current process
34        * @since 7
35        * @syscap SystemCapability.Utils.Lang
36        * @systemapi Hide this for inner system use
37        * @return return the pid of the current process.
38        */
39        readonly pid: number;
40        /**
41        * return ppid is the pid of the current child process
42        * @since 7
43        * @syscap SystemCapability.Utils.Lang
44        * @systemapi Hide this for inner system use
45        * @return return the pid of the current child process.
46        */
47        readonly ppid: number;
48
49        /**
50        * return exitCode is the exit code of the current child process
51        * @since 7
52        * @syscap SystemCapability.Utils.Lang
53        * @systemapi Hide this for inner system use
54        * @return return the exit code of the current child process.
55        */
56        readonly exitCode: number;
57
58        /**
59        * return boolean is whether the current process signal is sent successfully
60        * @since 7
61        * @syscap SystemCapability.Utils.Lang
62        * @systemapi Hide this for inner system use
63        * @return return whether the current process signal is sent successfully.
64        */
65        readonly killed: boolean;
66
67        /**
68        * return 'number' is the target process exit code
69        * @since 7
70        * @syscap SystemCapability.Utils.Lang
71        * @systemapi Hide this for inner system use
72        * @return return the target process exit code.
73        */
74        wait(): Promise<number>;
75
76        /**
77        * return it as 'Uint8Array' of the stdout until EOF
78        * @since 7
79        * @syscap SystemCapability.Utils.Lang
80        * @systemapi Hide this for inner system use
81        * @return return subprocess standard outpute.
82        */
83        getOutput(): Promise<Uint8Array>;
84
85        /**
86        * return it as 'Uint8Array of the stderr until EOF
87        * @since 7
88        * @syscap SystemCapability.Utils.Lang
89        * @systemapi Hide this for inner system use
90        * @return return subprocess standard error output.
91        */
92        getErrorOutput(): Promise<Uint8Array>;
93
94        /**
95        * close the target process
96        * @since 7
97        * @syscap SystemCapability.Utils.Lang
98        * @systemapi Hide this for inner system use
99        */
100        close(): void;
101
102        /**
103        * send a signal to process
104        * @since 7
105        * @syscap SystemCapability.Utils.Lang
106        * @systemapi Hide this for inner system use
107        * @param signal number or string represents the signal sent.
108        */
109        kill(signal: number | string): void;
110    }
111
112    /**
113    * returns the numeric valid group ID of the process
114    * @since 7
115    * @syscap SystemCapability.Utils.Lang
116    * @systemapi Hide this for inner system use
117    * @return return the numeric valid group ID of the process.
118    */
119    const egid: number;
120
121    /**
122    * return the numeric valid user identity of the process
123    * @since 7
124    * @syscap SystemCapability.Utils.Lang
125    * @systemapi Hide this for inner system use
126    * @return return the numeric valid user identity of the process.
127    */
128    const euid: number;
129
130    /**
131    * returns the numeric group id of the process
132    * @since 7
133    * @syscap SystemCapability.Utils.Lang
134    * @systemapi Hide this for inner system use
135    * @return return the numeric group if of the process.
136    */
137    const gid: number
138
139    /**
140    * returns the digital user id of the process
141    * @since 7
142    * @syscap SystemCapability.Utils.Lang
143    * @return return the digital user id of the process.
144    */
145    const uid: number;
146
147    /**
148    * return an array with supplementary group id
149    * @since 7
150    * @syscap SystemCapability.Utils.Lang
151    * @systemapi Hide this for inner system use
152    * @return return an array with supplementary group id.
153    */
154    const groups: number[];
155
156    /**
157    * return pid is The pid of the current process
158    * @since 7
159    * @syscap SystemCapability.Utils.Lang
160    * @return return The pid of the current process.
161    */
162    const pid: number;
163
164    /**
165    * return ppid is The pid of the current child process
166    * @since 7
167    * @syscap SystemCapability.Utils.Lang
168    * @systemapi Hide this for inner system use
169    * @return return The pid of the current child process.
170    */
171    const ppid: number;
172
173    /**
174    * Returns the tid of the current thread.
175    * @since 8
176    * @syscap SystemCapability.Utils.Lang
177    * @return return the tid of the current thread.
178    */
179    const tid: number;
180
181    /**
182    * Returns a boolean whether the process is isolated.
183    * @since 8
184    * @syscap SystemCapability.Utils.Lang
185    * @return return boolean whether the process is isolated.
186    */
187    function isIsolatedProcess(): boolean;
188
189    /**
190    * Returns a boolean whether the specified uid belongs to a particular application.
191    * @since 8
192    * @syscap SystemCapability.Utils.Lang
193    * @param v An id.
194    * @return return a boolean whether the specified uid belongs to a particular application.
195    */
196    function isAppUid(v: number): boolean;
197
198    /**
199    * Returns a boolean whether the process is running in a 64-bit environment.
200    * @since 8
201    * @syscap SystemCapability.Utils.Lang
202    * @return return a boolean whether the process is running in a 64-bit environment.
203    */
204    function is64Bit(): boolean;
205
206    /**
207    * Returns the uid based on the specified user name.
208    * @since 8
209    * @syscap SystemCapability.Utils.Lang
210    * @param v Process name.
211    * @return return the uid based on the specified user name.
212    */
213    function getUidForName(v: string): number;
214
215    /**
216    * Returns the thread priority based on the specified tid.
217    * @since 8
218    * @syscap SystemCapability.Utils.Lang
219    * @param v The tid of the process.
220    * @return Return the thread priority based on the specified tid.
221    */
222    function getThreadPriority(v: number): number;
223
224    /**
225    * Returns the elapsed real time (in milliseconds) taken from the start of the system to the start of the process.
226    * @since 8
227    * @syscap SystemCapability.Utils.Lang
228    * @return Return the start of the system to the start of the process.
229    */
230    function getStartRealtime(): number;
231
232    /**
233    * Returns the cpu time (in milliseconds) from the time when the process starts to the current time.
234    * @since 8
235    * @syscap SystemCapability.Utils.Lang
236    * @return Return the cpu time (in milliseconds) from the time when the process starts to the current time.
237    */
238    function getPastCpuTime(): number;
239
240    /**
241    * Returns the system configuration at runtime.
242    * @since 8
243    * @syscap SystemCapability.Utils.Lang
244    * @param name Parameters defined by the system configuration.
245    * @return Return the system configuration at runtime.
246    */
247    function getSystemConfig(name: number): number;
248
249    /**
250    * Returns the system value for environment variables.
251    * @since 8
252    * @syscap SystemCapability.Utils.Lang
253    * @param name Parameters defined by the system environment variables.
254    * @Returns the system value for environment variables.
255    */
256    function getEnvironmentVar(name: string): string;
257
258    type EventListener = (evt: Object) => void;
259    /**
260    * Return a child process object and spawns a new ChildProcess to run the command
261    * @since 7
262    * @syscap SystemCapability.Utils.Lang
263    * @param command string of the shell commands executed by the child process.
264    * @param options This is an object. The object contains three parameters. Timeout is the running time of the child
265    * process, killSignal is the signal sent when the child process reaches timeout, and maxBuffer is the size of the
266    * maximum buffer area for standard input and output.
267    * @systemapi Hide this for inner system use
268    * @return Return a child process object.
269    */
270    function runCmd(command: string,
271        options?: { timeout : number, killSignal : number | string, maxBuffer : number }): ChildProcess;
272
273    /**
274    * Abort current process
275    * @since 7
276    * @syscap SystemCapability.Utils.Lang
277    */
278    function abort(): void;
279
280    /**
281    * Register for an event
282    * @since 7
283    * @syscap SystemCapability.Utils.Lang
284    * @param type Indicates the type of event registered.
285    * @systemapi Hide this for inner system use
286    * @param listener Represents the registered event function
287    */
288    function on(type: string, listener: EventListener): void;
289
290    /**
291    * Remove registered event
292    * @since 7
293    * @syscap SystemCapability.Utils.Lang
294    * @param type Remove the type of registered event.
295    * @systemapi Hide this for inner system use
296    * @return Return removed result.
297    */
298    function off(type: string): boolean;
299
300    /**
301    * Process exit
302    * @since 7
303    * @syscap SystemCapability.Utils.Lang
304    * @param code Process exit code.
305    */
306    function exit(code: number): void;
307
308    /**
309    * Return the current work directory;
310    * @since 7
311    * @syscap SystemCapability.Utils.Lang
312    * @systemapi Hide this for inner system use
313    * @return Return the current work directory.
314    */
315    function cwd(): string;
316
317    /**
318    * Change current  directory
319    * @since 7
320    * @syscap SystemCapability.Utils.Lang
321    * @systemapi Hide this for inner system use
322    * @param dir The path you want to change.
323    */
324    function chdir(dir: string): void;
325
326    /**
327    * Returns the running time of the system
328    * @since 7
329    * @syscap SystemCapability.Utils.Lang
330    * @return Return the running time of the system.
331    */
332    function uptime(): number;
333
334    /**
335    * Return whether the signal was sent successfully
336    * @since 7
337    * @syscap SystemCapability.Utils.Lang
338    * @param signal Signal sent.
339    * @param pid Send signal to target pid.
340    * @return Return the result of the signal.
341    */
342    function kill(signal: number, pid: number): boolean;
343}
344export default process;