op_pro_mod_objid()
摘要
获取拥有某进程的模块的对象 ID。
语法
op_pro_mod_objid (pro_handle)
| 参数 | 类型 | 说明 |
|---|---|---|
pro_handle |
Prohandle |
需要查找其所属模块的进程的进程句柄 |
返回类型
Objid
拥有指定进程的模块的对象 ID。若发生错误,返回的对象 ID 将是符号常量 OPC_OBJID_INVALID。
示例
/* Loop through all the nodes in the system. */
for (i = 0; i < num_nodes; i++)
{
/* Obtain the globally administered node information data */
/* structure for the i_th node. */
ni_ptr = &Tm_Node_Info_Array [i];
/* Obtain a process handle for the "controller" process in the i_th node, */
/* and use it to determine the object id of the controller module. */
cntl_objid = op_pro_mod_objid (ni_ptr->cntl_ph);
/* Test for an error in the object id query. This would result */
/* if the process handle was one obtained as an error or if it */
/* refers to a process that has been destroyed previously. */
if (cntl_objid != OPC_OBJID_INVALID)
{
/* Deliver a packet from the command buffer to each controller. */
pkptr = op_subq_pk_remove (TP_SUBQ_COMMAND, OPC_QPOS_HEAD);
op_pk_deliver (cntl_objid, TP_CNTL_INSTRM_COMMAND);
}
}
详情
每个进程都由一个队列或处理器模块拥有。这一所有权属性在进程创建时确定。对于模块的根进程,这发生在仿真开始时由仿真内核自动创建它之时。当根进程创建其他(子)进程时,这些子进程同样归该模块所有;它们的子进程也是如此,依此类推。
通常,当进程只笼统地知道某个进程句柄,而需要获知其所属模块以便修改属性或与该模块通信时,会调用 op_pro_mod_objid()。获取另一模块中某进程的进程句柄可以通过多种机制,包括共享全局变量,以及将进程句柄嵌入传输的数据包或 ICI 中。
用途
当某进程的句柄可被其自身模块之外的其他进程获得时,op_pro_mod_objid() 通常很有用。该内核过程使一个进程能够确定所属模块的对象 ID,并可能利用该对象 ID 通过 op_pro_root() 获取该模块的根进程,或向远程模块投递某种中断,而无需具体指定接收该中断的进程。但请注意,该内核过程并不适合用于确定拥有当前正在执行进程的模块的对象 ID,因为调用内核过程 op_id_self() 可以更简单地获得这一信息。
错误
- 程序中止:段违例(由于进程句柄格式错误)。
- 可恢复错误:进程句柄无效。
- 可恢复错误:进程句柄指向已被销毁的进程(
<proc_id>)。
参考
- 使用内核过程 op_id_self() 确定拥有当前进程的模块的对象 id
- 使用内核过程 op_pro_root() 获取给定模块中根进程的句柄
- 使用内核过程 op_ima_obj_attr_get() 根据对象 ID 获取对象的属性值
- 使用内核过程 op_ima_obj_attr_set() 根据对象 ID 修改对象的属性值
- 使用内核过程 op_pk_deliver() 将数据包投递到远程处理器或队列模块
- 使用内核过程 op_intrpt_force_remote() 在远程处理器或队列处强制立即产生中断