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