poser
A C framework for POsix SERvices
|
A child process. More...
#include <poser/core/process.h>
Public Member Functions | |
PSC_Process * | PSC_Process_create (const PSC_ProcessOpts *opts) |
PSC_Process default constructor. | |
int | PSC_Process_exec (PSC_Process *self, void *obj, PSC_StreamCallback cb, const char *path) |
Execute an external program in the child process. | |
int | PSC_Process_run (PSC_Process *self, void *obj, PSC_StreamCallback cb, PSC_ProcessMain main) |
Execute a given function in the child process. | |
int | PSC_Process_stop (PSC_Process *self, unsigned forceMs) |
Send signals to stop the child process. | |
PSC_Event * | PSC_Process_done (PSC_Process *self) |
The child process finished. | |
pid_t | PSC_Process_pid (const PSC_Process *self) |
The process id of the child process. | |
A child process.
This class offers creating and controlling a child process, optionally opening pipes for the standard I/O streams that are represented by instances of PSC_Connection.
There is no explicit destructor. A PSC_Process object destroys itself automatically when the child process exited and, if configured, the pipes for standard output and standard error are closed.
A hung process can be stopped with PSC_Process_stop().
PSC_Process * PSC_Process_create | ( | const PSC_ProcessOpts * | opts | ) |
PSC_Process default constructor.
Creates a new PSC_Process configured as given by the PSC_ProcessOpts passed.
opts | the options for the process |
PSC_Event * PSC_Process_done | ( | PSC_Process * | self | ) |
The child process finished.
This event fires when the child process terminated, and, if there are pipes configured for standard output and/or standard error, these pipes were closed, for example by reaching EOF. It passes a PSC_EAProcessDone instance as the event argument.
self | the PSC_Process |
int PSC_Process_exec | ( | PSC_Process * | self, |
void * | obj, | ||
PSC_StreamCallback | cb, | ||
const char * | path | ||
) |
Execute an external program in the child process.
Fails if the process was already started, if cb was required but not given, or when required system/library calls (for setting up pipes or actually forking the process) failed.
self | the PSC_Process |
obj | some object reference for the callback cb |
cb | a callback to receive PSC_Connection objects for configured pipes. This must be given if any pipes are configured. |
path | the path to the external program |
pid_t PSC_Process_pid | ( | const PSC_Process * | self | ) |
The process id of the child process.
This fails if the child is not currently running.
self | the PSC_Process |
int PSC_Process_run | ( | PSC_Process * | self, |
void * | obj, | ||
PSC_StreamCallback | cb, | ||
PSC_ProcessMain | main | ||
) |
Execute a given function in the child process.
Fails if the process was already started, if cb was required but not given, or when required system/library calls (for setting up pipes or actually forking the process) failed.
self | the PSC_Process |
obj | some object reference for the callback cb |
cb | a callback to receive PSC_Connection objects for configured pipes. This must be given if any pipes are configured. |
main | the function to execute in the child |
int PSC_Process_stop | ( | PSC_Process * | self, |
unsigned | forceMs | ||
) |
Send signals to stop the child process.
This sends the child process a TERM signal, and optionally later a KILL signal. Fails if the child process is not running or sending a KILL signal is already scheduled.
self | the PSC_Process |
forceMs | if not 0, schedule sending a KILL signal in forceMs milliseconds if the child didn't terminate until then |