#include <iostream>#include "apue.h"#include "err_msg.h"using namespace std;void print(const char * str){int pid = getpid();cout << str << endl;cout << "pid = " << pid << endl;}int main(){int n;int fd[2];pid_t pid;char line[MAXLINE];cout << "MAXLINE = " << MAXLINE << endl;if (pipe(fd) < 0){err_sys("pipe error");}if ((pid = fork()) < 0){err_sys("fork error");}else if (pid > 0) /*parent process*/{close(fd[0]);while (1) {cout << "--------------------------------" << endl;print((char *)"parent process");cout << "write the data to pipe" << endl;write(fd[1], "hello world\n", 12);cout << "--------------------------------" << endl;sleep(10);}}else /*child process*/{close(fd[1]);while (1) {print((char *)"child process");cout << "read the data from pipe" << endl;n = read(fd[0], line, MAXLINE);write(STDOUT_FILENO, line, n);sleep(15);}}return 0;}