op_pro_valid()

Abstract

Determines if a process handle refers to a valid, existing process (i.e, the process handle is not one that has been obtained as an indication of a KP error, and the process that it refers to has not yet been destroyed).

Syntax

op_pro_valid (pro_handle)
Argument Type Description
pro_handle Prohandle Process handle to be tested for validity

Return Type

Boolean

Boolean value indicating if the process handle refers to a process that is valid and not destroyed. The value OPC_FALSE is returned if the process handle is invalid; OPC_TRUE is returned if the handle is valid.

Example

/* Loop through the child process list. */
for (i = 0; i < op_prg_list_size (process_list_ptr); i++)
	{
	/* Obtain the i_th process descriptor. */
	pd_ptr = op_prg_list_access (process_list_ptr, i);

	/* If the process is no longer active, remove it from the list. */
	if (op_pro_valid (pd_ptr->pro_handle) == OPC_FALSE)
		{
		op_prg_list_remove (process_list_ptr, i--);
		
		/* If under odb, issue a statement indicating the removal to the user. */
		if (op_prg_odb_ltrace_active ("process management"))
			{
			/* Note that the process id can’t be obtained from the handle, */
			/* because the process is already destroyed.                   */
			sprintf (str, "Deleting dead process (%d)", pd_ptr->pro_id);
			op_prg_odb_print_minor (str, OPC_NIL);
			}
		}

Details

Process handles for both automatically created and dynamic processes can be obtained using a variety of KPs in the Pro package. The process handles that are obtained can then be stored in state, temporary, or global variables for use in other KPs.

These process handles are user-declared data-structures (not pointers) that can become invalid for three reasons:

  1. The process handle was declared but never initialized, meaning that its contents are undefined.
  2. The process handle was used to capture the return value of a KP, and this KP made the process handle invalid to indicate to the caller that an error occurred in the KP’s execution.
  3. The process handle once represented a valid reference to a process, but this process has since been destroyed via the KP op_pro_destroy().

The KP op_pro_valid() will determine with certainty if a process handle is invalid for reasons (2) or (3) above, and if so will return the value OPC_FALSE. However, because the contents of the handle are arbitrary for case (1), a fatal error can occur simply in trying to access the contents of the handle itself. If the process handle refers to a process that was properly created and is still in existence, this KP will return OPC_TRUE.

Purpose

This KP allows a process handle to be tested for validity which is important for a number of different applications. One principal use of the KP is to check that a process handle is valid before using it as an argument in a call to a KP. A second important use is the test of process handles returned by KPs that have a Prohandle return data type; many of these KPs set the process handle to an invalid state in order to indicate some error in the KPs execution. op_pro_valid() is therefore used to validate the execution of certain other KPs in cases where there is a reason to believe that the KP may not complete successfully.

Errors

  • Program Abort: Segmentation violation. (due to a malformed process handle)

Reference

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · 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