Process#
Unix process creation and configuration.
Info
To use declarations from this page, include the <essence/process.hpp> header.
-
class process#
A Unix process abstraction.
Example
// calls the `ls` executable with `-alhF --color=auto` arguments // and then returns with the program with the exit status of the process. process p("ls", {"-alhF", "--color=auto"}); return p.spawn().wait().status();
-
std::string program#
The program name or full path to execute.
-
std::vector<std::string> arguments#
The arguments supplied to the process.
-
std::unordered_map<std::string, std::string> environment#
The process environment variables.
The default value when not supplied is to call env::map().
-
pid_t pid = -1#
When spawned, the process id.
-
std::string argzero#
The 0th argument in the exec argv, may be different from the program name.
-
bool running()#
Check if the process is alive.
-
void exec()#
Execute the process without forking, replacing the current process. Marked with the
[[noreturn]]attribute.
-
std::string program#
-
class pipeline#
Unix pipeline abstraction leveraging the process class.
Example
auto pl = process("echo", {"Hello there friend"}) | process("grep", {"-v", "-i", "i"}) | process("grep", {"-v", "-i", "t"}); pl.run(); // outputs: "Hello"
-
pipeline operator|(pipeline lhs, process rhs)#
Construct a pipeline from an existing pipeline and a process.
-
class output#
A container for process standard output and error.
-
std::string out#
The standard output.
-
std::string err#
The standard error.
-
std::string out#
-
class ioport#
Represents an IO stream as it relates to a process.
-
ioport::ioport(const std::filesystem::path &path)#
Alternative constructor accepting a filesystem path.
-
static ioport::input()#
Static constructor using
STDIN_FILENO.
-
static ioport::output()#
Static constructor using
STDOUT_FILENO.
-
static ioport::error()#
Static constructor using
STDERR_FILENO.
-
static ioport::null()#
Static constructor using
/dev/null.
-
bool is_open() const#
Check if the port is open.
-
void close()#
Close the port
-
operator bool() const#
Implicit conversion to bool.
-
ioport::ioport(const std::filesystem::path &path)#