BRL-CAD
Subprocess Management

Routines for launching and managing applications as subprocesses. More...

Collaboration diagram for Subprocess Management:

Files

file  process.h
 

Enumerations

enum  bu_process_io_t { BU_PROCESS_STDIN , BU_PROCESS_STDOUT , BU_PROCESS_STDERR }
 

Functions

int bu_process_id (void)
 
int bu_terminate (int process)
 terminate a given process and any children. More...
 
FILE * bu_process_open (struct bu_process *pinfo, bu_process_io_t d)
 
void bu_process_close (struct bu_process *pinfo, bu_process_io_t d)
 
int bu_process_fileno (struct bu_process *pinfo, bu_process_io_t d)
 
int bu_process_pid (struct bu_process *pinfo)
 
int bu_process_args (const char **cmd, const char *const **argv, struct bu_process *pinfo)
 
int bu_process_read (char *buff, int *count, struct bu_process *pinfo, bu_process_io_t d, int n)
 
void bu_process_exec (struct bu_process **info, const char *cmd, int argc, const char **argv, int out_eql_err, int hide_window)
 Wrapper for executing a sub-process. More...
 
int bu_process_wait (int *aborted, struct bu_process *pinfo, int wtime)
 wait for a sub-process to complete, release all process allocations, and release the process itself. More...
 
int bu_interactive (void)
 detect whether or not a program is being run in interactive mode More...
 

Detailed Description

Routines for launching and managing applications as subprocesses.

Routines for process and sub-process management.

Enumeration Type Documentation

◆ bu_process_io_t

Enumerator
BU_PROCESS_STDIN 
BU_PROCESS_STDOUT 
BU_PROCESS_STDERR 

Definition at line 55 of file process.h.

Function Documentation

◆ bu_process_id()

int bu_process_id ( void  )

returns the process ID of the calling process

◆ bu_terminate()

int bu_terminate ( int  process)

terminate a given process and any children.

returns truthfully whether the process could be killed.

◆ bu_process_open()

FILE * bu_process_open ( struct bu_process *  pinfo,
bu_process_io_t  d 
)

Open and return a FILE pointer associated with the specified file descriptor for input (0), output (1), or error (2) respectively.

Input will be opened write, output and error will be opened read.

Caller should not close these FILE pointers directly. Call bu_process_close() instead.

FIXME: misnomer, this does not open a process. Probably doesn't need to exist; just call fdopen().

◆ bu_process_close()

void bu_process_close ( struct bu_process *  pinfo,
bu_process_io_t  d 
)

Close any FILE pointers internally opened via bu_process_open().

FIXME: misnomer, this does not close a process. Probably doesn't need to exist; just call fclose().

◆ bu_process_fileno()

int bu_process_fileno ( struct bu_process *  pinfo,
bu_process_io_t  d 
)

Retrieve the file descriptor to the input (BU_PROCESS_STDIN), output (BU_PROCESS_STDOUT), or error (BU_PROCESS_STDERR) I/O channel associated with the process.

For Windows cases where HANDLE is needed, use _get_osfhandle

◆ bu_process_pid()

int bu_process_pid ( struct bu_process *  pinfo)

Return the pid of the subprocess.

FIXME: seemingly redundant or combinable with bu_process_id() (perhaps make NULL be equivalent to the current process).

◆ bu_process_args()

int bu_process_args ( const char **  cmd,
const char *const **  argv,
struct bu_process *  pinfo 
)

Reports one or both of the command string and the argv array used to execute the process.

The bu_process container owns all strings for both cmd and argv - for the caller they are read-only.

If either cmd or argv are NULL they will be skipped - if the caller only wants one of these outputs the other argument can be set to NULL.

Parameters
[out]cmd- pointer to the cmd string used to launch pinfo
[out]argv- pointer to the argv array used to launch pinfo
[in]pinfo- the bu_process structure of interest
Returns
the corresponding argc count for pinfo's argv array.

◆ bu_process_read()

int bu_process_read ( char *  buff,
int *  count,
struct bu_process *  pinfo,
bu_process_io_t  d,
int  n 
)

Read up to n bytes into buff from a process's specified output channel (fd == 1 for output, fd == 2 for err).

FIXME: arg ordering and input/output grouping is wrong. partially redundant with bu_process_fd() and/or bu_process_open().

◆ bu_process_exec()

void bu_process_exec ( struct bu_process **  info,
const char *  cmd,
int  argc,
const char **  argv,
int  out_eql_err,
int  hide_window 
)

Wrapper for executing a sub-process.

FIXME: eliminate the last two options so all callers are not exposed to parameters not relevant to them.

◆ bu_process_wait()

int bu_process_wait ( int *  aborted,
struct bu_process *  pinfo,
int  wtime 
)

wait for a sub-process to complete, release all process allocations, and release the process itself.

FIXME: 'aborted' argument may be unnecessary (could make function provide return value of the process waited for). wtime undocumented.

◆ bu_interactive()

int bu_interactive ( void  )

detect whether or not a program is being run in interactive mode

Returns 1 if interactive, else 0