Question: #include #include #include #include #define BUFFER_SIZE 25 #define READ_END 0 #define WRITE_END 1 int main(void) { char writeMsg[BUFFER_SIZE] = Greetings; char readMsg[BUFFER_SIZE]; int fd[2]; pid_t
#include
#define BUFFER_SIZE 25 #define READ_END 0 #define WRITE_END 1
int main(void) {
char writeMsg[BUFFER_SIZE] = "Greetings"; char readMsg[BUFFER_SIZE]; int fd[2]; pid_t pid;
/* create the pipe */ if (pipe(fd) == -1) { fprintf(stderr, "Pipe failed"); return 1; } /* fork a child process */ pid = fork(); if (pid
/* error occurred */ fprintf(stderr, "Fork failed"); return 1; } if (pid > 0) {
/* parent process */ printf ("Parent id is %d )", pid) /* close the unused end of the pipe */ close(fd[READ_END]);
/* write to the pipe */ write(fd[WRITE_END], writeMsg, strlen(writeMsg) + 1);
/* close the write end of the pipe */
close(fd[WRITE_END]); } else {
/* child process */ x /* close the unused end of the pipe */
close(fd[WRITE_END]);
/* read from the pipe */
read(fd[READ_END], readMsg, BUFFER_SIZE); printf("read %s ", readMsg);
/* close the read end of the pipe */
close(fd[READ_END]); }
return 0;
} 
ter 1. Display the pid of the parent and child after the fork. 2. Display termination messages for the parent and child. 3. Modify this program so that the parent does not exit until the child terminates so that output looks in sequence. Add a second pipe in which the child can send data to the parent by the following steps: i. Parent writes some data to the child via the existing pipe. ii. Child reads this data, adds some text to it and writes back to the parent the resultant data. iii. Parent reads this data and displays it
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
