Home | Previous Page | Next Page   Creating User-Defined Routines > Writing a User-Defined Routine > Controlling the VP Environment >

Changing the VP Environment

If the UDR determines that its VP environment is not correct for its execution requirements, it can perform either of the following tasks to change it.

Change to VP Environment DataBlade API Function
Execute a specified C function on another VP mi_call_on_vp( )
Fork and execute a new process to perform some task mi_process_exec( )

Executing on Another VP

If the VP environment is not useful for the execution of your C function, you can tell the routine manager to switch its execution to another VP with the mi_call_on_vp( ) function. Pass the following arguments to this function:

The mi_call_on_vp( ) function switches the current thread to the specified VP and executes the C function on this VP. When the C function completes, mi_call_on_vp( ) stores as one of its arguments the C-function return value and returns control to the originating VP.

Forking and Executing a Process

If you need to run some program or script as a separate process, you can use the mi_process_exec( ) function. The mi_process_exec( ) function forks and executes a new process and returns immediately. The database server does not wait for completion, and the new process is allowed to run independently.

Warning:
Never use the operating-system fork( ) and exec( ) calls from within a UDR. These system calls are unsafe within a UDR. (For more information, see Unsafe Operating-System Calls.) If you must execute a separate process, use the mi_process_exec( ) function to create this new process.

The mi_process_exec( ) function is similar to most operating-system exec( ) system calls in that you pass the function an argv array. This array contains all the command strings that are to be passed after the new process is forked. For more information on the syntax of the argv array, see the description of the mi_process_exec( ) function in the IBM Informix: DataBlade API Function Reference.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]