harmony 鸿蒙native_child_process.h

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

native_child_process.h

Overview

The native_child_process.h file declares the APIs used to create a native child process and establish an IPC channel between the main process and child process. A maximum of 512 child processes can be started through this module and childProcessManager (non-SELF_FORK mode).

Library: libchild_process.so

System capability: SystemCapability.Ability.AbilityRuntime.Core

Since: 12

Related module: ChildProcess

Summary

Files

Name Description
native_child_process.h Declares the APIs used to create a native child process and establish an IPC channel between the main process and child process.
File to include:
Library: libchild_process.so

Types

Name Description
typedef enum Ability_NativeChildProcess_ErrCode Ability_NativeChildProcess_ErrCode Defines an enum for the error codes used by the native child process module.
typedef void(* OH_Ability_OnNativeChildProcessStarted) (int errCode, OHIPCRemoteProxy *remoteProxy) Defines a callback function for notifying the child process startup result.
typedef void(* OH_Ability_OnNativeChildProcessExit) (int32_t pid, int32_t signal) Defines the callback function for detecting abnormal exit of a native child process.
typedef struct NativeChildProcess_Fd Defines a struct for the file descriptor of a child process.
typedef struct NativeChildProcess_FdList Defines a struct for the linked list of file descriptors of a child process.
typedef struct NativeChildProcess_Args Defines a struct for the arguments used for starting a child process.
typedef struct NativeChildProcess_Options Defines a struct for the startup configuration options of a child process.

Enums

Name Description
Ability_NativeChildProcess_ErrCode {
NCP_NO_ERROR = 0,
NCP_ERR_INVALID_PARAM = 401,
NCP_ERR_NOT_SUPPORTED = 801,
NCP_ERR_INTERNAL = 16000050,
NCP_ERR_BUSY = 16010001,
NCP_ERR_TIMEOUT = 16010002,
NCP_ERR_SERVICE_ERROR = 16010003,
NCP_ERR_MULTI_PROCESS_DISABLED = 16010004,
NCP_ERR_ALREADY_IN_CHILD = 16010005,
NCP_ERR_MAX_CHILD_PROCESSES_REACHED = 16010006,
NCP_ERR_LIB_LOADING_FAILED = 16010007,
NCP_ERR_CONNECTION_FAILED = 16010008
NCP_ERR_CALLBACK_NOT_EXIST = 16010009
}
Enumerates the error codes used by the native child process module.
NativeChildProcess_IsolationMode {
NCP_ISOLATION_MODE_NORMAL = 0,
NCP_ISOLATION_MODE_ISOLATED = 1,
}
Enumerates the isolation modes of a child process.

Functions

Name Description
int OH_Ability_CreateNativeChildProcess (const char *libName, OH_Ability_OnNativeChildProcessStarted onProcessStarted) Creates a child process, loads the specified dynamic library file, and returns the startup result asynchronously through a callback parameter. The callback notification is an independent thread. When implementing the callback function, pay attention to thread synchronization and do not perform time-consuming operations to avoid long-time blocking.
NOTE
Currently, this function is valid only for 2-in-1 devices. Since API version 15, a single process supports a maximum of 50 native child processes. In API version 14 and earlier versions, a single process supports only one native child process.
Ability_NativeChildProcess_ErrCode OH_Ability_StartNativeChildProcess(const char* entry, NativeChildProcess_Args args, NativeChildProcess_Options options, int32_t *pid) Starts a child process, loads the specified dynamic library file, and calls the entry function. Arguments can be passed to the child process.
NOTE
Currently, this function is valid only for 2-in-1 devices and tablets.
NativeChildProcess_Args* OH_Ability_GetCurrentChildProcessArgs() Used by a child process, after being started by calling OH_Ability_StartNativeChildProcess, to obtain the startup parameter NativeChildProcess_Args from any .so file or child thread.
NOTE
Currently, this function is valid only for 2-in-1 devices and tablets.
Ability_NativeChildProcess_ErrCode OH_Ability_RegisterNativeChildProcessExitCallback(OH_Ability_OnNativeChildProcessExit onProcessExit) Registers a callback function for detecting abnormal exit of a native child process. It is used to obtain the information about the child process that exits abnormally.
Ability_NativeChildProcess_ErrCode OH_Ability_UnregisterNativeChildProcessExitCallback(OH_Ability_OnNativeChildProcessExit onProcessExit) Unregisters the callback function used for detecting abnormal exit of a native child process.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Ability Kit

harmony 鸿蒙AbilityAccessControl

harmony 鸿蒙AbilityBase

harmony 鸿蒙AbilityBase_Element

harmony 鸿蒙AbilityRuntime

harmony 鸿蒙bundle

harmony 鸿蒙OH_NativeBundle_ApplicationInfo

harmony 鸿蒙OH_NativeBundle_ElementName

harmony 鸿蒙ability_access_control.h

harmony 鸿蒙ability_base_common.h

0  赞