A simple process management library for C++ on UNIX platforms.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
include
.clang-format Update clang-format and reformat process.h accordingly. Oct 22, 2015
.gitignore Initial commit Feb 23, 2014
LICENSE Initial commit Feb 23, 2014
README.md Wrap header in a namespace. Oct 22, 2015
cl_clang.sh Fix for some warrnings from clang. May 21, 2016
cl_gcc.sh Fix for some warrnings from clang. May 21, 2016
sample.cpp Small sample. May 21, 2016

README.md

procxx

A simple process management library for C++ on UNIX platforms.

Usage

Here is a simple (toy) example of setting up a very basic pipeline.

// construct a child process that runs `cat`
procxx::process cat{"cat"};

// construct a child process that runs `wc -c`
procxx::process wc{"wc", "-c"};

// set up the pipeline and execute the child processes
(cat | wc).exec();

// write "hello world" to the standard input of the cat child process
cat << "hello world";

// close the write end (stdin) of the cat child
cat.close(procxx::pipe_t::write_end());

// read from the `wc -c` process's stdout, line by line
std::string line;
while (std::getline(wc.output(), line))
    std::cout << line << std::endl;

procxx also provides functionality for setting resource limits on the child processes, as demonstrated below. The functionality is implemented via the POSIX rlimit functions.

procxx::process cat{"cat"};
procxx::process wc{"wc", "-c"};

// OPTION 1: same limits for all processes in the pipeline
procxx::process::limits_t limits;
limits.cpu_time(3);         // 3 second execution time limit
limits.memory(1024*1024*1); // 1 MB memory usage limit
(cat | wc).limit(limits).exec();

// OPTION 2: individual limits for each process
procxx::process::limits_t limits;
limits.cpu_time(3);         // 3 second execution time limit
limits.memory(1024*1024*1); // 1 MB memory usage limit
wc.limit(limits);

procxx::process::limits_t limits;
limits.cpu_time(1);  // 1 second execution time limit
limits.memory(1024); // 1 KB memory usage limit
cat.limit(limits);

(cat | wc).exec();