• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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 *
20 * @namespace process
21 * @syscap SystemCapability.Utils.Lang
22 * @since 7
23 */
24/**
25 * The process is mainly used to obtain the relevant ID of the process, obtain and modify
26 * the working directory of the process, exit and close the process.
27 *
28 * @namespace process
29 * @syscap SystemCapability.Utils.Lang
30 * @crossplatform
31 * @since 10
32 */
33declare namespace process {
34  /**
35   * The childprocess object can be used to create a new process.
36   *
37   * @typedef ChildProcess
38   * @syscap SystemCapability.Utils.Lang
39   * @systemapi Hide this for inner system use
40   * @since 7
41   * @test
42   */
43  export interface ChildProcess {
44    /**
45     * Return pid is the pid of the current process
46     *
47     * @syscap SystemCapability.Utils.Lang
48     * @systemapi Hide this for inner system use
49     * @since 7
50     * @test
51     */
52    readonly pid: number;
53
54    /**
55     * Return ppid is the pid of the current child process
56     *
57     * @syscap SystemCapability.Utils.Lang
58     * @systemapi Hide this for inner system use
59     * @since 7
60     * @test
61     */
62    readonly ppid: number;
63
64    /**
65     * Return exitCode is the exit code of the current child process
66     *
67     * @syscap SystemCapability.Utils.Lang
68     * @systemapi Hide this for inner system use
69     * @since 7
70     * @test
71     */
72    readonly exitCode: number;
73
74    /**
75     * Return boolean is whether the current process signal is sent successfully
76     *
77     * @syscap SystemCapability.Utils.Lang
78     * @systemapi Hide this for inner system use
79     * @since 7
80     * @test
81     */
82    readonly killed: boolean;
83
84    /**
85     * Return 'number' is the target process exit code
86     *
87     * @returns { Promise<number> } Return the target process exit code.
88     * @syscap SystemCapability.Utils.Lang
89     * @systemapi Hide this for inner system use
90     * @since 7
91     * @test
92     */
93    wait(): Promise<number>;
94
95    /**
96     * Return it as 'Uint8Array' of the stdout until EOF
97     *
98     * @returns { Promise<Uint8Array> } Return subprocess standard output.
99     * @syscap SystemCapability.Utils.Lang
100     * @systemapi Hide this for inner system use
101     * @since 7
102     * @test
103     */
104    getOutput(): Promise<Uint8Array>;
105
106    /**
107     * Return it as 'Uint8Array of the stderr until EOF
108     *
109     * @returns { Promise<Uint8Array> } Return subprocess standard error output.
110     * @syscap SystemCapability.Utils.Lang
111     * @systemapi Hide this for inner system use
112     * @since 7
113     * @test
114     */
115    getErrorOutput(): Promise<Uint8Array>;
116
117    /**
118     * Close the target process
119     *
120     * @syscap SystemCapability.Utils.Lang
121     * @systemapi Hide this for inner system use
122     * @since 7
123     * @test
124     */
125    close(): void;
126
127    /**
128     * Send a signal to process
129     *
130     * @param { number | string } signal - Number or string represents the signal sent.
131     * @syscap SystemCapability.Utils.Lang
132     * @systemapi Hide this for inner system use
133     * @since 7
134     * @test
135     */
136    kill(signal: number | string): void;
137  }
138
139  /**
140   * Process is mainly used to obtain the relevant ID of the process, obtain and modify the
141   * working directory of the process, exit and close the process.
142   *
143   * @syscap SystemCapability.Utils.Lang
144   * @since 9
145   * @name ProcessManager
146   */
147  /**
148   * Process is mainly used to obtain the relevant ID of the process, obtain and modify the
149   * working directory of the process, exit and close the process.
150   *
151   * @syscap SystemCapability.Utils.Lang
152   * @crossplatform
153   * @since 10
154   * @name ProcessManager
155   */
156  export class ProcessManager {
157    /**
158     * Returns a boolean whether the specified uid belongs to a particular application.
159     *
160     * @param { number } v - An id.
161     * @returns { boolean } Return a boolean whether the specified uid belongs to a particular application.
162     * @throws { BusinessError } 401 - The type of v must be number.
163     * @syscap SystemCapability.Utils.Lang
164     * @since 9
165     */
166    /**
167     * Returns a boolean whether the specified uid belongs to a particular application.
168     *
169     * @param { number } v - An id.
170     * @returns { boolean } Return a boolean whether the specified uid belongs to a particular application.
171     * @throws { BusinessError } 401 - The type of v must be number.
172     * @syscap SystemCapability.Utils.Lang
173     * @crossplatform
174     * @since 10
175     */
176    isAppUid(v: number): boolean;
177
178    /**
179     * Returns the uid based on the specified user name.
180     *
181     * @param { string } v - Process name.
182     * @returns { number } Return the uid based on the specified user name.
183     * @throws { BusinessError } 401 - The type of v must be string.
184     * @syscap SystemCapability.Utils.Lang
185     * @since 9
186     */
187    /**
188     * Returns the uid based on the specified user name.
189     *
190     * @param { string } v - Process name.
191     * @returns { number } Return the uid based on the specified user name.
192     * @throws { BusinessError } 401 - The type of v must be string.
193     * @syscap SystemCapability.Utils.Lang
194     * @crossplatform
195     * @since 10
196     */
197    getUidForName(v: string): number;
198
199    /**
200     * Returns the thread priority based on the specified tid.
201     *
202     * @param { number } v - The tid of the process.
203     * @returns { number } Return the thread priority based on the specified tid.
204     * @throws { BusinessError } 401 - The type of v must be number.
205     * @syscap SystemCapability.Utils.Lang
206     * @since 9
207     */
208    /**
209     * Returns the thread priority based on the specified tid.
210     *
211     * @param { number } v - The tid of the process.
212     * @returns { number } Return the thread priority based on the specified tid.
213     * @throws { BusinessError } 401 - The type of v must be number.
214     * @syscap SystemCapability.Utils.Lang
215     * @crossplatform
216     * @since 10
217     */
218    getThreadPriority(v: number): number;
219
220    /**
221     * Returns the system configuration at runtime.
222     *
223     * @param { number } name - Parameters defined by the system configuration.
224     * @returns { number } Return the system configuration at runtime.
225     * @throws { BusinessError } 401 - The type of name must be number.
226     * @syscap SystemCapability.Utils.Lang
227     * @since 9
228     */
229    /**
230     * Returns the system configuration at runtime.
231     *
232     * @param { number } name - Parameters defined by the system configuration.
233     * @returns { number } Return the system configuration at runtime.
234     * @throws { BusinessError } 401 - The type of name must be number.
235     * @syscap SystemCapability.Utils.Lang
236     * @crossplatform
237     * @since 10
238     */
239    getSystemConfig(name: number): number;
240
241    /**
242     * Returns the system value for environment variables.
243     *
244     * @param { string } name - Parameters defined by the system environment variables.
245     * @returns { string } Return the system value for environment variables.
246     * @throws { BusinessError } 401 - The type of name must be string.
247     * @syscap SystemCapability.Utils.Lang
248     * @since 9
249     */
250    /**
251     * Returns the system value for environment variables.
252     *
253     * @param { string } name - Parameters defined by the system environment variables.
254     * @returns { string } Return the system value for environment variables.
255     * @throws { BusinessError } 401 - The type of name must be string.
256     * @syscap SystemCapability.Utils.Lang
257     * @crossplatform
258     * @since 10
259     */
260    getEnvironmentVar(name: string): string;
261
262    /**
263     * Process exit
264     *
265     * @param { number } code - Process exit code.
266     * @throws { BusinessError } 401 - The type of code must be number.
267     * @syscap SystemCapability.Utils.Lang
268     * @since 9
269     */
270    /**
271     * Process exit
272     *
273     * @param { number } code - Process exit code.
274     * @throws { BusinessError } 401 - The type of code must be number.
275     * @syscap SystemCapability.Utils.Lang
276     * @crossplatform
277     * @since 10
278     */
279    exit(code: number): void;
280
281    /**
282     * Return whether the signal was sent successfully
283     *
284     * @param { number } signal - Signal sent.
285     * @param { number } pid - Send signal to target pid.
286     * @returns { boolean } Return the result of the signal.
287     * @throws { BusinessError } 401 - if the input parameters are invalid.
288     * @syscap SystemCapability.Utils.Lang
289     * @since 9
290     */
291    /**
292     * Return whether the signal was sent successfully
293     *
294     * @param { number } signal - Signal sent.
295     * @param { number } pid - Send signal to target pid.
296     * @returns { boolean } Return the result of the signal.
297     * @throws { BusinessError } 401 - if the input parameters are invalid.
298     * @syscap SystemCapability.Utils.Lang
299     * @crossplatform
300     * @since 10
301     */
302    kill(signal: number, pid: number): boolean;
303  }
304
305  /**
306   * Returns the numeric valid group ID of the process
307   *
308   * @constant
309   * @syscap SystemCapability.Utils.Lang
310   * @systemapi Hide this for inner system use
311   * @since 7
312   * @test
313   */
314  const egid: number;
315
316  /**
317   * Return the numeric valid user identity of the process
318   *
319   * @constant
320   * @syscap SystemCapability.Utils.Lang
321   * @systemapi Hide this for inner system use
322   * @since 7
323   * @test
324   */
325  const euid: number;
326
327  /**
328   * Returns the numeric group id of the process
329   *
330   * @constant
331   * @syscap SystemCapability.Utils.Lang
332   * @systemapi Hide this for inner system use
333   * @since 7
334   * @test
335   */
336  const gid: number;
337
338  /**
339   * Returns the digital user id of the process
340   *
341   * @constant
342   * @syscap SystemCapability.Utils.Lang
343   * @since 7
344   */
345  /**
346   * Returns the digital user id of the process
347   *
348   * @constant
349   * @syscap SystemCapability.Utils.Lang
350   * @crossplatform
351   * @since 10
352   */
353  const uid: number;
354
355  /**
356   * Return an array with supplementary group id
357   *
358   * @constant
359   * @syscap SystemCapability.Utils.Lang
360   * @systemapi Hide this for inner system use
361   * @since 7
362   * @test
363   */
364  const groups: number[];
365
366  /**
367   * Return pid is The pid of the current process
368   *
369   * @constant
370   * @syscap SystemCapability.Utils.Lang
371   * @since 7
372   */
373  /**
374   * Return pid is The pid of the current process
375   *
376   * @constant
377   * @syscap SystemCapability.Utils.Lang
378   * @crossplatform
379   * @since 10
380   */
381  const pid: number;
382
383  /**
384   * Return ppid is The pid of the current child process
385   *
386   * @constant
387   * @syscap SystemCapability.Utils.Lang
388   * @systemapi Hide this for inner system use
389   * @since 7
390   * @test
391   */
392  const ppid: number;
393
394  /**
395   * Returns the tid of the current thread.
396   *
397   * @constant
398   * @syscap SystemCapability.Utils.Lang
399   * @since 8
400   */
401  /**
402   * Returns the tid of the current thread.
403   *
404   * @constant
405   * @syscap SystemCapability.Utils.Lang
406   * @crossplatform
407   * @since 10
408   */
409  const tid: number;
410
411  /**
412   * Returns a boolean whether the process is isolated.
413   *
414   * @returns { boolean } Return boolean whether the process is isolated.
415   * @syscap SystemCapability.Utils.Lang
416   * @since 8
417   */
418  function isIsolatedProcess(): boolean;
419
420  /**
421   * Returns a boolean whether the specified uid belongs to a particular application.
422   *
423   * @param { number } v - An id.
424   * @returns { boolean } Return a boolean whether the specified uid belongs to a particular application.
425   * @syscap SystemCapability.Utils.Lang
426   * @since 8
427   * @deprecated since 9
428   * @useinstead ohos.process.ProcessManager.isAppUid
429   */
430  function isAppUid(v: number): boolean;
431
432  /**
433   * Returns a boolean whether the process is running in a 64-bit environment.
434   *
435   * @returns { boolean } Return a boolean whether the process is running in a 64-bit environment.
436   * @syscap SystemCapability.Utils.Lang
437   * @since 8
438   */
439  /**
440   * Returns a boolean whether the process is running in a 64-bit environment.
441   *
442   * @returns { boolean } Return a boolean whether the process is running in a 64-bit environment.
443   * @syscap SystemCapability.Utils.Lang
444   * @crossplatform
445   * @since 10
446   */
447  function is64Bit(): boolean;
448
449  /**
450   * Returns the uid based on the specified user name.
451   *
452   * @param { string } v - Process name.
453   * @returns { number } Return the uid based on the specified user name.
454   * @syscap SystemCapability.Utils.Lang
455   * @since 8
456   * @deprecated since 9
457   * @useinstead ohos.process.ProcessManager.getUidForName
458   */
459  function getUidForName(v: string): number;
460
461  /**
462   * Returns the thread priority based on the specified tid.
463   *
464   * @param { number } v - The tid of the process.
465   * @returns { number } Return the thread priority based on the specified tid.
466   * @syscap SystemCapability.Utils.Lang
467   * @since 8
468   * @deprecated since 9
469   * @useinstead ohos.process.ProcessManager.getThreadPriority
470   */
471  function getThreadPriority(v: number): number;
472
473  /**
474   * Returns the elapsed real time (in milliseconds) taken from the start of the system to the start of the process.
475   *
476   * @returns { number } Return the start of the system to the start of the process.
477   * @syscap SystemCapability.Utils.Lang
478   * @since 8
479   */
480  /**
481   * Returns the elapsed real time (in milliseconds) taken from the start of the system to the start of the process.
482   *
483   * @returns { number } Return the start of the system to the start of the process.
484   * @syscap SystemCapability.Utils.Lang
485   * @crossplatform
486   * @since 10
487   */
488  function getStartRealtime(): number;
489
490  /**
491   * Returns the cpu time (in milliseconds) from the time when the process starts to the current time.
492   *
493   * @returns { number } Return the cpu time (in milliseconds) from the time when the process starts to the current time.
494   * @syscap SystemCapability.Utils.Lang
495   * @since 8
496   */
497  /**
498   * Returns the cpu time (in milliseconds) from the time when the process starts to the current time.
499   *
500   * @returns { number } Return the cpu time (in milliseconds) from the time when the process starts to the current time.
501   * @syscap SystemCapability.Utils.Lang
502   * @crossplatform
503   * @since 10
504   */
505  function getPastCpuTime(): number;
506
507  /**
508   * Returns the system configuration at runtime.
509   *
510   * @param { number } name - Parameters defined by the system configuration.
511   * @returns { number } Return the system configuration at runtime.
512   * @syscap SystemCapability.Utils.Lang
513   * @since 8
514   * @deprecated since 9
515   * @useinstead ohos.process.ProcessManager.getSystemConfig
516   */
517  function getSystemConfig(name: number): number;
518
519  /**
520   * Returns the system value for environment variables.
521   *
522   * @param { string } name - Parameters defined by the system environment variables.
523   * @returns { string } Return the system value for environment variables.
524   * @syscap SystemCapability.Utils.Lang
525   * @since 8
526   * @deprecated since 9
527   * @useinstead ohos.process.ProcessManager.getEnvironmentVar
528   */
529  function getEnvironmentVar(name: string): string;
530
531  /**
532   * User Stored Events
533   *
534   * @syscap SystemCapability.Utils.Lang
535   * @since 7
536   */
537  /**
538   * User Stored Events
539   *
540   * @syscap SystemCapability.Utils.Lang
541   * @crossplatform
542   * @since 10
543   */
544  type EventListener = (evt: Object) => void;
545
546  /**
547   * Provides the ConditionType type,including timeout, killSignal, maxBuffer.
548   *
549   * @typedef ConditionType
550   * @syscap SystemCapability.Utils.Lang
551   * @systemapi Hide this for inner system use
552   * @since 10
553   * @test
554   */
555  interface ConditionType {
556
557    /**
558     * Maximum running time (in ms) of the child process.
559     *
560     * @type { ?number }
561     * @syscap SystemCapability.Utils.Lang
562     * @systemapi Hide this for inner system use
563     * @since 10
564     * @test
565     */
566    timeout?: number;
567
568    /**
569     * Signal sent to the child process when the running time of a child process exceeds the timeout period.
570     *
571     * @type { ?(number | string) }
572     * @syscap SystemCapability.Utils.Lang
573     * @systemapi Hide this for inner system use
574     * @since 10
575     * @test
576     */
577    killSignal?: number | string;
578
579    /**
580     * Maximum buffer size for the standard input and output of the child process.
581     *
582     * @type { ?number }
583     * @syscap SystemCapability.Utils.Lang
584     * @systemapi Hide this for inner system use
585     * @since 10
586     * @test
587     */
588    maxBuffer?: number;
589  }
590  /**
591   * Returns a child process object and spawns a new ChildProcess to run the command.
592   *
593   * @param { string } command - String of the shell commands executed by the child process.
594   * @param { ConditionType } options - This is an object. The object contains three parameters. Timeout is the running time of the child
595   * process, killSignal is the signal sent when the child process reaches timeout, and maxBuffer is the size of the
596   * maximum buffer area for standard input and output.
597   * @returns { ChildProcess } Returns a child process object.
598   * @syscap SystemCapability.Utils.Lang
599   * @systemapi Hide this for inner system use
600   * @since 7
601   * @test
602   */
603  function runCmd(
604    command: string,
605    options?: ConditionType
606  ): ChildProcess;
607
608  /**
609   * Abort current process
610   *
611   * @syscap SystemCapability.Utils.Lang
612   * @since 7
613   */
614  /**
615   * Abort current process
616   *
617   * @syscap SystemCapability.Utils.Lang
618   * @crossplatform
619   * @since 10
620   */
621  function abort(): void;
622
623  /**
624   * Register for an event
625   *
626   * @param { string } type - Indicates the type of event registered.
627   * @param { EventListener } listener - Represents the registered event function
628   * @syscap SystemCapability.Utils.Lang
629   * @systemapi Hide this for inner system use
630   * @since 7
631   * @test
632   */
633  function on(type: string, listener: EventListener): void;
634
635  /**
636   * Remove registered event
637   *
638   * @param { string } type - Remove the type of registered event.
639   * @returns { boolean } Return removed result.
640   * @syscap SystemCapability.Utils.Lang
641   * @systemapi Hide this for inner system use
642   * @since 7
643   * @test
644   */
645  function off(type: string): boolean;
646
647  /**
648   * Process exit
649   *
650   * @param { number } code - Process exit code.
651   * @syscap SystemCapability.Utils.Lang
652   * @since 7
653   * @deprecated since 9
654   * @useinstead ohos.process.ProcessManager.exit
655   */
656  function exit(code: number): void;
657
658  /**
659   * Return the current work directory;
660   *
661   * @returns { string } Return the current work directory.
662   * @syscap SystemCapability.Utils.Lang
663   * @systemapi Hide this for inner system use
664   * @since 7
665   * @test
666   */
667  function cwd(): string;
668
669  /**
670   * Change current directory
671   *
672   * @param { string } dir - The path you want to change.
673   * @syscap SystemCapability.Utils.Lang
674   * @systemapi Hide this for inner system use
675   * @since 7
676   * @test
677   */
678  function chdir(dir: string): void;
679
680  /**
681   * Returns the running time of the system
682   *
683   * @returns { number } Return the running time of the system.
684   * @syscap SystemCapability.Utils.Lang
685   * @since 7
686   */
687  /**
688   * Returns the running time of the system
689   *
690   * @returns { number } Return the running time of the system.
691   * @syscap SystemCapability.Utils.Lang
692   * @crossplatform
693   * @since 10
694   */
695  function uptime(): number;
696
697  /**
698   * Return whether the signal was sent successfully
699   *
700   * @param { number } signal - Signal sent.
701   * @param { number } pid - Send signal to target pid.
702   * @returns { boolean } Return the result of the signal.
703   * @syscap SystemCapability.Utils.Lang
704   * @since 7
705   * @deprecated since 9
706   * @useinstead ohos.process.ProcessManager.kill
707   */
708  function kill(signal: number, pid: number): boolean;
709}
710export default process;
711