1# background_process_manager.h 2 3## Overview 4 5The **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**. 6 7**File to include**: <background_process_manager/background_process_manager.h> 8 9**Library**: libbackground_process_manager.z.so 10 11**System capability**: SystemCapability.Resourceschedule.BackgroundProcessManager 12 13**Since**: 17 14 15**Related module**: [BackgroundProcessManager](capi-backgroundprocessmanager.md) 16 17## Summary 18 19### Enums 20 21| Name| typedef Keyword| Description| 22| -- | -- | -- | 23| [BackgroundProcessManager_ProcessPriority](#backgroundprocessmanager_processpriority) | BackgroundProcessManager_ProcessPriority | Enumerates child process priorities.| 24| [BackgroundProcessManager_ErrorCode](#backgroundprocessmanager_errorcode) | BackgroundProcessManager_ErrorCode | Enumerates the error codes used by the background child process management.| 25 26### Functions 27 28| Name| Description| 29| -- | -- | 30| [int OH_BackgroundProcessManager_SetProcessPriority(int pid, BackgroundProcessManager_ProcessPriority priority)](#oh_backgroundprocessmanager_setprocesspriority) | 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.| 31| [int OH_BackgroundProcessManager_ResetProcessPriority(int pid)](#oh_backgroundprocessmanager_resetprocesspriority) | 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**.| 32 33## Enum Description 34 35### BackgroundProcessManager_ProcessPriority 36 37``` 38enum BackgroundProcessManager_ProcessPriority 39``` 40 41**Description** 42 43Enumerates child process priorities. 44 45**Since**: 17 46 47| Enum| Description| 48| -- | -- | 49| PROCESS_BACKGROUND = 1 | 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.| 50| PROCESS_INACTIVE = 2 | You are advised to set this priority when executing background child processes that can be perceived by users, such as audio playback and navigation.| 51 52### BackgroundProcessManager_ErrorCode 53 54``` 55enum BackgroundProcessManager_ErrorCode 56``` 57 58**Description** 59 60Enumerates the error codes used by the background child process management. 61 62**Since**: 17 63 64| Enum| Description| 65| -- | -- | 66| ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS = 0 | The suppression parameter is sent successfully.| 67| ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM = 401 | Parameter check fails.| 68| ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR = 31800001 | The client process fails to obtain the system service.| 69 70 71## Function Description 72 73### OH_BackgroundProcessManager_SetProcessPriority() 74 75``` 76int OH_BackgroundProcessManager_SetProcessPriority(int pid, BackgroundProcessManager_ProcessPriority priority) 77``` 78 79**Description** 80 81Sets 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. 82 83**Since**: 17 84 85 86**Parameters** 87 88| Name| Description| 89| -- | -- | 90| int pid | ID of the child process to be suppressed, which is returned when the child process is created through **OH_Ability_StartNativeChildProcess**.| 91| [BackgroundProcessManager_ProcessPriority](capi-background-process-manager-h.md#backgroundprocessmanager_processpriority) priority | Suppression priority.| 92 93**Return value** 94 95| Type| Description| 96| -- | -- | 97| int | [ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS](capi-background-process-manager-h.md#backgroundprocessmanager_errorcode) is returned if the suppression parameter is sent successfully.<br> [ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM](capi-background-process-manager-h.md#backgroundprocessmanager_errorcode) is returned if the parameter check fails.| 98 99### OH_BackgroundProcessManager_ResetProcessPriority() 100 101``` 102int OH_BackgroundProcessManager_ResetProcessPriority(int pid) 103``` 104 105**Description** 106 107Unsuppresses 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**. 108 109**Since**: 17 110 111 112**Parameters** 113 114| Name| Description| 115| -- | -- | 116| int pid | Child process ID, which is returned when the child process is created through **OH_Ability_StartNativeChildProcess**.| 117 118**Return value** 119 120| Type| Description| 121| -- | -- | 122| int | [ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS](capi-background-process-manager-h.md#backgroundprocessmanager_errorcode) is returned if the suppression parameter is sent successfully.| 123