1# @ohos.process (Obtaining Process Information) 2 3> **NOTE** 4> 5> 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. 6 7 8## Modules to Import 9 10``` 11import process from '@ohos.process'; 12``` 13 14 15## Attributes 16 17**System capability**: SystemCapability.Utils.Lang 18 19| Name| Type| Readable| Writable| Description| 20| -------- | -------- | -------- | -------- | -------- | 21| uid | number | Yes| No| User identifier (UID) of the process.| 22| pid | number | Yes| No| Process ID (PID) of the process.| 23| tid<sup>8+</sup> | number | Yes| No| Thread ID (TID) of the thread.| 24 25 26## EventListener 27 28**System capability**: SystemCapability.Utils.Lang 29 30| Name| Description| 31| -------- | -------- | 32| EventListener = (evt: Object) => void | Event to store.| 33 34 35## process.isIsolatedProcess<sup>8+</sup> 36 37isIsolatedProcess(): boolean 38 39Checks whether this process is isolated. 40 41**System capability**: SystemCapability.Utils.Lang 42 43**Return value** 44 45| Type| Description| 46| -------- | -------- | 47| boolean | Returns **true** if the process is isolated; returns **false** otherwise.| 48 49**Example** 50 51```js 52let result = process.isIsolatedProcess(); 53``` 54 55 56## process.is64Bit<sup>8+</sup> 57 58is64Bit(): boolean 59 60Checks whether this process is running in a 64-bit environment. 61 62**System capability**: SystemCapability.Utils.Lang 63 64**Return value** 65 66| Type| Description| 67| -------- | -------- | 68| boolean | Returns **true** if the process is running in a 64-bit environment; returns **false** otherwise.| 69 70**Example** 71 72```js 73let result = process.is64Bit(); 74``` 75 76 77## process.getStartRealtime<sup>8+</sup> 78 79getStartRealtime(): number 80 81Obtains the duration, in milliseconds, from the time the system starts to the time the process starts. 82 83**System capability**: SystemCapability.Utils.Lang 84 85**Return value** 86 87| Type| Description| 88| -------- | -------- | 89| number | Duration obtained, in millisecond.| 90 91**Example** 92 93```js 94let realtime = process.getStartRealtime(); 95``` 96 97## process.getPastCpuTime<sup>8+</sup> 98 99getPastCpuTime(): number 100 101Obtains the CPU time (in milliseconds) from the time the process starts to the current time. 102 103**System capability**: SystemCapability.Utils.Lang 104 105**Return value** 106 107| Type| Description| 108| -------- | -------- | 109| number | CPU time obtained, in millisecond.| 110 111**Example** 112 113```js 114let result = process.getPastCpuTime() ; 115``` 116 117 118## process.abort 119 120abort(): void 121 122Aborts a process and generates a core file. This method will cause a process to exit immediately. Exercise caution when using this method. 123 124**System capability**: SystemCapability.Utils.Lang 125 126**Example** 127 128```js 129process.abort(); 130``` 131 132 133## process.uptime 134 135uptime(): number 136 137Obtains the running time of this process. 138 139**System capability**: SystemCapability.Utils.Lang 140 141**Return value** 142 143| Type| Description| 144| -------- | -------- | 145| number | Running time of the process, in seconds.| 146 147**Example** 148 149```js 150let time = process.uptime(); 151``` 152 153 154## process.kill<sup>(deprecated)</sup> 155 156kill(signal: number, pid: number): boolean 157 158Sends a signal to the specified process to terminate it. 159 160> **NOTE** 161> 162> 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. 163 164**System capability**: SystemCapability.Utils.Lang 165 166**Parameters** 167 168| Name| Type| Mandatory| Description| 169| -------- | -------- | -------- | -------- | 170| pid | number | Yes| PID of the process, to which the signal will be sent.| 171| signal | number | Yes| Signal to send.| 172 173**Return value** 174 175| Type| Description| 176| -------- | -------- | 177| boolean | Returns **true** if the signal is sent successfully; returns **false** otherwise.| 178 179**Example** 180 181```js 182let pres = process.pid 183let result = process.kill(28, pres) 184``` 185 186 187## process.exit<sup>(deprecated)</sup> 188 189exit(code: number): void 190 191Terminates this process. 192 193Exercise 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. 194 195> **NOTE** 196> 197> 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. 198 199**System capability**: SystemCapability.Utils.Lang 200 201**Parameters** 202 203| Name| Type| Mandatory| Description| 204| -------- | -------- | -------- | -------- | 205| code | number | Yes| Exit code of the process.| 206 207**Example** 208 209```js 210process.exit(0); 211``` 212 213 214## process.getUidForName<sup>(deprecated)</sup> 215 216getUidForName(v: string): number 217 218Obtains the process UID based on the process name. 219 220> **NOTE** 221> 222> 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. 223 224**System capability**: SystemCapability.Utils.Lang 225 226**Parameters** 227 228| Name| Type| Mandatory| Description| 229| -------- | -------- | -------- | -------- | 230| v | string | Yes| Name of a process.| 231 232**Return value** 233 234| Type| Description| 235| -------- | -------- | 236| number | Process UID.| 237 238**Example** 239 240```js 241let pres = process.getUidForName("tool") 242``` 243 244 245## process.getThreadPriority<sup>(deprecated)</sup> 246 247getThreadPriority(v: number): number 248 249Obtains the thread priority based on the specified TID. 250 251> **NOTE** 252> 253> 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. 254 255**System capability**: SystemCapability.Utils.Lang 256 257**Parameters** 258 259| Name| Type| Mandatory| Description| 260| -------- | -------- | -------- | -------- | 261| v | number | Yes| TID.| 262 263**Return value** 264 265| Type| Description| 266| -------- | -------- | 267| number | Priority of the thread.| 268 269**Example** 270 271```js 272let tid = process.tid; 273let pres = process.getThreadPriority(tid); 274``` 275 276 277## process.isAppUid<sup>(deprecated)</sup> 278 279isAppUid(v: number): boolean 280 281Checks whether a UID belongs to this application. 282 283> **NOTE** 284> 285> 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. 286 287**System capability**: SystemCapability.Utils.Lang 288 289**Parameters** 290 291| Name| Type| Mandatory| Description| 292| -------- | -------- | -------- | -------- | 293| v | number | Yes| UID.| 294 295**Return value** 296 297| Type| Description| 298| -------- | -------- | 299| boolean | Returns **true** if the UID belongs to the application; returns **false** otherwise.| 300 301**Example** 302 303```js 304let result = process.isAppUid(688); 305``` 306 307 308## process.getSystemConfig<sup>(deprecated)</sup> 309 310getSystemConfig(name: number): number 311 312Obtains the system configuration. 313 314> **NOTE** 315> 316> 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. 317 318**System capability**: SystemCapability.Utils.Lang 319 320**Parameters** 321 322| Name| Type| Mandatory| Description| 323| -------- | -------- | -------- | -------- | 324| name | number | Yes| System configuration parameter name.| 325 326**Return value** 327 328| Type| Description| 329| -------- | -------- | 330| number | System configuration obtained.| 331 332**Example** 333 334```js 335let _SC_ARG_MAX = 0 336let pres = process.getSystemConfig(_SC_ARG_MAX) 337``` 338 339 340## process.getEnvironmentVar<sup>(deprecated)</sup> 341 342getEnvironmentVar(name: string): string 343 344Obtains the value of an environment variable. 345 346> **NOTE** 347> 348> 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. 349 350**System capability**: SystemCapability.Utils.Lang 351 352**Parameters** 353 354| Name| Type| Mandatory| Description| 355| -------- | -------- | -------- | -------- | 356| name | string | Yes| Environment variable name.| 357 358**Return value** 359 360| Type| Description| 361| -------- | -------- | 362| string | Value of the environment variable.| 363 364**Example** 365 366```js 367let pres = process.getEnvironmentVar("PATH") 368``` 369 370 371## ProcessManager<sup>9+</sup> 372 373Provides APIs for throwing exceptions during the addition of a process. 374 375A **ProcessManager** object is obtained through its own constructor. 376 377### isAppUid<sup>9+</sup> 378 379isAppUid(v: number): boolean 380 381Checks whether a UID belongs to this application. 382 383**System capability**: SystemCapability.Utils.Lang 384 385**Parameters** 386 387| Name| Type| Mandatory| Description| 388| -------- | -------- | -------- | -------- | 389| v | number | Yes| UID.| 390 391**Return value** 392 393| Type| Description| 394| -------- | -------- | 395| boolean | Returns **true** if the UID belongs to the application; returns **false** otherwise.| 396 397**Example** 398 399```js 400let pro = new process.ProcessManager(); 401let result = pro.isAppUid(688); 402``` 403 404 405### getUidForName<sup>9+</sup> 406 407getUidForName(v: string): number 408 409Obtains the process UID based on the process name. 410 411**System capability**: SystemCapability.Utils.Lang 412 413**Parameters** 414 415| Name| Type| Mandatory| Description| 416| -------- | -------- | -------- | -------- | 417| v | string | Yes| Name of a process.| 418 419**Return value** 420 421| Type| Description| 422| -------- | -------- | 423| number | Process UID.| 424 425**Example** 426 427```js 428let pro = new process.ProcessManager(); 429let pres = pro .getUidForName("tool"); 430``` 431 432 433### getThreadPriority<sup>9+</sup> 434 435getThreadPriority(v: number): number 436 437Obtains the thread priority based on the specified TID. 438 439**System capability**: SystemCapability.Utils.Lang 440 441**Parameters** 442 443| Name| Type| Mandatory| Description| 444| -------- | -------- | -------- | -------- | 445| v | number | Yes| TID.| 446 447**Return value** 448 449| Type| Description| 450| -------- | -------- | 451| number | Priority of the thread.| 452 453**Example** 454 455```js 456let pro = new process.ProcessManager(); 457let tid = process.tid; 458let pres = pro.getThreadPriority(tid); 459``` 460 461 462### getSystemConfig<sup>9+</sup> 463 464getSystemConfig(name: number): number 465 466Obtains the system configuration. 467 468**System capability**: SystemCapability.Utils.Lang 469 470**Parameters** 471 472| Name| Type| Mandatory| Description| 473| -------- | -------- | -------- | -------- | 474| name | number | Yes| System configuration parameter name.| 475 476**Return value** 477 478| Type| Description| 479| -------- | -------- | 480| number | System configuration obtained.| 481 482**Example** 483 484```js 485let pro = new process.ProcessManager(); 486let _SC_ARG_MAX = 0; 487let pres = pro.getSystemConfig(_SC_ARG_MAX); 488``` 489 490 491### getEnvironmentVar<sup>9+</sup> 492 493getEnvironmentVar(name: string): string 494 495Obtains the value of an environment variable. 496 497**System capability**: SystemCapability.Utils.Lang 498 499**Parameters** 500 501| Name| Type| Mandatory| Description| 502| -------- | -------- | -------- | -------- | 503| name | string | Yes| Environment variable name.| 504 505**Return value** 506 507| Type| Description| 508| -------- | -------- | 509| string | Value of the environment variable.| 510 511**Example** 512 513```js 514let pro = new process.ProcessManager(); 515let pres = pro.getEnvironmentVar("PATH"); 516``` 517 518 519### exit<sup>9+</sup> 520 521exit(code: number): void 522 523Terminates this process. 524 525Exercise 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. 526 527**System capability**: SystemCapability.Utils.Lang 528 529**Parameters** 530 531| Name| Type| Mandatory| Description| 532| -------- | -------- | -------- | -------- | 533| code | number | Yes| Exit code of the process.| 534 535**Example** 536 537```js 538let pro = new process.ProcessManager(); 539pro.exit(0); 540``` 541 542 543### kill<sup>9+</sup> 544 545kill(signal: number, pid: number): boolean 546 547Sends a signal to the specified process to terminate it. 548 549**System capability**: SystemCapability.Utils.Lang 550 551**Parameters** 552 553| Name| Type| Mandatory| Description| 554| -------- | -------- | -------- | -------- | 555| pid | number | Yes| PID of the process, to which the signal will be sent.| 556| signal | number | Yes| Signal to send.| 557 558**Return value** 559 560| Type| Description| 561| -------- | -------- | 562| boolean | Returns **true** if the signal is sent successfully; returns **false** otherwise.| 563 564**Example** 565 566```js 567let pro = new process.ProcessManager(); 568let pres = process.pid; 569let result = pro.kill(28, pres); 570``` 571