Top | Description |
#include <tubo.h> #define TUBO_CONTROLLER_PID #define TUBO_EXIT_TEXT #define TUBO_REAP_CHILD #define TUBO_VALID_ANSI pid_t Tubo_fork (void (*fork_function) (void *)
,void *fork_function_data
,int *stdin_fd
,void (*stdout_f) (void *stdout_data, void *stream, int childFD)
,void (*stderr_f) (void *stderr_data, void *stream, int childFD)
,void (*tubo_done_f) (void *)
,void *user_function_data
,int flags
); pid_t Tubo_exec (char **argv
,int *stdin_fd
,void (*stdout_f) (void *stdout_data, void *stream, int childFD)
,void (*stderr_f) (void *stderr_data, void *stream, int childFD)
,void (*tubo_done_f) (void *)
,void *user_function_data
,int flags
); pid_t Tubo_threads (void (*fork_function) (void *)
,void *fork_function_data
,int *stdin_fd
,void (*stdout_f) (void *stdout_data, void *stream, int childFD)
,void (*stderr_f) (void *stderr_data, void *stream, int childFD)
,void (*tubo_done_f) (void *)
,void *user_function_data
,int reap_child
,int check_valid_ansi_sequence
); int Tubo_controller (pid_t child
); int Tubo_child (pid_t controller
); unsigned Tubo_get_id (pid_t pid
); unsigned Tubo_id (void
);
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. Furthermore, process control is done by individual threads controlled by semaphores, conditions and shared memory, which allows for control and response on multicore processors.
#define TUBO_CONTROLLER_PID 0x08
Use this flag to have Tubo_exec()
and Tubo_fork()
return the controller
pid instead of the pid of the program being executed. This is the default
in Tubo_threads()
.
#define TUBO_EXIT_TEXT 0x04
Use this flag to have the controller print the standard "Tubo exit"
text to stdout on program termination. This is the default in
Tubo_threads()
.
#define TUBO_REAP_CHILD 0x01
Flag to do reap child process on termination. If this is not set, calling program is responsible for reaping the child process.
#define TUBO_VALID_ANSI 0x02
Flag to do reap child process on termination. If this is not set, calling program is responsible for reaping the child process.
pid_t Tubo_fork (void (*fork_function) (void *)
,void *fork_function_data
,int *stdin_fd
,void (*stdout_f) (void *stdout_data, void *stream, int childFD)
,void (*stderr_f) (void *stderr_data, void *stream, int childFD)
,void (*tubo_done_f) (void *)
,void *user_function_data
,int flags
);
|
pointer to function to execute after forking. This will execute in the child process, and upon termination will be reaped by the controller process. |
|
pointer to data to be sent to fork_function , or NULL. |
|
pointer for file descriptor for stdin, or NULL |
|
pointer to thread safe function to process stdout, or NULL. This
is executed by an independent thread. Please note that gtk or qt instructions
should be done via main thread, as with g_main_context_invoke() . Otherwise,
calling program is responsible for any necessary mutex locks. |
|
pointer to thread safe function to process stderr, or NULL .This
is executed by an independent thread. Please note that gtk or qt instructions
should be done via main thread, as with g_main_context_invoke() . Otherwise,
calling program is responsible for any necessary mutex locks. |
|
pointer to function to execute when remote process has terminated. Execution of this function does not mean all pipe data has been processed yet (data may still be flowing in the pipes). It just means that the spawned process has exited. |
|
pointer to data to be sent to stdout_f , stderr_f
and tubo_done_f (yeah, same data block for all three).
flags TUBO_EXIT_TEXT: print a process termination text at the end of stdout.
flags TUBO_REAP_CHILD: flag to reap child. Set to TRUE to have the controller
process reaped.
If this is set to FALSE, then the user is responsible to reap the controller
process (i.e., with waitpid() ) to avoid leaving a zombie. The controller
process is responsible for reaping the child program.
flags TUBO_VALID_ANSI: flag to filter out non printer safe output.
If set to TRUE, output to stdout/stderr will be checked
for escape sequences that are not valid on a printer terminal and if any such
sequence is found, the child will be terminated without much more ado. |
Returns : |
pid of the program (not the controller). To obtain the controller
pid use Tubo_controller() with the pid of the program as first argument.
This function is not available in systems without fork() (i.e. windoze). |
pid_t Tubo_exec (char **argv
,int *stdin_fd
,void (*stdout_f) (void *stdout_data, void *stream, int childFD)
,void (*stderr_f) (void *stderr_data, void *stream, int childFD)
,void (*tubo_done_f) (void *)
,void *user_function_data
,int flags
);
|
NULL terminated string vector with the arguments of the program to
be executed. This function uses spawnvp() on windows. |
|
pointer for file descriptor for stdin, or NULL |
|
pointer to thread safe function to process stdout, or NULL. This
is executed by an independent thread. Please note that gtk or qt instructions
should be done via main thread, as with g_main_context_invoke() . Otherwise,
calling program is responsible for any necessary mutex locks. |
|
pointer to thread safe function to process stderr, or NULL .This
is executed by an independent thread. Please note that gtk or qt instructions
should be done via main thread, as with g_main_context_invoke() . Otherwise,
calling program is responsible for any necessary mutex locks. |
|
pointer to function to execute when remote process has terminated. Execution of this function does not mean all pipe data has been processed yet (data may still be flowing in the pipes). It just means that the spawned process has exited. |
|
pointer to data to be sent to stdout_f , stderr_f
and tubo_done_f (yeah, same data block for all three).
flags TUBO_EXIT_TEXT: print a process termination text at the end of stdout.
flags TUBO_REAP_CHILD: flag to reap child. Set to TRUE to have the controller
process reaped.
If this is set to FALSE, then the user is responsible to reap the controller
process (i.e., with waitpid() ) to avoid leaving a zombie. The controller
process is responsible for reaping the child program.
flags TUBO_VALID_ANSI: flag to filter out non printer safe output.
If set to TRUE, output to stdout/stderr will be checked
for escape sequences that are not valid on a printer terminal and if any such
sequence is found, the child will be terminated without much more ado. |
Returns : |
pid of the program (not the controller). To obtain the controller
pid use Tubo_controller() with the pid of the program as first argument.
This function is available in Linux, BSD and Windows. |
pid_t Tubo_threads (void (*fork_function) (void *)
,void *fork_function_data
,int *stdin_fd
,void (*stdout_f) (void *stdout_data, void *stream, int childFD)
,void (*stderr_f) (void *stderr_data, void *stream, int childFD)
,void (*tubo_done_f) (void *)
,void *user_function_data
,int reap_child
,int check_valid_ansi_sequence
);
Tubo_threads
is deprecated and should not be used in newly-written code. Use Tubo_fork()
or Tubo_exec()
instead
|
pointer to function to execute after forking. This will execute in the child process, and upon termination will be reaped by the controller process. |
|
pointer to data to be sent to fork_function , or NULL. |
|
pointer for file descriptor for stdin, or NULL |
|
pointer to thread safe function to process stdout, or NULL. This
is executed by an independent thread. Please note that gtk or qt instructions
should be done via main thread, as with g_main_context_invoke() . Otherwise,
calling program is responsible for any necessary mutex locks. |
|
pointer to thread safe function to process stderr, or NULL .This
is executed by an independent thread. Please note that gtk or qt instructions
should be done via main thread, as with g_main_context_invoke() . Otherwise,
calling program is responsible for any necessary mutex locks. |
|
pointer to function to execute when remote process has terminated. Execution of this function does not mean all pipe data has been processed yet (data may still be flowing in the pipes). It just means that the spawned process has exited. |
|
pointer to data to be sent to stdout_f , stderr_f
and tubo_done_f (yeah, same data block for all three).
flags TUBO_EXIT_TEXT: print a process termination text at the end of stdout.
flags TUBO_REAP_CHILD: flag to reap child. Set to TRUE to have the controller
process reaped.
If this is set to FALSE, then the user is responsible to reap the controller
process (i.e., with waitpid() ) to avoid leaving a zombie. The controller
process is responsible for reaping the child program.
flags TUBO_REAP_CHILD: flag to filter out non printer safe output.
If set to TRUE, output to stdout/stderr will be checked
for escape sequences that are not valid on a printer terminal and if any such
sequence is found, the child will be terminated without much more ado. |
Returns : |
pid of controller process. This pid is not the pid of the program
being executed. It is a process that ensures pipes will remain open while
pipe output is still to be read. To send a TERM signal to the actual
process which is executing the remote command, send a USR1 signal to the
controller process. To send a KILL to the actual process which is executing
the remote command, send a USR1 signal to the controller process. Finer
signalling requires the use of Tubo_child() function. |
int Tubo_controller (pid_t child
);
|
pid of the program being executed. |
Returns : |
pid of the process controller. This pid may be used to signal to the program with SIGUSR1 and SIGUSR2. Signals are currently not available in Windows. |
int Tubo_child (pid_t controller
);
|
pid of the controller process. This pid is not the pid of the program being executed. It is the pid of the controller process. |
Returns : |
pid of program being executed. This pid may be used to signal
directly to the process, instead of the limited SIGUSR1 and SIGUSR2
described in Tubo_threads() . Signals are currently not available in Windows. |
unsigned Tubo_get_id (pid_t pid
);
|
pid of the program being executed or of the controller process. |
Returns : |
Incremental serial number of the program being executed
where pid or controller pid matches pid . This function allows the
calling program obtain the internal serial number for any process
running within the current Tubo session. |