1# BackgroundProcessManager 2 3 4## Overview 5 6The **BackgroundProcessManager** module provides C APIs for managing the scheduling policy of background child processes. 7 8**Since**: 15 9 10 11## Summary 12 13 14### Files 15 16| Name| Description| 17| -------- | -------- | 18| [background_process_manager.h](background__process__manager_8h.md) | The **background_process_manager.h** file declares the APIs for background child process management. You can use these APIs to suppress and unsuppress child processes to prevent child processes from occupying too many system resources and causing system stuttering. The APIs take effect only for the child processes created through [OH_Ability_StartNativeChildProcess](../apis-ability-kit/c-apis-ability-childprocess.md#oh_ability_startnativechildprocess). | 19 20 21### Types 22 23| Name| Description| 24| -------- | -------- | 25| typedef enum [BackgroundProcessManager_ProcessPriority](#backgroundprocessmanager_processpriority) [BackgroundProcessManager_ProcessPriority](#backgroundprocessmanager_processpriority) | Defines an enum for the child process priority. | 26| typedef enum [BackgroundProcessManager_ErrorCode](#backgroundprocessmanager_errorcode) [BackgroundProcessManager_ErrorCode](#backgroundprocessmanager_errorcode) | Defines an enum for the error codes used by the background child process management. | 27 28 29### Enums 30 31| Name| Description| 32| -------- | -------- | 33| [BackgroundProcessManager_ProcessPriority](#backgroundprocessmanager_processpriority) { PROCESS_BACKGROUND = 1, PROCESS_INACTIVE = 2 } | Enumerates child process priorities. | 34| [BackgroundProcessManager_ErrorCode](#backgroundprocessmanager_errorcode) { ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS = 0, ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM = 401, ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR = 31800001 } | Enumerates the error codes used by the background child process management. | 35 36 37### Functions 38 39| Name| Description| 40| -------- | -------- | 41| int [OH_BackgroundProcessManager_SetProcessPriority](#oh_backgroundprocessmanager_setprocesspriority) (int pid, [BackgroundProcessManager_ProcessPriority](#backgroundprocessmanager_processpriority) priority) | Sets the child process priority. After a child process is suppressed, the CPU resources that can be obtained will be limited. If the scheduling policy of the main process changes, for example, from the background to the foreground, the child process changes with the main process. To suppress the child process, call this API again. | 42| int [OH_BackgroundProcessManager_ResetProcessPriority](#oh_backgroundprocessmanager_resetprocesspriority) (int pid) | Unsuppresses the child process. In this case, the child process follows the scheduling policy of the main process. If the scheduling policy of the main process changes, for example, from the background to the foreground, the child process changes with the main process. The effect is the same as calling **resetProcessPriority**. | 43 44 45## Type Description 46 47 48### BackgroundProcessManager_ErrorCode 49 50``` 51typedef enum BackgroundProcessManager_ErrorCodeBackgroundProcessManager_ErrorCode 52``` 53**Description** 54 55Defines an enum for the error codes used by the background child process management. 56 57**Since**: 15 58 59 60### BackgroundProcessManager_ProcessPriority 61 62``` 63typedef enum BackgroundProcessManager_ProcessPriorityBackgroundProcessManager_ProcessPriority 64``` 65**Description** 66 67Defines an enum for the child process priority. 68 69**Since**: 15 70 71 72## Enum Description 73 74 75### BackgroundProcessManager_ErrorCode 76 77``` 78enum BackgroundProcessManager_ErrorCode 79``` 80**Description** 81 82Enumerates the error codes used by the background child process management. 83 84**Since**: 15 85 86| Value| Description| 87| -------- | -------- | 88| ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS | The suppression parameter is sent successfully.| 89| ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM | Parameter check failed.| 90| ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR | The client process fails to obtain the system service.| 91 92 93### BackgroundProcessManager_ProcessPriority 94 95``` 96enum BackgroundProcessManager_ProcessPriority 97``` 98**Description** 99 100Enumerates child process priorities. 101 102**Since**: 15 103 104| Value| Description| 105| -------- | -------- | 106| PROCESS_BACKGROUND | Compared with **PROCESS_INACTIVE**, this priority has a more obvious suppression effect. Child processes can obtain less CPU resources. You are advised to set this priority when executing background child processes that cannot be perceived by users, such as background image-text pages. | 107| PROCESS_INACTIVE | You are advised to set this priority when executing background child processes that can be perceived by users, such as audio playback and navigation. | 108 109 110## Function Description 111 112 113### OH_BackgroundProcessManager_ResetProcessPriority() 114 115``` 116int OH_BackgroundProcessManager_ResetProcessPriority (int pid) 117``` 118**Description** 119 120Unsuppresses the child process. In this case, the child process follows the scheduling policy of the main process. If the scheduling policy of the main process changes, for example, from the background to the foreground, the child process changes with the main process. The effect is the same as calling **resetProcessPriority**. 121 122**Since**: 15 123 124**Parameters** 125 126| Name| Description| 127| -------- | -------- | 128| pid | Child process ID, which is returned when the child process is created through [OH_Ability_StartNativeChildProcess](../apis-ability-kit/c-apis-ability-childprocess.md#oh_ability_startnativechildprocess). | 129 130**Returns** 131 132Returns an error code. For details about the error codes, see [BackgroundProcessManager_ErrorCode](#backgroundprocessmanager_errorcode). **ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS** is returned if the suppression parameter is sent successfully. **ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR** is returned if the client process fails to obtain the system service. 133 134 135### OH_BackgroundProcessManager_SetProcessPriority() 136 137``` 138int OH_BackgroundProcessManager_SetProcessPriority (int pid, BackgroundProcessManager_ProcessPriority priority ) 139``` 140**Description** 141 142Sets the child process priority. After a child process is suppressed, the CPU resources that can be obtained will be limited. If the scheduling policy of the main process changes, for example, from the background to the foreground, the child process changes with the main process. To suppress the child process, call this API again. 143 144**Since**: 15 145 146**Parameters** 147 148| Name| Description| 149| -------- | -------- | 150| pid | ID of the child process to be suppressed, which is returned when the child process is created through [OH_Ability_StartNativeChildProcess](../apis-ability-kit/c-apis-ability-childprocess.md#oh_ability_startnativechildprocess). | 151| priority | Suppression priority.| 152 153**Returns** 154 155Returns an error code. For details about the error codes, see [BackgroundProcessManager_ErrorCode](#backgroundprocessmanager_errorcode). **ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS** is returned if the suppression parameter is sent successfully. **ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM** is returned if the parameter check fails. **ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR** is returned if the client process fails to obtain the system service. 156