op_pro_parent()
Abstract
Obtains a process handle for the parent of a process (i.e., the process that created the specified process).
Syntax
op_pro_parent (pro_handle)
| Argument | Type | Description |
|---|---|---|
pro_handle |
Prohandle |
Handle of the process whose parent process is sought. [This process handle may be obtained in a number of different ways, including the KPs op_pro_self() or op_pro_parent().] |
Return Type
Prohandle
Process handle of the parent of the given process. If an error occurs, and in particular if the supplied input argument is the handle of a module’s root process, the returned process handle will be invalid. A handle’s validity can be determined by calling the KP op_pro_valid().
Example
Excerpt from: example model (models/std/x25); process model (x25_dce_chan); state (INIT); enter execs.
/* 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);
}
Details
All processes in a given queue or processor module, except the root process, have a parent process. Parent is the term used to refer to the process that has created a new process via the KP op_pro_create(). The root process of a module is created automatically by the Simulation Kernel when the simulation begins, and therefore has no parent process. op_pro_parent() will return an invalid process handle when it is called with a process handle referring to a root process.
When a process creates a new one, the new process acquires the same ownership properties as its parents. Therefore, the KP op_pro_parent() always returns a process owned by the same module as the specified process.
This KP can be applied repeatedly to obtain handles for all the “ancestor” processes of a process, until a handle for the root process is returned.
Purpose
Provides a means of obtaining a handle for the process that created another. This handle is useful to support interrupt-based asynchronous communications with a parent process or processes. A process may also wish to know the handle of its parent process in order to apply various other KPs to it. Typical uses include calls to op_intrpt_schedule_process() to cause the parent process to be interrupted at some future date; op_pro_invoke() to execute the parent process immediately; op_pro_destroy() to deactivate and remove the parent process from the module; and op_intrpt_type_register(), and op_intrpt_port_register() to cause particular interrupts to be directed specifically at the parent process.
Errors
- Program Abort: Segmentation violation. (due to a malformed process handle)
- Recoverable Error: Process handle is invalid.
- Recoverable Error: Process handle is for destroyed process (
<proc_id>). - Recoverable Error: Process handle is for root process (
<proc_id>). - Recoverable Error: Parent process (
<proc_id>) is a destroyed process.
Reference
- Use the KP op_pro_root() to obtain a handle for the root process of a queue or processor module
- Use the KP op_pro_self() to obtain a process handle for the process currently executing
- Use the KP op_pro_invoke() to cause a process to execute immediately
- Use the KP op_pro_destroy() to deactivate and remove a process from a queue/processor module
- Use the KP op_pro_parmem_access() to make use of shared memory between a process and its parent