| 1 |
#include "../pipe.h" |
| 2 |
#include "../fork.h" |
| 3 |
#include "../selector.h" |
| 4 |
|
| 5 |
#include <sys/types.h> |
| 6 |
#include <signal.h> |
| 7 |
#include <sys/wait.h> |
| 8 |
|
| 9 |
#include <iostream> |
| 10 |
|
| 11 |
//CLASS |
| 12 |
class Child: public Fork |
| 13 |
{ |
| 14 |
Pipe d_in; |
| 15 |
Pipe d_out; |
| 16 |
|
| 17 |
int d_parentReadFd; |
| 18 |
int d_parentWriteFd; |
| 19 |
int d_nr; |
| 20 |
|
| 21 |
public: |
| 22 |
Child(int nr); |
| 23 |
~Child() override; |
| 24 |
int readFd() const; |
| 25 |
int writeFd() const; |
| 26 |
int pid() const; |
| 27 |
int nr() const; |
| 28 |
private: |
| 29 |
void childRedirections() override; |
| 30 |
void parentRedirections() override; |
| 31 |
void childProcess() override; |
| 32 |
void parentProcess() override; |
| 33 |
}; |
| 34 |
//= |
| 35 |
|
| 36 |
//CONS |
| 37 |
inline Child::Child(int nr) |
| 38 |
: |
| 39 |
d_nr(nr) |
| 40 |
{} |
| 41 |
//= |
| 42 |
//PIPES |
| 43 |
inline int Child::readFd() const |
| 44 |
{ |
| 45 |
return d_parentReadFd; |
| 46 |
} |
| 47 |
inline int Child::writeFd() const |
| 48 |
{ |
| 49 |
return d_parentWriteFd; |
| 50 |
} |
| 51 |
//= |
| 52 |
//PIDNR |
| 53 |
inline int Child::pid() const |
| 54 |
{ |
| 55 |
return Fork::pid(); |
| 56 |
} |
| 57 |
inline int Child::nr() const |
| 58 |
{ |
| 59 |
return d_nr; |
| 60 |
} |
| 61 |
//= |
| 62 |
inline void Child::parentProcess() |
| 63 |
{} |