Beamlib 3.1.1
This is the Beam C++ class library.
|
Implements system process manager. More...
#include <BProc.h>
Public Member Functions | |
BProc () | |
~BProc () | |
BError | usePipes (Bool fileIn, Bool fileOut, Bool fileErr) |
Enable IO pipes for the processes standard file descriptors. More... | |
BError | runForeground (BString cmd, BStringList argList=BStringList(), int *status=0, int timeoutMs=-1) |
Run the program in the foreground with optional status return value and timeout. More... | |
BError | runBackground (BString cmd, BStringList argList=BStringList()) |
Run the program in the background. More... | |
int | getPid () |
Return the process ID of the program. More... | |
int | getFd (int cmdFd) |
Return the stdin - 0, stdout - 1 or stderr -2 file descriptor pipes to send or receive data to/from the process. More... | |
BError | wait (int &status, int timeoutMs=-1) |
Wait for the process to complete. The programs exist status is returned in status. The call will block unless the timeoutMs value is given. More... | |
BError | kill (int sig=SIGTERM) |
Kill the process by sending it a signal. More... | |
void | finish () |
Tidy up when finised (closes all pipes). More... | |
Implements system process manager.
BProc class. This class is used to run programs on the system.
A system program can be run either in the forground where the run function will block or in the background. In both cases the full path of the program is provided in the cmd argument and a set of optional program arguments is provided in the argList argument. The processes arg0 value is set to the programs file name.
When run in the foreground with runForeground() function, the user can supply an int pointer to return the programs exit status and a timeout in ms to wait for the process to complete. By default the timeout of -1 means the function will wait forever. If the status pointer is NULL, then the programs return status will be returned in the BError return value otherwise the return BError will be set to an appropriate error status.
When run in the background with runBackground() function, the parenet process can wait for completion using the wait() call. The wait() call will return the programs exit status or an error. The exit staus value is the same as the normal wait() system call.
The processes standard 0, 1, 2 file descriptors can be overriden with IO pipes using the usePipes() function. If any of these pipes are enabled, then the getFd() function will return the parant processe's file descriptor for writing or reading data from the processe's standard file descriptors. The usePipes() function should be called before each run call.
BProc::BProc | ( | ) |
BProc::~BProc | ( | ) |
Enable IO pipes for the processes standard file descriptors.
BError BProc::runForeground | ( | BString | cmd, |
BStringList | argList = BStringList() , |
||
int * | status = 0 , |
||
int | timeoutMs = -1 |
||
) |
Run the program in the foreground with optional status return value and timeout.
BError BProc::runBackground | ( | BString | cmd, |
BStringList | argList = BStringList() |
||
) |
Run the program in the background.
int BProc::getPid | ( | ) |
Return the process ID of the program.
int BProc::getFd | ( | int | cmdFd | ) |
Return the stdin - 0, stdout - 1 or stderr -2 file descriptor pipes to send or receive data to/from the process.
BError BProc::wait | ( | int & | status, |
int | timeoutMs = -1 |
||
) |
Wait for the process to complete. The programs exist status is returned in status. The call will block unless the timeoutMs value is given.
BError BProc::kill | ( | int | sig = SIGTERM | ) |
Kill the process by sending it a signal.
void BProc::finish | ( | ) |
Tidy up when finised (closes all pipes).