- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Types | Static Public Member Functions | Friends | List of all members
G::NewProcess Class Reference

A static interface for creating new processes. More...

`#include <gnewprocess.h>`

## Classes
class | ChildProcess
| Represents the state of a child process. More...
class | ChildProcessImp
| A private implementation class used by G::NewProcess. More...

## Public Types
enum | Who { Parent, Child }

## Static Public Member Functions
static Who | fork ()
| Forks a child process. More...
static Who | fork (Process::Id &child)
| Forks a child process. More...
static int | spawn (Identity nobody, const Path &exe, const Strings &args, std::string *pipe_result_p=NULL, int error_return=127, std::string(*error_decode_fn)(int)=0)
| Runs a command in an unprivileged child process. More...
static ChildProcess | spawn (const Path &exe, const Strings &args)
| A simple overload to spawn a child process asynchronously. More...

## Friends
class | ChildProcess

## Detailed Description

A static interface for creating new processes.

See also
  G::Daemon, G::NewProcess

Definition at line 42 of file gnewprocess.h.

## Member Enumeration Documentation

enum G::NewProcess::Who

Enumerator
Parent |
Child |

Definition at line 53 of file gnewprocess.h.

## Member Function Documentation

G::NewProcess::Who G::NewProcess::fork | ( |  | ) |
| static

Forks a child process.

Definition at line 134 of file gnewprocess_unix_exec_enabled.cpp.

Referenced by G::Daemon::detach(), fork(), and spawn().

G::NewProcess::Who G::NewProcess::fork | ( | Process::Id & | child | ) |
| static

Forks a child process.

Returns the child pid by reference to the parent.

Definition at line 140 of file gnewprocess_unix_exec_enabled.cpp.

References Child, fork(), and Parent.

int G::NewProcess::spawn | ( | Identity | nobody,
|  | const Path & | exe,
|  | const Strings & | args,
|  | std::string * | pipe_result_p = `NULL`,
|  | int | error_return = `127`,
|  | std::string(*)(int) | error_decode_fn = `0`
| ) |  |
| static

Runs a command in an unprivileged child process.

Returns the child process's exit code, or 'error_return' on error.

The 'nobody' identity should have come from beOrdinary().

If the 'pipe_result_p' pointer is supplied then the child process is given a pipe as its stdout and this is used to read the first bit of whatever it writes.

If the function pointer is supplied then it is used to generate a string that is written into the pipe if the exec() fails in the fork()ed child process.

Definition at line 232 of file gnewprocess_unix_exec_enabled.cpp.

References G::Process::beNobody(), Child, G::Process::closeFiles(), G::Pipe::dup(), G::Identity::effective(), G::Pipe::fd(), fork(), G_ASSERT, G::Pipe::inChild(), G::Pipe::inParent(), G::Path::isRelative(), G::Identity::isRoot(), G::Pipe::read(), and G::Path::str().

G::NewProcess::ChildProcess G::NewProcess::spawn | ( | const Path & | exe,
|  | const Strings & | args
| ) |  |
| static

A simple overload to spawn a child process asynchronously.

Does no special security checks.

Definition at line 207 of file gnewprocess_unix_exec_enabled.cpp.

References Child, ChildProcess, G::Process::closeFiles(), G::Pipe::dup(), G::Pipe::fd(), fork(), G::Pipe::inChild(), G::Pipe::inParent(), G::NewProcess::ChildProcessImp::m_id, and G::NewProcess::ChildProcessImp::m_pipe.

## Friends And Related Function Documentation

friend class ChildProcess
| friend

Definition at line 96 of file gnewprocess.h.

Referenced by spawn().

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

- gnewprocess.h
- gnewprocess_unix_exec_enabled.cpp