1# @ohos.app.ability.ChildProcessArgs 2 3传递到子进程的参数。[childProcessManager](js-apis-app-ability-childProcessManager.md)启动子进程时,可以通过ChildProcessArgs传递参数到子进程中。 4 5> **说明:** 6> 7> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> 本模块接口仅可在Stage模型下使用。 10 11## 导入模块 12 13```ts 14import { ChildProcessArgs } from '@kit.AbilityKit'; 15``` 16 17## 属性 18 19**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 20 21| 名称 | 类型 | 必填 | 说明 | 22| ----------- | -------------------- | ---- | ------------------------------------------------------------ | 23| entryParams | string | 否 | 开发者自定义参数,透传到子进程中。可以在[ChildProcess.onStart](js-apis-app-ability-childProcess.md#childprocessonstart)方法中通过args.entryParams获取,entryParams支持传输的最大数据量为150KB。| 24| fds | Record<string, number> | 否 | 文件描述符句柄集合,用于主进程和子进程通信,通过key-value的形式传入到子进程中,其中key为自定义字符串,value为文件描述符句柄。可以在[ChildProcess.onStart](js-apis-app-ability-childProcess.md#childprocessonstart)方法中通过args.fds获取fd句柄。<br/><b>说明:</b> <br>- fds最多支持16组,每组key的最大长度为20字符。<br>- 传递到子进程中句柄数字可能会变,但是指向的文件是一致的。| 25 26**示例:** 27 28示例中的context的获取方式请参见[获取UIAbility的上下文信息](../../application-models/uiability-usage.md#获取uiability的上下文信息)。 29 30```ts 31// 主进程中: 32import { common, ChildProcessArgs, childProcessManager } from '@kit.AbilityKit'; 33import { fileIo } from '@kit.CoreFileKit'; 34 35@Entry 36@Component 37struct Index { 38 build() { 39 Row() { 40 Column() { 41 Text('Click') 42 .fontSize(30) 43 .fontWeight(FontWeight.Bold) 44 .onClick(() => { 45 let context = this.getUIContext().getHostContext() as common.UIAbilityContext; 46 let path = context.filesDir + "/test.txt"; 47 let file = fileIo.openSync(path, fileIo.OpenMode.READ_ONLY | fileIo.OpenMode.CREATE); 48 let args: ChildProcessArgs = { 49 entryParams: "testParam", 50 fds: { 51 "key1": file.fd 52 } 53 }; 54 childProcessManager.startArkChildProcess("entry/./ets/process/DemoProcess.ets", args); 55 }); 56 } 57 .width('100%') 58 } 59 .height('100%') 60 } 61} 62``` 63 64```ts 65// 子进程中: 66import { ChildProcess, ChildProcessArgs } from '@kit.AbilityKit'; 67 68export default class DemoProcess extends ChildProcess { 69 70 onStart(args?: ChildProcessArgs) { 71 let entryParams = args?.entryParams; 72 let fd = args?.fds?.key1; 73 // .. 74 } 75} 76``` 77