op_pro_id()
Abstract
Obtains a unique integer identifier for a process.
Syntax
op_pro_id (pro_handle)
| Argument | Type | Description |
|---|---|---|
pro_handle |
Prohandle |
Process handle of the process whose unique id is sought. |
Return Type
int
Unique integer identifier of the process specified by the argument pro_handle. This identifier is assigned by the Simulation Kernel when the process is created. If an error occurs, the return value will be the symbolic constant OPC_PRO_ID_INVALID.
Example
/* Loop through the list of channels and create each channel's */
/* packet handling process. */
for (i = 0; i < num_channels; i++)
{
/* Obtain the i_th channel data structure. */
chan_ptr = (Channel*) op_prg_list_access (Channel_List_Ptr, i);
/* Create a process to handle packet arrives on this channel; */
/* retain a handle for the process to invoke it when needed. */
chan_ptr->pro_handle = op_pro_create ("chan_pkt_hndlr", OPC_NIL);
/* If a trace is enabled for the simulation debugger, print the */
/* id of the process next to the channel index. */
if (op_prg_odb_ltrace_active ("channels"))
{
sprintf (str, "%d) pro_id = (%d)", i, op_pro_id (chan_ptr->pro_handle));
op_prg_odb_print_minor (str, OPC_NIL);
}
}
Details
Processes are instances of process models created either automatically by the Simulation Kernel at the start of simulation or dynamically by other processes via the KP op_pro_create(). Each process carries a unique integer ID that can be used to distinguish it from any other process in the simulation, including processes belonging to other modules. This ID is assigned by the Simulation Kernel when the process is created.
Every process handle carries the ID of the process to which it refers. Therefore every initialized process handle (i.e., those that have been assigned the return value of a KP), carries a meaningful process ID. Those process handles that are invalid because they have been returned by KPs that executed erroneously will contain a process ID equal to the symbolic constant OPC_PRO_ID_INVALID. Unlike most other KPs that take process handles as input arguments, op_pro_id() can properly return a process ID for a process that has been destroyed; while the process is no longer active, the ID may be useful for reporting purposes, or for comparison with process IDs stored in application-specific data-structures.
Purpose
Provides access to a unique integer identifier of a process, typically useful for printing debugging or trace statements.
Errors
- Recoverable Error: Process handle is invalid.
- Program Abort: Segmentation violation. (due to malformed process handle)
Reference
- Use the KP op_pro_create() to create a new process
- Use the KP op_pro_parent() to obtain a process handle for the process that created another
- Use the KP op_pro_root() to obtain a process handle for the root process of a queue/processor
- Use the KP op_pro_self() to obtain a process handle for the process that is currently executing
- Use the KP op_pro_mod_objid() to determine the object id of the module that owns a process