Question: 1. Test Communication Using Pipes: Download and run the code (P1_Code.c) below and answer the following questions: #include #include #include #include #define MSG_SIZE 32 //same

1. Test Communication Using Pipes: Download and run the code (P1_Code.c) below and answer the following questions:

#include  #include  #include  #include  #define MSG_SIZE 32 //same size messages char *pkt[] = { "Msg_1: Hello CIS370", "Msg_2: Hello CIS370", "Msg_3: Hello CIS370" }; int main() { int bytesWritten, bytesRead, index; int pipeFD[2]; char Buffer[MSG_SIZE]; if(pipe(pipeFD) == -1) { perror("pipe call error"); exit(1); } bytesWritten = write(pipeFD[1], pkt[0], MSG_SIZE); bytesWritten = write(pipeFD[1], pkt[1], MSG_SIZE); bytesWritten = write(pipeFD[1], pkt[2], MSG_SIZE); /* read pipe */ for(index=0; index<3; index++) { bytesRead = read(pipeFD[0], Buffer, MSG_SIZE); printf("%s (Chars read: %d) ", Buffer, bytesRead); } return 1; } 

a. How many bytes are written to the upstream end of the pipe?

b. How many bytes are read from the downstream end of the pipe?

c. Change the code in line 32 to read 10 bytes instead of MSG_SIZE. Show the output of the code and explain what is being printed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!