目录

background_process_manager.h

Overview

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.

File to include: <background_process_manager/background_process_manager.h>

Library: libbackground_process_manager.z.so

System capability: SystemCapability.Resourceschedule.BackgroundProcessManager

Since: 17

Related module: BackgroundProcessManager

Summary

[h2]Enums

Name typedef Keyword Description
BackgroundProcessManager_ProcessPriority BackgroundProcessManager_ProcessPriority Enumerates child process priorities.
BackgroundProcessManager_ErrorCode BackgroundProcessManager_ErrorCode Enumerates the error codes used by the background child process management.

[h2]Functions

Name Description
int OH_BackgroundProcessManager_SetProcessPriority(int pid, 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.
int 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.

Enum Description

[h2]BackgroundProcessManager_ProcessPriority

enum BackgroundProcessManager_ProcessPriority

Description

Enumerates child process priorities.

Since: 17

Enum Description
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.
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.

[h2]BackgroundProcessManager_ErrorCode

enum BackgroundProcessManager_ErrorCode

Description

Enumerates the error codes used by the background child process management.

Since: 17

Enum Description
ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS = 0 The suppression parameter is sent successfully.
ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM = 401 Parameter check fails.
ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR = 31800001 The client process fails to obtain the system service.

Function Description

[h2]OH_BackgroundProcessManager_SetProcessPriority()

int OH_BackgroundProcessManager_SetProcessPriority(int pid, BackgroundProcessManager_ProcessPriority priority)

Description

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.

Since: 17

Parameters

Name Description
int pid ID of the child process to be suppressed, which is the value of the pid parameter after the child process is created through the OH_Ability_StartNativeChildProcess API.
BackgroundProcessManager_ProcessPriority priority Suppression priority.

Returns

Type Description
int

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.

[h2]OH_BackgroundProcessManager_ResetProcessPriority()

int OH_BackgroundProcessManager_ResetProcessPriority(int pid)

Description

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.

Since: 17

Parameters

Name Description
int pid ID of the child process, which is the value of the pid parameter of the OH_Ability_StartNativeChildProcess API.

Returns

Type Description
int ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS is returned if the decompression is successful.