Please read the question carefully and in full and then answer it (using C language and any necessar

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.

include
#include
#include /* needed for getpid() */
#include /* needed for getpid(), and usleep() */
#include
#include
#include
#include
#include

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

#define n_vals 128 /* number of values to be evaluated */

struct timespec start, end;

int main (void)
{

pid_t pid;
int status;

int i;

int64_t PID;
int64_t timeElapsed;

time_t t;

/* start the clock*/
clock_gettime(CLOCK_MONOTONIC, &start);
srand((unsigned) time(&t));

if ((pid = fork ())
perror (“fork error”);
else if (pid == 0)
{

/* can do child stuff here */
/* Print n_vals numbers */
for (i = 0; i
{
usleep (100000);

/* Find out when the event happened */
/* evaluate the elapsed time, in nanoseconds, integer type*/
clock_gettime(CLOCK_MONOTONIC, &end);
timeElapsed = (int64_t) timespecDiff(&end, &start);

/* Find out where the event came from */
PID = (int64_t) getpid();
printf (“ttttttttimeElapsed = %ld, PID = %ldn”, timeElapsed, PID);
}
}
else
{
/* pid != 0, so we know that this process is the parent */

/* can do parent stuff here */
for (i = 0; i
{
usleep (100000);

/* Find out when the event happened */
/* evaluate the elapsed time, in nanoseconds, integer type*/
clock_gettime(CLOCK_MONOTONIC, &end);
timeElapsed = (int64_t) timespecDiff(&end, &start);

/* Find out where the event came from */
PID = (int64_t) getpid();
printf (“timeElapsed = %ld, PID = %ldn”, timeElapsed, PID);
}

if ((pid = waitpid (pid, &status, 0))
perror (“waitpid error”);

}
/* end of while() */
exit (0);
}

/* end of main() */

/* A user function to extract the number of nanoseconds that have elapsed*/
int64_t timespecDiff (struct timespec *timeA_p, struct timespec *timeB_p)
{
return ((timeA_p->tv_sec * 1000000000) + timeA_p->tv_nsec) –
((timeB_p->tv_sec * 1000000000) + timeB_p->tv_nsec);
} Use fork) to create a child process that generates the data for events, a source 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 accumulation process (PID), and an dispatch during this The child-process and parent process need to agree on a 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 stopping condition. A suitable way to do this 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

 

Looking for a Similar Assignment? Let us take care of your classwork while you enjoy your free time! All papers are written from scratch and are 100% Original. Try us today! Use Code FREE15