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]
4 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]4 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
Risks are Not Perceived Differently from What is Happening<br> False<br> True
Gnoma [55]

Answer:

False......................

8 0
3 years ago
A 60-kg woman holds a 9-kg package as she stands within an elevator which briefly accelerates upward at a rate of g/4. Determine
Anuta_ua [19.1K]

Answer:

force R = 846.11 N

lifting force L = 110.36 N

if cable fail complete both R and L will be zero

Explanation:

given data

mass woman mw = 60 kg

mass package mp = 9 kg

accelerates rate a = g/4

to find out

force R and lifting force L and if cable fail than what values would R and L acquire

solution

we calculate here first reaction R force

we know elevator which accelerates upward

so now by direction of motion , balance the force that is express as

R - ( mw + mp ) × g = ( mw + mp ) × a

here put all these value and a = g/4 and use g = 9.81 m/s²

R - ( 60 + 9 ) × 9.81 = ( 60 + 9  ) × g/4

R = ( 69  ) × 9.81/4  + ( 69 ) 9.81

R = 69  ( 9.81 + 2.4525 )

force R = 846.11 N

and

lifting force is express as here

lifting force = mp ( g + a)

put here value

lifting force = 9 ( 9.81 + 9.81/4)

lifting force L = 110.36 N

and

we know if cable completely fail than body move free fall and experience no force

so both R and L will be zero

5 0
3 years ago
A group of students launches a model rocket in the vertical direction. Based on tracking data, they determine that the altitude
Fofino [41]

Answer:

u = 260.22m/s

S_{max} = 1141.07ft

Explanation:

Given

S_0 = 89.6ft --- Initial altitude

S_{16.5} = 0ft -- Altitude after 16.5 seconds

a = -g = -32.2ft/s^2 --- Acceleration (It is negative because it is an upward movement i.e. against gravity)

Solving (a): Final Speed of the rocket

To do this, we make use of:

S = ut + \frac{1}{2}at^2

The final altitude after 16.5 seconds is represented as:

S_{16.5} = S_0 + ut + \frac{1}{2}at^2

Substitute the following values:

S_0 = 89.6ft       S_{16.5} = 0ft     a = -g = -32.2ft/s^2    and t = 16.5

So, we have:

0 = 89.6 + u * 16.5 - \frac{1}{2} * 32.2 * 16.5^2

0 = 89.6 + u * 16.5 - \frac{1}{2} * 8766.45

0 = 89.6 + 16.5u-  4383.225

Collect Like Terms

16.5u = -89.6 +4383.225

16.5u = 4293.625

Make u the subject

u = \frac{4293.625}{16.5}

u = 260.21969697

u = 260.22m/s

Solving (b): The maximum height attained

First, we calculate the time taken to attain the maximum height.

Using:

v=u  + at

At the maximum height:

v =0 --- The final velocity

u = 260.22m/s

a = -g = -32.2ft/s^2

So, we have:

0 = 260.22 - 32.2t

Collect Like Terms

32.2t = 260.22

Make t the subject

t = \frac{260.22}{ 32.2}

t = 8.08s

The maximum height is then calculated as:

S_{max} = S_0 + ut + \frac{1}{2}at^2

This gives:

S_{max} = 89.6 + 260.22 * 8.08 - \frac{1}{2} * 32.2 * 8.08^2

S_{max} = 89.6 + 260.22 * 8.08 - \frac{1}{2} * 2102.22

S_{max} = 89.6 + 260.22 * 8.08 - 1051.11

S_{max} = 1141.0676

S_{max} = 1141.07ft

Hence, the maximum height is 1141.07ft

8 0
3 years ago
tech a says that small vacuum leaks can be found with a vacuum gauge. tech b says that the catalytic converter is typically loca
schepotkina [342]

Both are true. Tech A claims that a vacuum gauge can be used to locate tiny vacuum leaks. According to tech B, the catalytic converter is usually placed behind the muffler.

<h3>Which of the following links the catalytic converter to the exhaust manifold?</h3>

Tailpipe. The catalytic converter has cleaned up the exhaust gases, which are then sent out of the car and into the atmosphere via the tailpipe, the last link in the exhaust system.

<h3>Which of the following exhaust system parts aids in lowering exhaust emissions?</h3>

Hazardous pollutants from engine exhaust are decreased by the catalytic converter. The converter, which is situated between the exhaust manifold and the muffler, works with heat and metals that serve as catalysts.

To know more about vacuum gauge visit:-

brainly.com/question/20989381

#SPJ4

8 0
1 year ago
A tool used to put a concave edge on a plane iron is
Over [174]

Answer:

C) grinder

Explanation:

7 0
3 years ago
Other questions:
  • A plane surface 25 cm wide has its temperature maintained at 80°C. Atmospheric air at 25°C ows parallel to the surface
    12·1 answer
  • Which of the following is a advantage of a chain and sprocket over a pulley and belt system?
    7·1 answer
  • Write a matrix, that is a lower triangular matrix.
    15·1 answer
  • An ordinary egg can be approximated as a 5.5-cm-diameter sphere. The egg is initially at a uniform temperature of 8°C and is dro
    6·1 answer
  • In which order are the following measuring instruments listed from lowest precision to highest precision:
    12·1 answer
  • A steam turbine has an inlet of 3 kg/s water at 1200 kPa, 350 °C and velocity 15 m/s. The exit is at 100 kPa, 150 °C and very lo
    13·1 answer
  • The beam below will be subjected to a live load of 600 lb/ft, a concentrated live load of 25 kip, and a dead load of 300 lb/ft.
    15·1 answer
  • Describe three examples of how metrology can improve the safety of automobiles.
    12·1 answer
  • A major tennis manufacturer is undertaking a test program for shoes, tennis balls, and tennis strings. Develop a test plan for t
    11·1 answer
  • Heater control valves can not leak coolant<br><br> True <br> False
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!