poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
PSC_Process Class Reference

A child process. More...

#include <poser/core/process.h>

Public Member Functions

PSC_ProcessPSC_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_EventPSC_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.
 

Detailed Description

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().

Member Function Documentation

◆ PSC_Process_create()

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.

Parameters
optsthe options for the process

◆ PSC_Process_done()

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.

Parameters
selfthe PSC_Process
Returns
the done event

◆ PSC_Process_exec()

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.

Parameters
selfthe PSC_Process
objsome object reference for the callback cb
cba callback to receive PSC_Connection objects for configured pipes. This must be given if any pipes are configured.
paththe path to the external program
Returns
0 on success, -1 on error

◆ PSC_Process_pid()

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.

Parameters
selfthe PSC_Process
Returns
the process id, or -1 on error

◆ PSC_Process_run()

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.

Parameters
selfthe PSC_Process
objsome object reference for the callback cb
cba callback to receive PSC_Connection objects for configured pipes. This must be given if any pipes are configured.
mainthe function to execute in the child
Returns
0 on success, -1 on error

◆ PSC_Process_stop()

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.

Parameters
selfthe PSC_Process
forceMsif not 0, schedule sending a KILL signal in forceMs milliseconds if the child didn't terminate until then
Returns
0 on success, -1 on error

The documentation for this class was generated from the following file: