-
Notifications
You must be signed in to change notification settings - Fork 0
/
Process.hpp
57 lines (43 loc) · 1.15 KB
/
Process.hpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _PROCESS_HPP_
#define _PROCESS_HPP_
#include <sys/types.h>
#include <sys/poll.h>
#include <iostream>
#include <vector>
#define PARENT_READ m_readpipe[0]
#define CHILD_WRITE m_readpipe[1]
#define CHILD_READ m_writepipe[0]
#define PARENT_WRITE m_writepipe[1]
class Process
{
public:
//The extra bool argument can be used to enable verbose messages
Process(const std::vector<char*>&, bool verbose);
Process(const std::vector<char*>&);
// prevent copying and assignment
Process(const Process &p);
Process& operator=(const Process &p);
//Implement a move constructor
Process(Process& other);
Process& operator=(Process& other);
~Process();
void write(const std::string&);
std::string read();
bool stop();
bool resume();
//int wait();
int status();
private:
bool verbose;
std::string m_name;
//PID of child process
pid_t m_pid;
int m_status;
//File descriptors for writing/reading to/from process
int m_writepipe[2];
int m_readpipe[2];
//File stream to write/read to/from child process
FILE* m_pwrite;
FILE* m_pread;
};
#endif