libamxp
1.4.0
Patterns C Implementation
|
API to help in launching and monitoring child processes. More...
Data Structures | |
struct | _subproc_t |
Child process information structure. More... | |
Typedefs | |
typedef struct _subproc_t | amxp_subproc_t |
Child process information structure. More... | |
Functions | |
int | amxp_subproc_new (amxp_subproc_t **subproc) |
Constructor function, creates a new child process data structure. More... | |
int | amxp_subproc_delete (amxp_subproc_t **subproc) |
Destructor function, deletes a child process data structure. More... | |
int | amxp_subproc_open_fd (amxp_subproc_t *subproc, int requested) |
Opens standard file descriptor to the child process. More... | |
int | amxp_subproc_vstart (amxp_subproc_t *const subproc, char **argv) |
Start a child process. More... | |
int | amxp_subproc_start (amxp_subproc_t *const subproc, char *cmd,...) |
Start a child process. More... | |
int | amxp_subproc_astart (amxp_subproc_t *const subproc, amxc_array_t *cmd) |
Start a child process. More... | |
int | amxp_subproc_kill (const amxp_subproc_t *const subproc, const int sig) |
Sends a Linux signal to the child process. More... | |
int | amxp_subproc_wait (amxp_subproc_t *subproc, int timeout_msec) |
Waits until the child process has stopped. More... | |
int | amxp_subproc_vstart_wait (amxp_subproc_t *subproc, int timeout_msec, char **cmd) |
Starts a child process and waits until it exits. More... | |
int | amxp_subproc_start_wait (amxp_subproc_t *subproc, int timeout_msec, char *cmd,...) |
Starts a child process and waits until it exits. More... | |
amxp_subproc_t * | amxp_subproc_find (const int pid) |
Retrieve a amxp_subproc_t for a child process using it's process identifier. More... | |
pid_t | amxp_subproc_get_pid (const amxp_subproc_t *const subproc) |
Get the PID of a child process. More... | |
amxp_signal_mngr_t * | amxp_subproc_get_sigmngr (const amxp_subproc_t *const subproc) |
Get the Signal managers of the child process. More... | |
bool | amxp_subproc_is_running (const amxp_subproc_t *const subproc) |
Checks if the child process is running. More... | |
int | amxp_subproc_ifexited (amxp_subproc_t *subproc) |
Checks if the child process terminated normally. More... | |
int | amxp_subproc_ifsignaled (amxp_subproc_t *subproc) |
Checks if the child process was stopped because of an uncaught Linux signal. More... | |
int | amxp_subproc_get_exitstatus (amxp_subproc_t *subproc) |
Gets the exit code of the child process. More... | |
int | amxp_subproc_get_termsig (amxp_subproc_t *subproc) |
Gets the Linux signal id that caused the child process to stop. More... | |
API to help in launching and monitoring child processes.
typedef struct _subproc_t amxp_subproc_t |
Child process information structure.
int amxp_subproc_astart | ( | amxp_subproc_t *const | subproc, |
amxc_array_t * | cmd | ||
) |
Start a child process.
Forks and executes a command. Will monitor the child process and handles SIGCHLD.
The process name and its arguments must be passed as an amxc_array_t, where all items must be char * and the first item (index 0) is the process name.
When an empty item is encountered in the array (item containing a NULL pointer), it is considered as the end of the process argument list.
Example:
subproc | pointer to the subproc |
cmd | the child process |
Definition at line 365 of file amxp_subproc.c.
int amxp_subproc_delete | ( | amxp_subproc_t ** | subproc | ) |
Destructor function, deletes a child process data structure.
This function doesn't stop the child process. To stop a child process use amxp_subproc_kill
subproc | pointer to the subproc pointer. Will be set to NULL |
Definition at line 239 of file amxp_subproc.c.
amxp_subproc_t* amxp_subproc_find | ( | const int | pid | ) |
Retrieve a amxp_subproc_t for a child process using it's process identifier.
Searches in the list of launched and running child processes for a child process with a specific process id and returns the amxp_subproc_t pointer representing the child process.
pid | Process id of the child process |
Definition at line 402 of file amxp_subproc.c.
int amxp_subproc_get_exitstatus | ( | amxp_subproc_t * | subproc | ) |
Gets the exit code of the child process.
If the value of WIFEXITED(stat_val) is non-zero, this function evaluates to the low-order 8 bits of the status argument that the child process passed to _exit() or exit(), or the value the child process returned from main().
subproc | pointer to the amxp_subproc_t structure |
Definition at line 537 of file amxp_subproc.c.
pid_t amxp_subproc_get_pid | ( | const amxp_subproc_t *const | subproc | ) |
Get the PID of a child process.
When the provide amxp_subproc_t is not representing a running child process the return pid is 0.
subproc | ponter to the amxp_subproc_t structure |
Definition at line 415 of file amxp_subproc.c.
amxp_signal_mngr_t* amxp_subproc_get_sigmngr | ( | const amxp_subproc_t *const | subproc | ) |
Get the Signal managers of the child process.
Using the signal manager callback functions (Slots) can be connected to the child process.
The child process will trigger signal "stop" when it exits. The data of the signal will contain all the Linux system signal information.
subproc | pointer to the amxp_subproc_t structure |
Definition at line 419 of file amxp_subproc.c.
int amxp_subproc_get_termsig | ( | amxp_subproc_t * | subproc | ) |
Gets the Linux signal id that caused the child process to stop.
If the value of WIFSIGNALED(stat_val) is non-zero, this function evaluates to the number of the signal that caused the termination of the child process.
subproc | pointer to the amxp_subproc_t structure |
Definition at line 547 of file amxp_subproc.c.
int amxp_subproc_ifexited | ( | amxp_subproc_t * | subproc | ) |
Checks if the child process terminated normally.
Evaluates to a non-zero value if status was returned for a child process that terminated normally.
subproc | pointer to the amxp_subproc_t structure |
Definition at line 517 of file amxp_subproc.c.
int amxp_subproc_ifsignaled | ( | amxp_subproc_t * | subproc | ) |
Checks if the child process was stopped because of an uncaught Linux signal.
Evaluates to a non-zero value if status was returned for a child process that terminated due to the receipt of a signal that was not caught (see <signal.h>).
subproc | pointer to the amxp_subproc_t structure |
Definition at line 527 of file amxp_subproc.c.
bool amxp_subproc_is_running | ( | const amxp_subproc_t *const | subproc | ) |
Checks if the child process is running.
Returns true when the child process is running
subproc | pointer to the amxp_subproc_t structure |
Definition at line 423 of file amxp_subproc.c.
int amxp_subproc_kill | ( | const amxp_subproc_t *const | subproc, |
const int | sig | ||
) |
Sends a Linux signal to the child process.
When the child process is not running this function has no effect.
Example:
subproc | pointer to the subproc |
sig | the signal id |
Definition at line 391 of file amxp_subproc.c.
int amxp_subproc_new | ( | amxp_subproc_t ** | subproc | ) |
Constructor function, creates a new child process data structure.
This function allocates memory, to free the allocated memory use the destruction function amxp_subproc_delete
The *subproc argument must be initialized to NULL before calling this function.
This function doesn't start the child process. To start a child process use amxp_subproc_vstart or amxp_subproc_start.
subproc | where to store the subproc pointer |
Definition at line 215 of file amxp_subproc.c.
int amxp_subproc_open_fd | ( | amxp_subproc_t * | subproc, |
int | requested | ||
) |
Opens standard file descriptor to the child process.
It is possible to read the child stdout or stderr to monitor it's output or to write to the child stdin file descriptor.
subproc | pointer to the subproc |
requested | must be one of STDIN_FILENO, STDOUT_FILENO or STDERR_FILENO |
Definition at line 263 of file amxp_subproc.c.
int amxp_subproc_start | ( | amxp_subproc_t *const | subproc, |
char * | cmd, | ||
... | |||
) |
Start a child process.
Forks and executes a command. Will monitor the child process and handles SIGCHLD.
The process name and it's arguments must be passed as individual arguments to this function. The last argument must be a NULL pointer.
Example:
subproc | pointer to the subproc |
cmd | the child process |
Definition at line 330 of file amxp_subproc.c.
int amxp_subproc_start_wait | ( | amxp_subproc_t * | subproc, |
int | timeout_msec, | ||
char * | cmd, | ||
... | |||
) |
Starts a child process and waits until it exits.
This function is blocking and will return either when the child process has exited or when a timeout occurs.
When the child process was not able to start an error is returned
This function calls amxp_subproc_vstart_wait to launch the child process and to wait until the child exits.
subproc | pointer to the subproc |
timeout_msec | time out in milli seconds |
cmd | the command used to launch the child process |
Definition at line 480 of file amxp_subproc.c.
int amxp_subproc_vstart | ( | amxp_subproc_t *const | subproc, |
char ** | argv | ||
) |
Start a child process.
Forks and executes a command. Will monitor the child process and handles SIGCHLD.
The process name and it's arguments must be passed as an array of strings, the last item in the array must be a NULL pointer.
Example:
subproc | pointer to the subproc |
argv | the child process and its arguments |
Definition at line 288 of file amxp_subproc.c.
int amxp_subproc_vstart_wait | ( | amxp_subproc_t * | subproc, |
int | timeout_msec, | ||
char ** | cmd | ||
) |
Starts a child process and waits until it exits.
This function is blocking and will return either when the child process has exited or when a timeout occurs.
When the child process was not able to start an error is returned
This function first launches the child process by calling amxp_subproc_vstart and then waits until it exits using amxp_subproc_wait.
subproc | pointer to the subproc |
timeout_msec | time out in milli seconds |
cmd | the command used to launch the child process |
Definition at line 466 of file amxp_subproc.c.
int amxp_subproc_wait | ( | amxp_subproc_t * | subproc, |
int | timeout_msec | ||
) |
Waits until the child process has stopped.
This function is blocking and will return either when the child process has stopped or when a timeout occurs.
subproc | pointer to the subproc |
timeout_msec | time out in milli-seconds |
Definition at line 428 of file amxp_subproc.c.