Question: Download and run the code (P2_Code.c) below and answer the following questions: #include #include #include #include #include #include char *pkt[2] = { Hello there from
Download and run the code (P2_Code.c) below and answer the following questions:
#include#include #include #include #include #include char *pkt[2] = { "Hello there from CIS370", "Hope you have been enjoying the lab" }; int main(int argc, char *argv[]) { int pipeFD[2]; int charCount; char buffer[32]; pipe(pipeFD); /* set up pipe */ if (fork() == 0) { close(pipeFD[1]); /* child reads (closes p[1]) */ while ((charCount = read(pipeFD[0], buffer, 8)) != 0) { buffer[charCount ] = '\0'; /* string terminator */ printf("%d chars :\"%s\": received by child ", charCount , buffer); } close(pipeFD[0]); exit(0); /* child done */ } close(pipeFD[0]); /* parent process */ wait(NULL); write(pipeFD[1], pkt[0], strlen(pkt[0])); write(pipeFD[1], pkt[1], strlen(pkt[1])); close(pipeFD[1]); //line 33 /* finished writing p[1] */ return 1; }
a. Comment line 33 and run the code again. How does the code behave? Explain the behavior?
b. Uncomment line 33 and move line 34 after line 30 then run the code again. How does the code behave? Explain the behavior?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
