blob: 1c0789d968e211607a1ad2e767a63e394bfdb636 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#pragma once
#include <deque>
#include <string>
#include <boost/process.hpp>
struct process
{
process(const std::string& k, const std::string& command): key{k}, child{command} {}
std::string key;
boost::process::child child;
};
// runs a number of processes in parallel, with an upper limit
class ProcessRunner
{
public:
ProcessRunner();
void spawn(const std::string& key, const std::string& command);
bool empty(); // number of running processes is zero
bool full(); // number of running processes equals maximum
int wait_one(std::string& key); // returns exit code, and key via reference
int wait_all();
size_t running(); // number of running processes in queue
size_t finished(); // number of finished processes in queue
private:
int _max_number_of_processes;
std::deque<process> _processes;
};
|