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
What are the philological elements of interior design most like?
sp2606 [1]

Answer:

Ea public address glven via the intercom system of a large buildingxplanation:

7 0
2 years ago
214Bi83 --&gt; 214Po84 + eBismuth-214 undergoes first-order radioactive decay to polonium-214 by the release of a beta particle,
Zolol [24]

Answer:

(C) ln [Bi]

Explanation:

Radioactive materials will usually decay based on their specific half lives. In radioactivity, the plot of the natural logarithm of the original radioactive material against time will give a straight-line curve. This is mostly used to estimate the decay constant that is equivalent to the negative of the slope. Thus, the answer is option C.

3 0
2 years ago
Read 2 more answers
Consider a multiprocessor system and a multithreaded program written using the many-to-many threading model. Let the number of u
Montano1993 [528]

Answer:

At the point when the quantity of bit strings is not exactly the quantity of processors, at that point a portion of the processors would stay inert since the scheduler maps just part strings to processors and not client level strings to processors. At the point when the quantity of part strings is actually equivalent to the quantity of processors, at that point it is conceivable that the entirety of the processors may be used all the while. Be that as it may, when a part string obstructs inside the portion (because of a page flaw or while summoning framework calls), the comparing processor would stay inert. When there are more portion strings than processors, a blocked piece string could be swapped out for another bit string that is prepared to execute, in this way expanding the use of the multiprocessor system.When the quantity of part strings is not exactly the quantity of processors, at that point a portion of the processors would stay inert since the scheduler maps just bit strings to processors and not client level strings to processors. At the point when the quantity of bit strings is actually equivalent to the quantity of processors, at that point it is conceivable that the entirety of the processors may be used at the same time. Be that as it may, when a part string hinders inside the piece (because of a page flaw or while summoning framework calls), the relating processor would stay inert. When there are more portion strings than processors, a blocked piece string could be swapped out for another bit string that is prepared to execute, along these lines expanding the usage of the multiprocessor framework.

4 0
2 years ago
A well-insulated rigid vessel contains 3 kg of saturated liquid water at 40oC. The vessel also contains an electrical resistor t
user100 [1]

Answer:

The final temperature is 111.66°C

Explanation:

The given conditions :-

i) Well insulated means no heat loss.

ii) Rigid vessels means volume remains same.

iii) Initial temperature ( T₁ ) = 40°C. = 273 + 40 = 313 K

iv ) Mass of water in vessel = 3 kg.

v) current drawn by resistor ( i ) = 10 ampere.

vi) Voltage applied ( V ) = 50 volts.

vii) The time for which resistor operating ( t ) = 30 minute = 30 * 60 = 1800 seconds.

Now we have to calculate heat developed by resistor in vessel.

Q = V * i * t  = 50 * 10 * 1800 = 900,000 J = 900 KJ.

Since it is a rigid container so the work done is zero.

Q = du    ( du - change in internal energy)

Q = m * C * dT      ( C = 4.186 KJ/KgK )

Q = 3 * 4.186 * (T₂ - T₁ )

900 = 12.558 * ( T₂ - 313 )

T₂ - 313 = 71.6674

T₂ = 384.6674 K

T = 384.6674 - 273 = 111.66°C

So the final temperature is 111.66°C.

3 0
3 years ago
5. Consider the LTI system defined by the differential equation (a) Draw the pole-zero plot for the system. Is the system stable
stealth61 [152]

Answer:

Detailed solution is attached in the images below showing step wise solution and answer for each part individually.

8 0
3 years ago
Other questions:
  • Select the properties and typical applications for the high carbon steels.
    12·1 answer
  • True or false? Don't break or crush mercury-containing lamps because mercury powder may be released.
    8·1 answer
  • If you know that the change in entropy of a system where heat was added is 12 J/K, and that the temperature of the system is 250
    10·1 answer
  • Consider air entering a heated duct at P1 = 1 atm and T1 = 288 K. Ignore the effect of friction. Calculate the amount of heat pe
    10·2 answers
  • What is the ILS stand for
    8·2 answers
  • What are the units or dimensions of the shear rate dv/dy (English units)? Then, what are the dimensions of the shear stress τ= μ
    14·1 answer
  • An airplane flies horizontally at 80 m/s. Its propeller delivers 1300 N of thrust (forward force) to overcome aerodynamic drag (
    15·1 answer
  • Hey any one ride dirtbikes here
    5·2 answers
  • 10.16.1: LAB: Interstate highway numbers (Python)
    9·1 answer
  • When framing a building, a simple way to estimate the total amount of wall studs needed is to allow
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!