Beamlib 3.3.2
This is the Beam C++ class library.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BProc Class Reference

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ BProc()

BProc::BProc ( )

◆ ~BProc()

BProc::~BProc ( )

Member Function Documentation

◆ usePipes()

BError BProc::usePipes ( Bool  fileIn,
Bool  fileOut,
Bool  fileErr 
)

Enable IO pipes for the processes standard file descriptors.

◆ runForeground()

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.

◆ runBackground()

BError BProc::runBackground ( BString  cmd,
BStringList  argList = BStringList() 
)

Run the program in the background.

◆ getPid()

int BProc::getPid ( )

Return the process ID of the program.

◆ getFd()

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.

◆ wait()

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.

◆ kill()

BError BProc::kill ( int  sig = SIGTERM)

Kill the process by sending it a signal.

◆ finish()

void BProc::finish ( )

Tidy up when finised (closes all pipes).


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