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
Physical properties of minerals
lord [1]

Most minerals can be characterized and classified by their unique physical properties: hardness, luster, color, streak, specific gravity, cleavage, fracture, and tenacity.

<em>-</em><em> </em><em>BRAINLIEST</em><em> answerer</em><em> ❤️</em><em>✌</em>

6 0
3 years ago
Read 2 more answers
What does this work for
Anastaziya [24]

Answer:

it allows your dash board to light up you MPH RPM and all the other numbers on the spadomter

Explanat

8 0
3 years ago
The tolerance for a geometric can be easily identified by reading the _________.
baherus [9]

Answer:

C

Explanation:

4 0
3 years ago
Read 2 more answers
An escalator handles a steady load of 26 people per minute in elevating them from the first to the second floor through a vertic
photoshop1234 [79]

Answer:

\eta = 70.711\,\%

Explanation:

The power needed to make the escalator working is obtained by means of the Work-Energy Theorem:

\dot W  = \dot U_{g}

\dot W = \dot n \cdot m_{p}\cdot g \cdot \Delta y

\dot W = \left(26\,\frac{persons}{min}\right)\cdot (124\,lbm)\cdot \left(32.174\,\frac{ft}{s^{2}}\right)\cdot \left(\frac{1\,lbf}{32.174\,\frac{lbm\cdot ft}{s^{2}} } \right)\cdot (27.5\,ft)

\dot W = 88660\,\frac{lbf\cdot ft}{min}\,\left(2.687\,hp\right)

The mechanical efficiency of the escalator is:

\eta = \frac{2.687\,hp}{3.8\,hp}\times 100\,\%

\eta = 70.711\,\%

3 0
3 years ago
I'll mark brainliest plz help
Citrus2011 [14]

Answer:

Explanation:

There are three points in time we need to consider.  At point 0, the mango begins to fall from the tree.  At point 1, the mango reaches the top of the window.  At point 2, the mango reaches the bottom of the window.

We are given the following information:

y₁ = 3 m

y₂ = 3 m − 2.4 m = 0.6 m

t₂ − t₁ = 0.4 s

a = -9.8 m/s²

t₀ = 0 s

v₀ = 0 m/s

We need to find y₀.

Use a constant acceleration equation:

y = y₀ + v₀ t + ½ at²

Evaluated at point 1:

3 = y₀ + (0) t₁ + ½ (-9.8) t₁²

3 = y₀ − 4.9 t₁²

Evaluated at point 2:

0.6 = y₀ + (0) t₂ + ½ (-9.8) t₂²

0.6 = y₀ − 4.9 t₂²

Solve for y₀ in the first equation and substitute into the second:

y₀ = 3 + 4.9 t₁²

0.6 = (3 + 4.9 t₁²) − 4.9 t₂²

0 = 2.4 + 4.9 (t₁² − t₂²)

We know t₂ = t₁ + 0.4:

0 = 2.4 + 4.9 (t₁² − (t₁ + 0.4)²)

0 = 2.4 + 4.9 (t₁² − (t₁² + 0.8 t₁ + 0.16))

0 = 2.4 + 4.9 (t₁² − t₁² − 0.8 t₁ − 0.16)

0 = 2.4 + 4.9 (-0.8 t₁ − 0.16)

0 = 2.4 − 3.92 t₁ − 0.784

0 = 1.616 − 3.92 t₁

t₁ = 0.412

Now we can plug this into the original equation and find y₀:

3 = y₀ − 4.9 t₁²

3 = y₀ − 4.9 (0.412)²

3 = y₀ − 0.83

y₀ = 3.83

Rounded to two significant figures, the height of the tree is 3.8 meters.

7 0
3 years ago
Other questions:
  • Rolling and Shearing are the types of a)-Bulk Deformation Process b)- Sheet Metal Process c)- Machining Process d)- Both a &amp;
    7·1 answer
  • in a vehicle you're servicing the fuel pressure drops rapidly when the engine is says that one or more turned off. Technician a
    7·1 answer
  • The yield of a chemical process is being studied.The two most important variables are thought to be the pressure and the tempera
    9·1 answer
  • Please answer the following questions.
    9·2 answers
  • A rectangular block having dimensions 20 cm X 30 cm X 40 cm is subjected to a hydrostatic stress of -50 kPa (i.e. under compress
    15·1 answer
  • An object is supported by a crane through a steel cable of 0.02m diameter. If the natural swinging of the equivalent pendulum is
    6·1 answer
  • A cylinder fitted with a movable piston contains water at 3 MPa with 50% quality, at which point the volume is 20 L. The water n
    8·2 answers
  • A plane wall, 7.5 cm thick, generates heat internally at the rate of 105W/m3. One side of the wall is insulated and the other si
    14·1 answer
  • Which level of acceleration should you use when accelerating on a short highway entry ramp?
    11·1 answer
  • 3. (5%) you would like to physically separate different materials in a scrap recycling plant. describe at least one method that
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!