gmerlin
Data Structures | Functions
Subprocesses

Subprocesses with pipable stdin, stdout and stderr. More...

Data Structures

struct  bg_subprocess_t
 Subprocess handle. More...
 

Functions

bg_subprocess_tbg_subprocess_create (const char *command, int do_stdin, int do_stdout, int do_stderr)
 Create a subprocess.
 
void bg_subprocess_kill (bg_subprocess_t *proc, int signal)
 Send a signal to a process.
 
int bg_subprocess_close (bg_subprocess_t *proc)
 Close a subprocess and free all associated memory.
 
int bg_subprocess_read_line (int fd, char **ret, int *ret_alloc, int timeout)
 Read a line from stdout or stderr of a process.
 
int bg_subprocess_read_data (int fd, uint8_t *ret, int len)
 Read data from stdout or stderr of a process.
 
int bg_system (const char *command)
 Run a command as a subprocess.
 

Detailed Description

Subprocesses with pipable stdin, stdout and stderr.

Function Documentation

◆ bg_subprocess_create()

bg_subprocess_t * bg_subprocess_create ( const char * command,
int do_stdin,
int do_stdout,
int do_stderr )

Create a subprocess.

Parameters
commandCommand, will be passed to /bin/sh
do_stdin1 if stdin should be connected by a pipe, 0 else
do_stdout1 if stdout should be connected by a pipe, 0 else
do_stderr1 if stderr should be connected by a pipe, 0 else

A new handle with the runnig child program or NULL

◆ bg_subprocess_kill()

void bg_subprocess_kill ( bg_subprocess_t * proc,
int signal )

Send a signal to a process.

Parameters
procA subprocess
signalWhich signal to send

Types for signal are the same as in <signal.h>

◆ bg_subprocess_close()

int bg_subprocess_close ( bg_subprocess_t * proc)

Close a subprocess and free all associated memory.

Parameters
procA subprocess
Returns
The return code of the program

◆ bg_subprocess_read_line()

int bg_subprocess_read_line ( int fd,
char ** ret,
int * ret_alloc,
int timeout )

Read a line from stdout or stderr of a process.

Parameters
fdThe filesecriptor
retString (will be realloced)
ret_allocAllocated size of the string (will be changed with each realloc)
timeoutTimeout in milliseconds
Returns
1 if a line could be read, 0 else

◆ bg_subprocess_read_data()

int bg_subprocess_read_data ( int fd,
uint8_t * ret,
int len )

Read data from stdout or stderr of a process.

Parameters
fdThe filesecriptor
retPointer to allocated memory, where the data will be placed
lenHow many bytes to read
Returns
The number of bytes read

If the return value is smaller than the number of bytes you requested, you can assume, that the process finished and won't send more data.

◆ bg_system()

int bg_system ( const char * command)

Run a command as a subprocess.

Parameters
commandCommand to run
Returns
Return code of the program

This is pretty much the same as the system() function