Tubo Remote Process Execution Library

Tubo Remote Process Execution Library — The Libtubo library is small and simple function set to enable a process to run any other process in the background and communicate via the stdout, stderr and stdin file descriptors.

Synopsis


#include <tubo.h>


tubo_t*     TuboCancel                      (tubo_t *forkObject,
                                             void (*cleanup) (void *),
                                             void *user_data);
pid_t       TuboPID                         (tubo_t *forkObject);
tubo_t*     TuboO                           (void (*fork_function) (void *),
                                             void *fork_function_data,
                                             void (*fork_finished_function) (pid_t, void *),
                                             int (*operate_stdout) (int, void *, void *),
                                             int (*operate_stderr) (int, void *, void *),
                                             void *user_data);
tubo_t*     TuboIO                          (void (*fork_function) (void *),
                                             void *fork_function_data,
                                             void (*fork_finished_function) (pid_t, void *),
                                             int *operate_stdin,
                                             int (*operate_stdout) (int, void *, void *),
                                             int (*operate_stderr) (int, void *, void *),
                                             void *user_data);
tubo_t*     Tubo_full                       (void (*fork_function) (void *),
                                             void *fork_function_data,
                                             void (*fork_finished_function) (pid_t, void *),
                                             int *operate_stdin,
                                             int (*operate_stdout) (int, void *, void *),
                                             int (*operate_stderr) (int, void *, void *),
                                             void *user_data,
                                             int read_delay,
                                             int double_fork);

Description

The functionality is similar to the glib function g_spawn_async_with_pipes() except that all pipe setup and monitoring is taken care of. The calling function only has to provide the functions with which to process the input/output of the remote process.

Details

TuboCancel ()

tubo_t*     TuboCancel                      (tubo_t *forkObject,
                                             void (*cleanup) (void *),
                                             void *user_data);

This function will cancel and terminate a remote process which is currently running. Once termination is complete, the specified fork_finished_function will be called, of course, after which all associated memory is released.

forkObject : Pointer to pointer to the remote interprocess object returned by TuboO, TuboIO or Tubo_full.
cleanup : User function to execute once the remote process is terminated. If this value is NULL, it is ignored.
user_data : User data pointer to send to cleanup function.
Returns : NULL pointer.

TuboPID ()

pid_t       TuboPID                         (tubo_t *forkObject);

This function returns the system process identification for the remote process.

forkObject : Pointer to pointer to the remote interprocess object returned by TuboO, TuboIO or Tubo_full.
Returns : System PID for the remote child process.

TuboO ()

tubo_t*     TuboO                           (void (*fork_function) (void *),
                                             void *fork_function_data,
                                             void (*fork_finished_function) (pid_t, void *),
                                             int (*operate_stdout) (int, void *, void *),
                                             int (*operate_stderr) (int, void *, void *),
                                             void *user_data);

Function for creating a remote process which does not require any input from parent process (in other words, just one way communication from remote process towards parent process).

fork_function : Pointer to function to execute after forking.
fork_function_data : Pointer to date to be sent to fork_function. If this value is NULL, it is ignored.
fork_finished_function : Pointer to function to execute when remote process has terminated.
operate_stdout : Pointer to function to process output produced by remote process towards stdout. Set to NULL to ignore output.
operate_stderr : Pointer to function to process output produced by remote process towards stderr. Set to NULL to ignore output.
user_data : Pointer to user_data passed to fork_finished_function, operate_stdin, and operate_stdout.
Returns : Pointer to the remote interprocess object.

TuboIO ()

tubo_t*     TuboIO                          (void (*fork_function) (void *),
                                             void *fork_function_data,
                                             void (*fork_finished_function) (pid_t, void *),
                                             int *operate_stdin,
                                             int (*operate_stdout) (int, void *, void *),
                                             int (*operate_stderr) (int, void *, void *),
                                             void *user_data);

Function for creating a remote process which requires two way communication between remote process and parent process. The file descriptor for stdin should not be NULL and may be used by the parent process to write to stdin for the remote child process: This must point to a global memory variable.

fork_function : Pointer to function to execute after forking.
fork_function_data : Pointer to date to be sent to fork_function. If this value is NULL, it is ignored.
fork_finished_function : Pointer to function to execute when remote process has terminated.
operate_stdin : Pointer to the file descriptor to be used by the parent process to write to stdin at the remote child process. If this value is NULL, then it is ignored.
operate_stdout : Pointer to function to process output produced by remote process towards stdout. Set to NULL to ignore output.
operate_stderr : Pointer to function to process output produced by remote process towards stderr. Set to NULL to ignore output.
user_data : Pointer to user_data passed to fork_finished_function, operate_stdin, and operate_stdout.
Returns : Pointer to the remote interprocess object.

Tubo_full ()

tubo_t*     Tubo_full                       (void (*fork_function) (void *),
                                             void *fork_function_data,
                                             void (*fork_finished_function) (pid_t, void *),
                                             int *operate_stdin,
                                             int (*operate_stdout) (int, void *, void *),
                                             int (*operate_stderr) (int, void *, void *),
                                             void *user_data,
                                             int read_delay,
                                             int double_fork);

Full control function for creating a remote process which requires two way communication between remote process and parent process. The file descriptor for stdin should not be NULL (will be ignored if NULL) and may be used by the parent process to write to stdin for the remote child process: This must point to a global memory variable. Further parameters allow a finer control of the remote process control, such as specifying an alternate read delay from the default, and the option to do a double fork and garantee that no output from the child process is lost. Output from the child process may be lost if the child terminates too quickly is this value is set to FALSE (default). If it is important not to lose any output at all (such as the result from a find command), set this value to TRUE.

fork_function : Pointer to function to execute after forking.
fork_function_data : Pointer to date to be sent to fork_function. If this value is NULL, it is ignored.
fork_finished_function : Pointer to function to execute when remote process has terminated.
operate_stdin : Pointer to the file descriptor to be used by the parent process to write to stdin at the remote child process. If this value is NULL, then it is ignored.
operate_stdout : Pointer to function to process output produced by remote process towards stdout. Set to NULL to ignore output.
operate_stderr : Pointer to function to process output produced by remote process towards stderr. Set to NULL to ignore output.
user_data : Pointer to user_data passed to fork_finished_function, operate_stdin, and operate_stdout.
read_delay : Millisecond delay before reading. Usually just set this value to zero to use the default delay.
double_fork : Set this value to TRUE to use a grandchild process and avoid losing any output at all when the remote process terminates. If all the output is not that important, then just set this value to FALSE.
Returns : Pointer to the remote interprocess object.