//--------------------------------------------------------- // com.pipe.cc //--------------------------------------------------------- #include "check.h" // check #include // cout #include // wait #include // fork pipe int main() { const char EOS = '\0'; const int RD = 0, WR = 1; int c2p[2]; // child to parent pipe check(pipe(c2p)); // create pipe if (check(fork())) // parent/reader { char c = 0; std::cout << "parent/reader: "; do { check(read(c2p[RD], &c, 1)); if (c != '\0') std::cout << c; } while (c != '\0'); wait(nullptr); } else // child/writer { std::cout << " child/writer: "; for (char c = 'a'; c <= 'z'; ++c) { check(write(c2p[WR], &c, 1)); std::cout << c; } check(write(c2p[WR], &EOS, 1)); } std::cout << std::endl; }