1e41f4b71Sopenharmony_ci# @ohos.process (Obtaining Process Information)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **process** module provides process management APIs, for example, APIs for obtaining process information.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport { process } from '@kit.ArkTS';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## Attributes
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name            | Type  | Readable | Writable | Description            |
24e41f4b71Sopenharmony_ci| ---------------- | ------ | ---- | ---- | ---------------- |
25e41f4b71Sopenharmony_ci| uid              | number | Yes  | No  | User identifier (UID) of the process. |
26e41f4b71Sopenharmony_ci| pid              | number | Yes  | No  | Process ID (PID) of the process. |
27e41f4b71Sopenharmony_ci| tid<sup>8+</sup> | number | Yes  | No  | Thread ID (TID) of the thread. |
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci## EventListener
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_citype EventListener = (evt: Object) => void
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ciDescribes the event to store.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci**Parameters**
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description           |
43e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
44e41f4b71Sopenharmony_ci| evt   | Object | Yes | Event.|
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci## process.isIsolatedProcess<sup>8+</sup>
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ciisIsolatedProcess(): boolean
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ciChecks whether this process is isolated.
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci**Return value**
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci| Type   | Description                                                   |
59e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------- |
60e41f4b71Sopenharmony_ci| boolean | **true**: The process is isolated.<br>**false**: The process is not isolated. |
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**Example**
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci```js
65e41f4b71Sopenharmony_cilet result = process.isIsolatedProcess();
66e41f4b71Sopenharmony_ci```
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci## process.is64Bit<sup>8+</sup>
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciis64Bit(): boolean
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ciChecks whether this process is running in a 64-bit environment.
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**Return value**
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci| Type   | Description                                                       |
82e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------- |
83e41f4b71Sopenharmony_ci| boolean | **true**: The process is running in a 64-bit environment.<br>**false**: The process is not running in a 64-bit environment. |
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**Example**
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci```js
88e41f4b71Sopenharmony_cilet result = process.is64Bit();
89e41f4b71Sopenharmony_ci```
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci## process.getStartRealtime<sup>8+</sup>
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_cigetStartRealtime(): number
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ciObtains the duration, in milliseconds, from the time the system starts to the time the process starts.
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**Return value**
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci| Type  | Description                          |
105e41f4b71Sopenharmony_ci| ------ | ------------------------------ |
106e41f4b71Sopenharmony_ci| number | Duration obtained, in millisecond. |
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**Example**
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci```js
111e41f4b71Sopenharmony_cilet realtime = process.getStartRealtime();
112e41f4b71Sopenharmony_ci```
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci## process.getPastCpuTime<sup>8+</sup>
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_cigetPastCpuTime(): number
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ciObtains the CPU time (in milliseconds) from the time the process starts to the current time.
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**Return value**
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci| Type  | Description                         |
127e41f4b71Sopenharmony_ci| ------ | ----------------------------- |
128e41f4b71Sopenharmony_ci| number | CPU time obtained, in millisecond. |
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Example**
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci```js
133e41f4b71Sopenharmony_cilet result = process.getPastCpuTime() ;
134e41f4b71Sopenharmony_ci```
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci## process.abort
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ciabort(): void
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ciAborts a process and generates a core file. This method will cause a process to exit immediately. Exercise caution when using this method.
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci**Example**
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci```js
150e41f4b71Sopenharmony_ciprocess.abort();
151e41f4b71Sopenharmony_ci```
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci## process.uptime
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ciuptime(): number
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ciObtains the running time of this process.
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci**Return value**
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci| Type  | Description                  |
167e41f4b71Sopenharmony_ci| ------ | ---------------------- |
168e41f4b71Sopenharmony_ci| number | Running time of the process, in seconds. |
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**Example**
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci```js
173e41f4b71Sopenharmony_cilet time = process.uptime();
174e41f4b71Sopenharmony_ci```
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci## process.kill<sup>(deprecated)</sup>
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_cikill(signal: number, pid: number): boolean
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ciSends a signal to the specified process to terminate it.
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci> **NOTE**
184e41f4b71Sopenharmony_ci>
185e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [kill<sup>9+</sup>](#kill9) instead.
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci**Parameters**
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description        |
192e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------ |
193e41f4b71Sopenharmony_ci| signal | number | Yes  | Signal to send. |
194e41f4b71Sopenharmony_ci| pid    | number | Yes  | PID of the process, to which the signal will be sent.  |
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci**Return value**
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci| Type   | Description                                                        |
199e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
200e41f4b71Sopenharmony_ci| boolean |  **true**: The signal is sent successfully.<br>**false**: The signal fails to be sent. |
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**Example**
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci```js
205e41f4b71Sopenharmony_cilet pres = process.pid
206e41f4b71Sopenharmony_cilet result = process.kill(28, pres)
207e41f4b71Sopenharmony_ci```
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci## process.exit<sup>(deprecated)</sup>
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ciexit(code: number): void
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ciTerminates this process.
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ciExercise caution when using this API. After this API is called, the application exits. If the input parameter is not 0, data loss or exceptions may occur.
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci> **NOTE**
219e41f4b71Sopenharmony_ci>
220e41f4b71Sopenharmony_ci> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [exit<sup>9+</sup>](#exit9) instead.
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci**Parameters**
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description          |
227e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- |
228e41f4b71Sopenharmony_ci| code   | number | Yes  | Exit code of the process. |
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**Example**
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci```js
233e41f4b71Sopenharmony_ciprocess.exit(0);
234e41f4b71Sopenharmony_ci```
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci## process.getUidForName<sup>(deprecated)</sup>
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_cigetUidForName(v: string): number
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ciObtains the UID of a user from the user database of the system based on the specified user name.
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ci> **NOTE**
244e41f4b71Sopenharmony_ci>
245e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getUidForName<sup>9+</sup>](#getuidforname9) instead.
246e41f4b71Sopenharmony_ci
247e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci**Parameters**
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description    |
252e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------- |
253e41f4b71Sopenharmony_ci| v      | string | Yes  | User name. |
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci**Return value**
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci| Type  | Description         |
258e41f4b71Sopenharmony_ci| ------ | ------------- |
259e41f4b71Sopenharmony_ci| number | UID of the user. |
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci**Example**
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci```js
264e41f4b71Sopenharmony_cilet pres = process.getUidForName("tool")
265e41f4b71Sopenharmony_ci```
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci## process.getThreadPriority<sup>(deprecated)</sup>
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_cigetThreadPriority(v: number): number
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ciObtains the thread priority based on the specified TID.
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ci> **NOTE**
275e41f4b71Sopenharmony_ci>
276e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getThreadPriority<sup>9+</sup>](#getthreadpriority9) instead.
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci**Parameters**
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description           |
283e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
284e41f4b71Sopenharmony_ci| v      | number | Yes  | TID. |
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci**Return value**
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci| Type  | Description                                            |
289e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------ |
290e41f4b71Sopenharmony_ci| number | Priority of the thread. The priority depends on the operating system. |
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci**Example**
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci```js
295e41f4b71Sopenharmony_cilet tid = process.tid;
296e41f4b71Sopenharmony_cilet pres = process.getThreadPriority(tid);
297e41f4b71Sopenharmony_ci```
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci## process.isAppUid<sup>(deprecated)</sup>
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ciisAppUid(v: number): boolean
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ciChecks whether a UID belongs to this application.
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci> **NOTE**
307e41f4b71Sopenharmony_ci>
308e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [isAppUid<sup>9+</sup>](#isappuid9) instead.
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci**Parameters**
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description           |
315e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
316e41f4b71Sopenharmony_ci| v      | number | Yes  | UID. |
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci**Return value**
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci| Type   | Description                                                        |
321e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
322e41f4b71Sopenharmony_ci| boolean | **true**: The UID belongs to the application.<br>**false**: The UID does not belong to the application. |
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci**Example**
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci```js
327e41f4b71Sopenharmony_cilet result = process.isAppUid(688);
328e41f4b71Sopenharmony_ci```
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci## process.getSystemConfig<sup>(deprecated)</sup>
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_cigetSystemConfig(name: number): number
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ciObtains the system configuration.
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci> **NOTE**
338e41f4b71Sopenharmony_ci>
339e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getSystemConfig<sup>9+</sup>](#getsystemconfig9) instead.
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci**Parameters**
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                |
346e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- |
347e41f4b71Sopenharmony_ci| name   | number | Yes  | System configuration parameter name. |
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci**Return value**
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci| Type  | Description              |
352e41f4b71Sopenharmony_ci| ------ | ------------------ |
353e41f4b71Sopenharmony_ci| number | System configuration obtained. |
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ci**Example**
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci```js
358e41f4b71Sopenharmony_cilet _SC_ARG_MAX = 0
359e41f4b71Sopenharmony_cilet pres = process.getSystemConfig(_SC_ARG_MAX)
360e41f4b71Sopenharmony_ci```
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci## process.getEnvironmentVar<sup>(deprecated)</sup>
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_cigetEnvironmentVar(name: string): string
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ciObtains the value of an environment variable.
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ci> **NOTE**
370e41f4b71Sopenharmony_ci>
371e41f4b71Sopenharmony_ci> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEnvironmentVar<sup>9+</sup>](#getenvironmentvar9) instead.
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci**Parameters**
376e41f4b71Sopenharmony_ci
377e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description        |
378e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------ |
379e41f4b71Sopenharmony_ci| name   | string | Yes  | Environment variable name. |
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci**Return value**
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ci| Type  | Description                       |
384e41f4b71Sopenharmony_ci| ------ | --------------------------- |
385e41f4b71Sopenharmony_ci| string | Value of the environment variable. |
386e41f4b71Sopenharmony_ci
387e41f4b71Sopenharmony_ci**Example**
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci```js
390e41f4b71Sopenharmony_cilet pres = process.getEnvironmentVar("PATH")
391e41f4b71Sopenharmony_ci```
392e41f4b71Sopenharmony_ci
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci## ProcessManager<sup>9+</sup>
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ciProvides APIs for throwing exceptions during the addition of a process.
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ciA **ProcessManager** object is obtained through its own constructor.
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci### isAppUid<sup>9+</sup>
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ciisAppUid(v: number): boolean
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ciChecks whether a UID belongs to this application.
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci**Parameters**
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description           |
413e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
414e41f4b71Sopenharmony_ci| v      | number | Yes  | UID, which can be obtained by running **process.uid**. |
415e41f4b71Sopenharmony_ci
416e41f4b71Sopenharmony_ci**Return value**
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci| Type   | Description                                                        |
419e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
420e41f4b71Sopenharmony_ci| boolean | **true**: The UID belongs to the application.<br>**false**: The UID does not belong to the application. |
421e41f4b71Sopenharmony_ci
422e41f4b71Sopenharmony_ci**Error codes**
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_ci| ID | Error Message |
427e41f4b71Sopenharmony_ci| -------- | -------- |
428e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
429e41f4b71Sopenharmony_ci
430e41f4b71Sopenharmony_ci**Example**
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_ci```js
433e41f4b71Sopenharmony_cilet pro = new process.ProcessManager();
434e41f4b71Sopenharmony_ci// Use process.uid to obtain the UID.
435e41f4b71Sopenharmony_cilet pres = process.uid;
436e41f4b71Sopenharmony_cilet result = pro.isAppUid(pres);
437e41f4b71Sopenharmony_ciconsole.log("result: " + result); // result: true
438e41f4b71Sopenharmony_ci```
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci### getUidForName<sup>9+</sup>
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_cigetUidForName(v: string): number
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ciObtains the UID of a user from the user database of the system based on the specified user name.
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci**Parameters**
452e41f4b71Sopenharmony_ci
453e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description    |
454e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------- |
455e41f4b71Sopenharmony_ci| v      | string | Yes  | User name. |
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci**Return value**
458e41f4b71Sopenharmony_ci
459e41f4b71Sopenharmony_ci| Type  | Description         |
460e41f4b71Sopenharmony_ci| ------ | ------------- |
461e41f4b71Sopenharmony_ci| number | UID of the user. If the user does not exist, **-1** is returned.|
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci**Error codes**
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci| ID | Error Message |
468e41f4b71Sopenharmony_ci| -------- | -------- |
469e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
470e41f4b71Sopenharmony_ci
471e41f4b71Sopenharmony_ci**Example**
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_ci```js
474e41f4b71Sopenharmony_cilet pro = new process.ProcessManager();
475e41f4b71Sopenharmony_cilet pres = pro .getUidForName("tool");
476e41f4b71Sopenharmony_ci```
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci
479e41f4b71Sopenharmony_ci### getThreadPriority<sup>9+</sup>
480e41f4b71Sopenharmony_ci
481e41f4b71Sopenharmony_cigetThreadPriority(v: number): number
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ciObtains the thread priority based on the specified TID.
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
486e41f4b71Sopenharmony_ci
487e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
488e41f4b71Sopenharmony_ci
489e41f4b71Sopenharmony_ci**Parameters**
490e41f4b71Sopenharmony_ci
491e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description           |
492e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
493e41f4b71Sopenharmony_ci| v      | number | Yes  | TID. |
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ci**Return value**
496e41f4b71Sopenharmony_ci
497e41f4b71Sopenharmony_ci| Type  | Description                                            |
498e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------ |
499e41f4b71Sopenharmony_ci| number | Priority of the thread. The priority depends on the operating system. |
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_ci**Error codes**
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ci| ID | Error Message |
506e41f4b71Sopenharmony_ci| -------- | -------- |
507e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci**Example**
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ci```js
512e41f4b71Sopenharmony_cilet pro = new process.ProcessManager();
513e41f4b71Sopenharmony_cilet tid = process.tid;
514e41f4b71Sopenharmony_cilet pres = pro.getThreadPriority(tid);
515e41f4b71Sopenharmony_ci```
516e41f4b71Sopenharmony_ci
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ci### getSystemConfig<sup>9+</sup>
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_cigetSystemConfig(name: number): number
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ciObtains the system configuration.
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci**Parameters**
529e41f4b71Sopenharmony_ci
530e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                |
531e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- |
532e41f4b71Sopenharmony_ci| name   | number | Yes  | System configuration parameter name. |
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ci**Return value**
535e41f4b71Sopenharmony_ci
536e41f4b71Sopenharmony_ci| Type  | Description              |
537e41f4b71Sopenharmony_ci| ------ | ------------------ |
538e41f4b71Sopenharmony_ci| number | System configuration obtained. If the system configuration does not exist, **-1** is returned. |
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ci**Error codes**
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci| ID | Error Message |
545e41f4b71Sopenharmony_ci| -------- | -------- |
546e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_ci**Example**
549e41f4b71Sopenharmony_ci
550e41f4b71Sopenharmony_ci```js
551e41f4b71Sopenharmony_cilet pro = new process.ProcessManager();
552e41f4b71Sopenharmony_cilet _SC_ARG_MAX = 0;
553e41f4b71Sopenharmony_cilet pres = pro.getSystemConfig(_SC_ARG_MAX);
554e41f4b71Sopenharmony_ci```
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci
557e41f4b71Sopenharmony_ci### getEnvironmentVar<sup>9+</sup>
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_cigetEnvironmentVar(name: string): string
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_ciObtains the value of an environment variable.
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ci> **NOTE**
564e41f4b71Sopenharmony_ci>
565e41f4b71Sopenharmony_ci>  If the environment variable does not exist, **undefined** is returned.
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
568e41f4b71Sopenharmony_ci
569e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
570e41f4b71Sopenharmony_ci
571e41f4b71Sopenharmony_ci**Parameters**
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description        |
574e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------ |
575e41f4b71Sopenharmony_ci| name   | string | Yes  | Environment variable name. |
576e41f4b71Sopenharmony_ci
577e41f4b71Sopenharmony_ci**Return value**
578e41f4b71Sopenharmony_ci
579e41f4b71Sopenharmony_ci| Type  | Description                    |
580e41f4b71Sopenharmony_ci| ------ | ------------------------ |
581e41f4b71Sopenharmony_ci| string | Value of the environment variable. |
582e41f4b71Sopenharmony_ci
583e41f4b71Sopenharmony_ci**Error codes**
584e41f4b71Sopenharmony_ci
585e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci| ID | Error Message |
588e41f4b71Sopenharmony_ci| -------- | -------- |
589e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci**Example**
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci```js
594e41f4b71Sopenharmony_cilet pro = new process.ProcessManager();
595e41f4b71Sopenharmony_cilet pres = pro.getEnvironmentVar("PATH");
596e41f4b71Sopenharmony_ci```
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci
599e41f4b71Sopenharmony_ci### exit<sup>9+</sup>
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ciexit(code: number): void
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ciTerminates this process.
604e41f4b71Sopenharmony_ci
605e41f4b71Sopenharmony_ciExercise caution when using this API. After this API is called, the application exits. If the input parameter is not 0, data loss or exceptions may occur.
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
608e41f4b71Sopenharmony_ci
609e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_ci**Parameters**
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description          |
614e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- |
615e41f4b71Sopenharmony_ci| code   | number | Yes  | Exit code of the process. |
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_ci**Error codes**
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci| ID | Error Message |
622e41f4b71Sopenharmony_ci| -------- | -------- |
623e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci**Example**
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_ci```js
628e41f4b71Sopenharmony_cilet pro = new process.ProcessManager();
629e41f4b71Sopenharmony_cipro.exit(0);
630e41f4b71Sopenharmony_ci```
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci### kill<sup>9+</sup>
634e41f4b71Sopenharmony_ci
635e41f4b71Sopenharmony_cikill(signal: number, pid: number): boolean
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_ciSends a signal to the specified process to terminate it.
638e41f4b71Sopenharmony_ci
639e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
640e41f4b71Sopenharmony_ci
641e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Utils.Lang
642e41f4b71Sopenharmony_ci
643e41f4b71Sopenharmony_ci**Parameters**
644e41f4b71Sopenharmony_ci
645e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description        |
646e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------ |
647e41f4b71Sopenharmony_ci| signal | number | Yes  | Signal to send. |
648e41f4b71Sopenharmony_ci| pid    | number | Yes  | PID of the process, to which the signal will be sent.  |
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ci**Return value**
651e41f4b71Sopenharmony_ci
652e41f4b71Sopenharmony_ci| Type   | Description                                                        |
653e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
654e41f4b71Sopenharmony_ci| boolean |  **true**: The signal is sent successfully.<br>**false**: The signal fails to be sent. |
655e41f4b71Sopenharmony_ci
656e41f4b71Sopenharmony_ci**Error codes**
657e41f4b71Sopenharmony_ci
658e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci| ID | Error Message |
661e41f4b71Sopenharmony_ci| -------- | -------- |
662e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
663e41f4b71Sopenharmony_ci
664e41f4b71Sopenharmony_ci**Example**
665e41f4b71Sopenharmony_ci
666e41f4b71Sopenharmony_ci```js
667e41f4b71Sopenharmony_cilet pro = new process.ProcessManager();
668e41f4b71Sopenharmony_cilet pres = process.pid;
669e41f4b71Sopenharmony_cilet result = pro.kill(28, pres);
670e41f4b71Sopenharmony_ci```
671