op_pro_parent()

摘要

获取某个进程的父进程(即创建该指定进程的进程)的进程句柄。

语法

op_pro_parent (pro_handle)
参数 类型 说明
pro_handle Prohandle 需要查找其父进程的进程的句柄。
[该进程句柄可以通过多种不同方式获得,包括内核过程 op_pro_self() 或 op_pro_parent()。]

返回类型

Prohandle

给定进程的父进程的进程句柄。如果发生错误,特别是当提供的输入参数是某个模块根进程的句柄时,返回的进程句柄将是无效的。句柄的有效性可以通过调用内核过程 op_pro_valid() 来判断。

示例

摘自:示例模型(models/std/x25);进程模型(x25_dce_chan);状态(INIT);进入执行函数。

/* Test if this is the initial invocation of the process, or      */
/* a reentry of the initial state (presumably due to call ending) */
if (op_pro_argmem_access () == OPC_NIL)
	{
	/* our argument is nil, so this is initialization. */
	}
else
	{
	/* We’ve returned to this state for some other event; */
	/* free our dynamically allocated memory.            */
	op_prg_mem_free (window);
	window = OPC_NIL;
	op_prg_mem_free (input_buffer);
	input_buffer = OPC_NIL;

	/* Obtain a handle for the parent process and notify that we can be deleted.*/
	parent_ph = op_pro_parent (op_pro_self());
	op_intrpt_schedule_process (parent_ph, op_sim_time(), chan_vars->number);
	}

详情

在给定队列或处理器模块中的所有进程中,除根进程外,每个进程都有一个父进程。父进程(Parent)是指通过内核过程 op_pro_create() 创建了新进程的进程。模块的根进程在仿真开始时由仿真内核自动创建,因此没有父进程。当以指向根进程的进程句柄调用 op_pro_parent() 时,它将返回无效的进程句柄。

当一个进程创建新进程时,新进程获得与其父进程相同的归属属性。因此,内核过程 op_pro_parent() 总是返回与指定进程同属一个模块的进程。

该内核过程可以反复应用,以获取一个进程的所有“祖先”进程的句柄,直到返回根进程的句柄为止。

用途

提供了一种获取创建另一进程的进程句柄的方法。该句柄有助于支持与父进程之间基于中断的异步通信。进程也可能希望知道其父进程的句柄,以便对其应用其他各种内核过程。典型用途包括:调用 op_intrpt_schedule_process() 使父进程在将来某个时刻被中断;op_pro_invoke() 立即执行父进程;op_pro_destroy() 将父进程从模块中停用并移除;以及 op_intrpt_type_register() 和 op_intrpt_port_register(),使特定中断专门指向父进程。

错误

  • 程序中止:段违例(由于进程句柄格式错误)。
  • 可恢复错误:进程句柄无效。
  • 可恢复错误:进程句柄属于已销毁的进程(<proc_id>)。
  • 可恢复错误:进程句柄属于根进程(<proc_id>)。
  • 可恢复错误:父进程(<proc_id>)是已销毁的进程。

参考

  • 使用内核过程 op_pro_root() 获取队列或处理器模块根进程的进程句柄
  • 使用内核过程 op_pro_self() 获取当前正在执行进程的进程句柄
  • 使用内核过程 op_pro_invoke() 使某个进程立即执行
  • 使用内核过程 op_pro_destroy() 将进程从队列/处理器模块中停用并移除
  • 使用内核过程 op_pro_parmem_access() 利用进程与其父进程之间的共享内存

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com