openharmony 鸿蒙 capi-background-process-manager-h

2026-08-25 浏览 (2)

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

Enums

Nametypedef KeywordDescription
BackgroundProcessManager_ProcessPriorityBackgroundProcessManager_ProcessPriorityEnumerates child process priorities.
BackgroundProcessManager_ErrorCodeBackgroundProcessManager_ErrorCodeEnumerates the error codes used by the background child process management.

Functions

NameDescription
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

BackgroundProcessManager_ProcessPriority

enum BackgroundProcessManager_ProcessPriority

Description

Enumerates child process priorities.

Since: 17

EnumDescription
PROCESS_BACKGROUND = 1Compared 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 = 2You are advised to set this priority when executing background child processes that can be perceived by users, such as audio playback and navigation.

BackgroundProcessManager_ErrorCode

enum BackgroundProcessManager_ErrorCode

Description

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

Since: 17

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

Function Description

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

NameDescription
int pidID 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 prioritySuppression priority.

Return value

TypeDescription
intERR_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.

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

NameDescription
int pidID of the child process, which is the value of the pid parameter of the OH_Ability_StartNativeChildProcess API.

Return value

TypeDescription
intERR_BACKGROUND_PROCESS_MANAGER_SUCCESS is returned if the suppression parameter is sent successfully.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 js-apis-backgroundTaskManager

openharmony 鸿蒙 errorcode-DeviceUsageStatistics

openharmony 鸿蒙 capi-transient-task-type-h

openharmony 鸿蒙 errorcode-backgroundTaskMgr

openharmony 鸿蒙 js-apis-WorkSchedulerExtensionContext

openharmony 鸿蒙 js-apis-reminderAgent

openharmony 鸿蒙 errorcode-backgroundProcessManager

openharmony 鸿蒙 js-apis-WorkSchedulerExtensionAbility

openharmony 鸿蒙 errorcode-reminderAgentManager

openharmony 鸿蒙 capi-transienttask-transienttask-transienttaskinfo

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/SNSVbUJt