1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Firlakuza [10]
3 years ago
5

CS3733: Homework/Practice 05 Suppose we would like to write a program called monitor which allows two other programs to communic

ate with each other through the monitor while inspecting the send messages. It can be executed as follows: > monitor progl prog2 To simplify the implementation, we assume that prog1 (e.g., 1s) will be printing some messages on the standard output while the prog2 (e.g, sort) reads from standard input and writes something into standard output. Our monitor can run these two programs as children and let the first one send messages to the second one through our monitor. So our monitor can inspect the incoming messages. After inspection, it sends the message to the next program as is. Again to simplify the implementation, we assume that our monitor simply looks for digits. When it detects a digit in the message, our monitor simply prints it on the stderr (this monitoring task can be complicated for other purposes) Logically these programs will have the following relationship prog1(child11Pie>[0Monitor (Paren)[1>Pipe2->[0Kprog2 (child2) You are asked to create the necessary pipes, child processes and connect them as explained in the above scenario. You can ignore most of the error checking to make your solution clear, but you need to close all unnecessary file descriptors and check what read-write return > monitor /bin/ls /usr/bin/sort #include #include #include #include int main (int argc, char argv int Pipel [2]; int Pipe2 [2] int chlpid, ch2pid, numread, numwrite; char buf if (chlpid.. 0){ /* child 1 7/ execl (argv[1], "progl", NULL) if (ch2pid0)/child 1 / execi (argv[2],"prog2", NULL)
Engineering
1 answer:
valina [46]3 years ago
8 0

Answer:

#include<stdio.h>

#include<stdlib.h>

#include<unistd.h>

#include<sys/types.h>

#include<string.h>

#include<pthread.h>

//#include<sys/wait.h>

int main(int argc, char** argv)

{

int fd1[2];

int fd2[2];

int fd3[2];

int fd4[2];

char message[] = "abcd";

char input_str[100];

pid_t p,q;

if (pipe(fd1)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd2)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd3)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

if (pipe(fd4)==-1)

{

 fprintf(stderr, "Pipe Failed" );

 return 1;

}

p = fork();

if (p < 0)

{

 fprintf(stderr, "fork Failed" );

return 1;

}

// child process-1

else if (p == 0)

{

 close(fd1[0]);// Close reading end of first pipe

 char concat_str[100];

 printf("\n\tEnter meaaage:"):

 scanf("%s",concat_str);

 write(fd1[1], concat_str, strlen(concat_str)+1);

 // Concatenate a fixed string with it

 int k = strlen(concat_str);

 int i;

 for (i=0; i<strlen(fixed_str); i++)

 {

  concat_str[k++] = fixed_str[i];

 }

 concat_str[k] = '\0';//string ends with '\0'

 // Close both writting ends

 close(fd1[1]);

 wait(NULL);

//.......................................................................

 close(fd2[1]);

 read(fd2[0], concat_str, 100);

 if(strcmp(concat_str,"invalid")==0)

 {

 printf("\n\tmessage not send");

 }

 else

 {

  printf("\n\tmessage send to prog_2(child_2).");

 }

 close(fd2[0]);//close reading end of pipe 2

 exit(0);

}

else

{

 close(fd1[1]);//Close writting end of first pipe

 char concat_str[100];

 read(fd1[0], concal_str, strlen(concat_str)+1);

 close(fd1[0]);

 close(fd2[0]);//Close writing end of second pipe

 if(/*check if msg is valid or not*/)

 {

  //if not then

  write(fd2[1], "invalid",sizeof(concat_str));

  return 0;

 }

 else

 {

  //if yes then

  write(fd2[1], "valid",sizeof(concat_str));

  close(fd2[1]);

  q=fork();//create chile process 2

  if(q>0)

  {

   close(fd3[0]);/*close read head offd3[] */

   write(fd3[1],concat_str,sizeof(concat_str);//write message by monitor(main process) using fd3[1]

   close(fd3[1]);

   wait(NULL);//wait till child_process_2 send ACK

   //...........................................................

   close(fd4[1]);

   read(fd4[0],concat_str,100);

   close(fd4[0]);

   if(sctcmp(concat_str,"ack")==0)

   {

    printf("Messageof child process_1 is received by child process_2");

   }

   else

   {

    printf("Messageof child process_1 is not received by child process_2");

   }

  }

  else

  {

   if(p<0)

   {

    printf("Chiile_Procrss_2 not cheated");

   }

   else

   {

     

    close(fd3[1]);//Close writing end of first pipe

    char concat_str[100];

    read(fd3[0], concal_str, strlen(concat_str)+1);

    close(fd3[0]);

    close(fd4[0]);//Close writing end of second pipe

    write(fd4[1], "ack",sizeof(concat_str));

     

   }

  }

 }

 close(fd2[1]);

}

}

You might be interested in
Manufacturing employees who perform assembly line work are referred to as
mamaluj [8]

Answer:

C. assembly line workers.

Explanation:

8 0
3 years ago
Read 2 more answers
For a body moving with simple harmonic motion state the equations to represent: i) Velocity ii) Acceleration iii) Periodic Time
max2010maxim [7]

Answer with Explanation:

The general equation of simple harmonic motion is

x(t)=Asin(\omega t+\phi)

where,

A is the amplitude of motion

\omega is the angular frequency of the motion

\phi is known as initial phase

part 1)

Now by definition of velocity we have

v=\frac{dx}{dt}\\\\\therefore v(t)=\frac{d}{dt}(Asin(\omega t+\phi )\\\\v(t)=A\omega cos(\omega t+\phi )

part 2)

Now by definition of acceleration we have

a=\frac{dv}{dt}\\\\\therefore a(t)=\frac{d}{dt}(A\omega cos(\omega t+\phi )\\\\a(t)=-A\omega ^{2}sin(\omega t+\phi )

part 3)

The angular frequency is related to Time period 'T' asT =\frac{2\pi }{\omega }

where

\omega is the angular frequency of the motion of the particle.

Part 4) The acceleration and velocities are plotted below

since the maximum value that the sin(x) and cos(x) can achieve in their respective domains equals 1 thus the maximum value of acceleration and velocity is A\omega ^{2} and A\omega respectively.

4 0
3 years ago
Can be used to eliminate rubbing friction of wheel touching frame. 1.Traction 2.Thrust washer
Vilka [71]

Answer:

thrust washer

can be used to eliminate rubbing friction of wheel touching frame

5 0
3 years ago
What is a microwave transmitter?a) A technology that uses active or passive tags in the form of chips or smart labels that can s
Blababa [14]

Answer:

b) Commonly used to transmit network signals over great distances.

Explanation:

The transmission of information or data by using microwave radio waves is known as microwave transmission. Microwave transmitter is commonly used to transmit network signals over great distances. It is an electronic device that transmits and receives radio frequency signals ranging from 1GHz to 100GHz.

The microwave transmitter has a wide range of applications and these includes, radio stations, television stations, mobile phones, radio astronomy, radar,

5 0
3 years ago
Read 2 more answers
Calculate the areas under the stress-strain curve (toughness) for the materials shown in Fig. below, (a) plot them as a
defon

Answer:

Explanation:

Wow

5 0
3 years ago
Other questions:
  • "From the earth to the moon". In Jules Verne’s 1865 story with this title, three men went to the moon in a shell fired from a gi
    5·1 answer
  • A 15 cm × 15 cm circuit board dissipating 20 W of power uniformly is cooled by air, which approached the circuit board at 20C w
    11·1 answer
  • What is a thermal reservoir?
    15·1 answer
  • A large plate is fabricated from a steel alloy that has a plane strain fracture toughness of 78 MPa (70.98 ksi). If the plate is
    7·1 answer
  • 5.5 A scraper with a 275 hp diesel engine will be used to excavate and haul earth for a highway project. An evaluation of the jo
    10·1 answer
  • Earth whose in situ weight is 105lb/cf and whose compacted weight is 122 lb/cf is placed in a fill at the rate of 260 cy/hr, mea
    14·1 answer
  • 1. In a series circuit the sum of all voltage drops produced by the loads in the circuit
    7·1 answer
  • Difference between theory and practice?​
    10·1 answer
  • lmfsojdkkfjdsskfsaj;fkljsldfkjlsdkfdjs;dklfjsldkfjflkjfkjfldjsdlfgkljshglksdjfghdskjgsdfkfjghlsdfghsdkjfghlskjdfhglskjdfghkjsfhg
    12·1 answer
  • How many meters per second is 100 meters and 10 seconds
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!