Question: Write a C program that creates a pipe and forks a child process. The parent then sendsthe following message on his side of the pipe
Write a C program that creates a pipe and forks a child process. The parent then sendsthe following message on his side of the pipe I am your daddy! and my name is , the child receives this message and prints it to its stdout verbatim.The parent then blocks reading on the pipe from the child. The child writes back to its parent through its side of the pipe stating Daddy, my name is . The parent then writes the message received from the child to its stdout. Make sure the parentwaits on the child exit as to not creating orphans or zombies: creating such leftover willresult in zero grade.
I have this solution, is this correct?
#include
if(read(pc_pipe[0], read_buffer, BUFSIZ) == -1) { exit(EXIT_FAILURE); } printf("%s", read_buffer); dprintf(cp_pipe[1], "Daddy, my name is %d", getpid()); }
else { close(pc_pipe[0]); close(cp_pipe[1]); dprintf(pc_pipe[1], "I am your daddy! and my name is %d ", getpid()); if(read(cp_pipe[0], read_buffer, BUFSIZ) == -1) { exit(EXIT_FAILURE); } printf("%s", read_buffer); } exit(EXIT_SUCCESS);}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
