| 1 |
|
| 2 |
// compile with 'g++ parentslurp.cc fork.cc waitforchild.cc pipe.cc' |
| 3 |
|
| 4 |
#include "fork.h" |
| 5 |
#include "pipe.h" |
| 6 |
#include <unistd.h> |
| 7 |
//CLASS |
| 8 |
class ParentSlurp: public Fork |
| 9 |
{ |
| 10 |
Pipe d_pipe; |
| 11 |
|
| 12 |
void childRedirections() override; |
| 13 |
void parentRedirections() override; |
| 14 |
void childProcess() override; |
| 15 |
void parentProcess() override; |
| 16 |
}; |
| 17 |
//= |
| 18 |
|
| 19 |
//CHILDREDIR |
| 20 |
inline void ParentSlurp::childRedirections() |
| 21 |
{ |
| 22 |
d_pipe.writtenBy(STDOUT_FILENO); |
| 23 |
} |
| 24 |
//= |
| 25 |
//PARENTREDIR |
| 26 |
inline void ParentSlurp::parentRedirections() |
| 27 |
{ |
| 28 |
d_pipe.readFrom(STDIN_FILENO); |
| 29 |
} |
| 30 |
//= |
| 31 |
//CHILDPROC |
| 32 |
inline void ParentSlurp::childProcess() |
| 33 |
{ |
| 34 |
execl("/bin/ls", "/bin/ls", 0); |
| 35 |
} |
| 36 |
//= |