Skip to content

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

License

Notifications You must be signed in to change notification settings

skystrife/procxx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published