harmony 鸿蒙BackgroundProcessManager

  • 2025-06-12
  • 浏览 (4)

BackgroundProcessManager

Overview

The BackgroundProcessManager module provides C APIs for managing the scheduling policy of background child processes.

Since: 15

Summary

Files

Name Description
background_process_manager.h 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.

Types

Name Description
typedef enum BackgroundProcessManager_ProcessPriority BackgroundProcessManager_ProcessPriority Defines an enum for the child process priority.
typedef enum BackgroundProcessManager_ErrorCode BackgroundProcessManager_ErrorCode Defines an enum for the error codes used by the background child process management.

Enums

Name Description
BackgroundProcessManager_ProcessPriority { PROCESS_BACKGROUND = 1, PROCESS_INACTIVE = 2 } Enumerates child process priorities.
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.

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.

Type Description

BackgroundProcessManager_ErrorCode

typedef enum BackgroundProcessManager_ErrorCodeBackgroundProcessManager_ErrorCode

Description

Defines an enum for the error codes used by the background child process management.

Since: 15

BackgroundProcessManager_ProcessPriority

typedef enum BackgroundProcessManager_ProcessPriorityBackgroundProcessManager_ProcessPriority

Description

Defines an enum for the child process priority.

Since: 15

Enum Description

BackgroundProcessManager_ErrorCode

enum BackgroundProcessManager_ErrorCode

Description

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

Since: 15

Value Description
ERR_BACKGROUND_PROCESS_MANAGER_SUCCESS The suppression parameter is sent successfully.
ERR_BACKGROUND_PROCESS_MANAGER_INVALID_PARAM Parameter check failed.
ERR_BACKGROUND_PROCESS_MANAGER_REMOTE_ERROR The client process fails to obtain the system service.

BackgroundProcessManager_ProcessPriority

enum BackgroundProcessManager_ProcessPriority

Description

Enumerates child process priorities.

Since: 15

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

Function Description

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: 15

Parameters

Name Description
pid Child process ID, which is returned when the child process is created through OH_Ability_StartNativeChildProcess.

Returns

Returns an error code. For details about the error codes, see 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.

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: 15

Parameters

Name Description
pid ID of the child process to be suppressed, which is returned when the child process is created through OH_Ability_StartNativeChildProcess.
priority Suppression priority.

Returns

Returns an error code. For details about the error codes, see 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.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Background Tasks Kit

harmony 鸿蒙TransientTask

harmony 鸿蒙TransientTask_DelaySuspendInfo

harmony 鸿蒙background_process_manager.h

harmony 鸿蒙DeviceUsageStatistics Error Codes

harmony 鸿蒙backgroundTaskManager Error Codes

harmony 鸿蒙reminderAgentManager Error Codes

harmony 鸿蒙workScheduler Error Codes

harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (Deferred Task Scheduling Callbacks)

harmony 鸿蒙@ohos.resourceschedule.backgroundProcessManager (Background Child Process Management)

0  赞