CppCommon  1.0.4.1
C++ Common Library
system_process.cpp

Process example

#include "system/process.h"
#include <iostream>
int main(int argc, char** argv)
{
if (argc > 1)
{
std::cout << "Executing child process..." << std::endl;
int result = child.Wait();
std::cout << "Executed child process! Result = " << result << std::endl;
return 0;
}
std::cout << "Current process Id: " << CppCommon::Process::CurrentProcessId() << std::endl;
std::cout << "Parent process Id: " << CppCommon::Process::ParentProcessId() << std::endl;
return 123;
}
Process abstraction.
Definition: process.h:38
static Process Execute(const std::string &command, const std::vector< std::string > *arguments=nullptr, const std::map< std::string, std::string > *envars=nullptr, const std::string *directory=nullptr, Pipe *input=nullptr, Pipe *output=nullptr, Pipe *error=nullptr)
Execute a new process.
Definition: process.cpp:549
static uint64_t ParentProcessId() noexcept
Get the parent process Id.
Definition: process.cpp:545
int Wait()
Wait the process to exit.
Definition: process.cpp:541
static uint64_t CurrentProcessId() noexcept
Get the current process Id.
Definition: process.cpp:544
Process definition.