Fork a child process.
More...
#include <childprocess.h>
◆ ChildProcess()
wibble::sys::ChildProcess::ChildProcess |
( |
| ) |
|
|
inline |
◆ ~ChildProcess()
virtual wibble::sys::ChildProcess::~ChildProcess |
( |
| ) |
|
|
inlinevirtual |
◆ exitStatus()
int wibble::sys::ChildProcess::exitStatus |
( |
| ) |
|
◆ fork()
pid_t wibble::sys::ChildProcess::fork |
( |
| ) |
|
◆ forkAndRedirect()
pid_t wibble::sys::ChildProcess::forkAndRedirect |
( |
int * |
stdinfd = 0 , |
|
|
int * |
stdoutfd = 0 , |
|
|
int * |
stderrfd = 0 |
|
) |
| |
|
inline |
◆ kill()
void wibble::sys::ChildProcess::kill |
( |
int |
signal | ) |
|
◆ main()
◆ pid()
pid_t wibble::sys::ChildProcess::pid |
( |
| ) |
const |
|
inline |
Get the pid of the child process or (pid_t)-1 if no child is running.
Note: while ChildProcess::kill() has a safeguard against killing pid -1, if you are going to run kill on the output of pid() make sure to check what is the semanthics of kill() when pid is -1.
References _pid.
◆ running()
bool wibble::sys::ChildProcess::running |
( |
| ) |
|
◆ setExec()
void wibble::sys::ChildProcess::setExec |
( |
std::string |
command | ) |
|
|
inline |
Instead of calling the main() function of this class, execute an external command.
The command is passed to the shell interpreter of the system (/bin/sh on UNIX, CreateProcess on Windows).
References m_command, and m_doExec.
◆ setupChild()
void wibble::sys::ChildProcess::setupChild |
( |
| ) |
|
|
protected |
◆ setupParent()
void wibble::sys::ChildProcess::setupParent |
( |
| ) |
|
|
protected |
◆ setupPipes()
void wibble::sys::ChildProcess::setupPipes |
( |
| ) |
|
|
protected |
◆ setupPrefork()
void wibble::sys::ChildProcess::setupPrefork |
( |
| ) |
|
|
protected |
◆ setupRedirects()
void wibble::sys::ChildProcess::setupRedirects |
( |
int * |
stdinfd = 0 , |
|
|
int * |
stdoutfd = 0 , |
|
|
int * |
stderrfd = 0 |
|
) |
| |
◆ spawnChild()
void wibble::sys::ChildProcess::spawnChild |
( |
| ) |
|
|
protectedvirtual |
On Windows, it's impossible to fork(), but if you were to fork+exec, it's not all lost.
You can implement spawnChild() instead of main(), which needs to call CreateProcess, spawn or similar. The redirections requested by setupRedirects are respected. Exec and ShellProcess implement spawnChild on Windows.
NB. For wait() to work, the si/pi member variables need to be filled in by the implementation.
Reimplemented in wibble::sys::Exec.
References assert_die.
◆ wait()
◆ waitError()
void wibble::sys::ChildProcess::waitError |
( |
| ) |
|
|
protected |
◆ waitForSuccess()
void wibble::sys::ChildProcess::waitForSuccess |
( |
| ) |
|
◆ _pid
pid_t wibble::sys::ChildProcess::_pid |
|
protected |
◆ _stderr
int * wibble::sys::ChildProcess::_stderr |
|
protected |
◆ _stdin
int* wibble::sys::ChildProcess::_stdin |
|
protected |
◆ _stdout
int * wibble::sys::ChildProcess::_stdout |
|
protected |
◆ m_command
std::string wibble::sys::ChildProcess::m_command |
|
protected |
◆ m_doExec
bool wibble::sys::ChildProcess::m_doExec |
|
protected |
◆ m_status
int wibble::sys::ChildProcess::m_status |
|
protected |
◆ pipes
int wibble::sys::ChildProcess::pipes[3][2] |
|
protected |
The documentation for this class was generated from the following files: