The mi_process_exec() function

The mi_process_exec() function forks and executes a new process, returning before this new process completes.

Syntax

mi_integer mi_process_exec(argv)
   char *argv[]; 
argv
A pointer to the command array, which provides the commands to execute in the newly forked process.
Valid in client LIBMI application? Valid in user-defined routine?
No Yes
Important: This advanced function can adversely affect your UDR if you use the function incorrectly. Use it only when no regular DataBlade® API function can perform the task you need done.

Usage

The mi_process_exec() function forks a process and executes the commands in the argv array. The rules for the contents of the argv array are as follows:
  • The first element must be an executable program or script.

    You must provide the full path name of this program or script. A single environment variable is allowed as a prefix using the same rules as the mi_file_open() function.

    To include environment variables in the command path name, use the following syntax:
    $ENV_VAR
    To use the PATH environment variable, you must execute the command through a shell (such as /bin/sh). However, make sure that the command is also executable:
    /bin/sh -c cmd

    If the command is a script, it must be executable and start with a shell identifier (such as “#!/bin/sh”).

  • The last element must be the keyword NULL.
For example, the following code fragment executes the UNIX™ touch command on a file called somefile:
char *argv[5];
argv[0] = "/usr/ucb/touch";
argv[1] = "somefile"; 
argv[2] = NULL;
mi_process_exec(argv);
The following code fragment executes the same command but uses the Bourne shell (/bin/sh) to execute it:
argv[0] = "/bin/sh"; 
argv[1] = "-c"; 
argv[2] = "touch"; 
argv[3] = "somefile"; 
argv[4] = NULL; 
mi_process_exec(argv);
The new process inherits its execution environment from the parent server-initialization process (the operating-system process that runs the oninit utility or its equivalent). The user and group identifiers are those of the application user of the session, and the working directory is as follows:
$ONEDB_HOME/bin

This function is useful if you need to perform a UNIX or Linux™ fork() and exec() from a C UDR.

Return values

MI_OK
The function was successful.
MI_ERROR
The function was not successful.

The mi_process_exec() return value is not a success indicator for the executed process. No feedback occurs between the C-function call and the actual fork() and exec() tasks, which takes place in the ADM VP at some time in the near future when the child-status timer goes off.