Menu
support@authoritypapers.com
+1(805) 568 7317

code include include include include include include void main int fd1 2 int fd2 2 i 5150359

Please read the question carefully and in full and then answer it (using C language and any necessary libraries). (I am not s

CODE:

#include
#include
#include
#include
#include
#include

void main()
{
   int fd1[2];
   int fd2[2];
   int pid1 = 0, pid2 = 0;

/* register pipe 1 */
   if(pipe(fd1) == -1)
   {
       perror(“Pipe1”);
       return;
   }
/* register pipe 2 */
   if(pipe(fd2) == -1)
   {
       perror(“Pipe2”);
       return;
   }
/* create child 1 process */
   if((pid1 = fork()) == 0)
   {
       int i=0;
       char data[64] = {0};
       /* send data in pipe 1 from 1 to 100 */
       for(i=1; i
       {
           memset(data, 0 , sizeof(data)); // clear buffer
           sprintf(data,”child – 1, data – %dn”,i); // copy data in child 1 into data
           write(fd1[1],data,strlen(data)); // send data over pipe
           sleep(0.01);
       }
       memset(data, 0 , sizeof(data)); // clear buffer
       sprintf(data,”end”);
       write(fd1[1],data,strlen(data)); // send end to pipe to indicate data is over
       close(fd1[1]);

   }
   else
   {
       /* create child 2 process */
       if((pid2 = fork()) == 0)
       {
           int i=0;
           char data[64] = {0};
           /* send data in pipe 1 from 1 to 100 */
           for(i=1; i
           {
               memset(data, 0 , sizeof(data)); // clear buffer
               sprintf(data,”child – 2, data – %dn”,i); // copy data and child 2 in data
               write(fd2[1],data,strlen(data)); // send data in pipe
               sleep(0.01);
           }
           memset(data, 0 , sizeof(data)); // clear buffer
           sprintf(data,”end”);
           write(fd2[1],data,strlen(data)); // send end to pipe to indicate data is over
           close(fd2[1]);
       }
       else
       {
           char data1[64] = {0};
           char data2[64] = {0};
           int status = 0;
           int flag1 = 0;
           int flag2 = 0;
           close(fd1[1]); // close fd1 writing end
           close(fd2[1]); // close fd1 writing end
           while(1)
           {
              
               memset(data1, 0 ,sizeof(data1)); // clean buffer
               memset(data2, 0 ,sizeof(data2));
               if(flag1 != 1 )
                   read(fd1[0], data1, sizeof(data1)); // read from pipe 1
               if(flag2 != 1)
                   read(fd2[0], data2, sizeof(data2)); // read from pipe 2
              
               if(strstr(data1,”end”)) // if got end close pipe
               {
                   printf(“end 1n”);
                   if(flag2 == 1) // if child 2 process over
                       break; // break the loop
                   flag1 =1;
                   close(fd1[0]); // close fd1 reading end
               }
               else if(strstr(data2, “end”))
               {
                   printf(“end 2n”);
                   if(flag1 == 1) // if child 1 process over
                       break; // break the while loop
                   flag2 = 1;
                   close(fd2[0]); // close fd2 reading end
               }
               if(strstr(data1,”child”) && strstr(data2,”child”))
               {
                   if(flag1 != 1)
                       printf(“%sn”,data1);
                   if(flag2 != 1)
                       printf(“%sn”,data2);
               }

              

           }
           waitpid(-1, &status, 0); // wait for child to complite
           waitpid(-1, &status, 0); // wait for child to complite
          
       }
   }
}

Please read the question carefully and in full and then answer it (using C language and any necessary libraries). (I am not sure what the expert's mean by when to move to using pipe. I guess if you need to, then you can use a random time or any exact time but make sure to put a comment next to it). An expert did attempt it previously but seems that he didn't read the question fully. It requires usage of pipes and other techniques. You might use the code provided below. Use fork() to create a child process that generates the data for events, a source (PID), and an elapsedtime, and writes these into a pipe. The parent process will read the pipe, assemble the data into the correct format and insert it into a circular queue. There should be no dispatch during this accumulation process. The child-process and parent process need to agree on a stopping condition. A suitable way to do this is to make each process stop after a given period has elapsed, say 1 minute. Note that both the parentprocess and the child-process are handling variables containing elapsed times. It should be easy to test for a condition where the elapsed-time has exceeded a limit. The parent needs to perform a waitpid() for the child. All the events in the queue need to be dispatched at the end, to show that the events have been captured and placed in the queue.

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now