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
Consider a space shuttle weighing 100 kN. It is travelling at 310 m/s for 30 minutes. At the same time, it descends 2200 m. Cons
mixas84 [53]

Answer:

work done = 48.88 × 10^{9} J

Explanation:

given data

mass = 100 kN

velocity =  310 m/s

time = 30 min = 1800 s

drag force = 12 kN

descends = 2200 m

to find out

work done by the shuttle engine

solution

we know that work done here is

work done = accelerating work - drag work - descending work

put here all value

work done = ( mass ×velocity ×time  - force ×velocity ×time  - mass ×descends )  10³ J

work done = ( 100 × 310 × 1800  - 12×310 ×1800  - 100 × 2200 )  10³ J

work done = 48.88 × 10^{9} J

6 0
3 years ago
The maximum stress that a bar will withstand before failing is called • Rapture Strength • Yield Strength • Tensile Strength • B
konstantin123 [22]

Answer: Rupture strength

Explanation: Rupture strength is the strength of a material that is bearable till the point before the breakage by the tensile strength applied on it. This term is mentioned when there is a sort of deformation in the material due to tension.So, rupture will occur before whenever there are chances of failing and the material is still able to bear stresses before failing.  

7 0
3 years ago
A sign erected on uneven ground is guyed by cables EF and EG. If the force exerted by cable EF at E is 46 lb, determine the mome
Vikki [24]

Answer:

M_AD = 1359.17 lb-in

Explanation:

Given:

- T_ef = 46 lb

Find:

- Moment of that force T_ef about the line joining points A and D.

Solution:

- Find the position of point E:

                           mag(BC) = sqrt ( 48^2 + 36^2) = 60 in

                           BE / BC = 45 / 60 = 0.75

Hence,                E = < 0.75*48 , 96 , 36*0.75> = < 36 , 96 , 27 > in

- Find unit vector EF:

                           mag(EF) = sqrt ( (21-36)^2 + (96+14)^2 + (57-27)^2 ) = 115 in

                           vec(EF) = < -15 , -110 , 30 >

                           unit(EF) = (1/115) * < -15 , -110 , 30 >

- Tension            T_EF = (46/115) * < -15 , -110 , 30 > = < -6 , -44 , 12 > lb

- Find unit vector AD:

                           mag(AD) = sqrt ( (48)^2 + (-12)^2 + (36)^2 ) = 12*sqrt(26) in

                           vec(AD) = < 48 , -12 , 36 >

                           unit(AD) = (1/12*sqrt(26)) * < 48 , -12 , 36 >

                           unit (AD) = <0.7845 , -0.19612 , 0.58835 >

Next:

                           M_AD = unit(AD) . ( E x T_EF)

                           M_d = \left[\begin{array}{ccc}0.7845&-0.19612&0.58835\\36&96&27\\-6&-44&12\end{array}\right]

                            M_AD = 1835.73 + 116.49528 - 593.0568

                            M_AD = 1359.17 lb-in

3 0
3 years ago
Witch truck company is better.<br><br> Ram <br> Ford <br> Toyoda<br> GMC
arlik [135]
Ram is the better truck company
7 0
3 years ago
Read 2 more answers
In the case, the software engineers present at the meeting would concern themselves with ________-level strategy
jekas [21]

The level of strategy which the software engineers would concern themselves with would be highly dependent on the nature of the case or situation.

<h3>What is a strategy?</h3>

A strategy can be defined as a set of guiding principles, procedures, actions, and decisions that a business organization or an individual combines, in order to achieve its aim, objectives and goals.

Basically, developing a strategy is essential because it helps to attract new customers and gives a competitive advantage over rivals in the industry.

<h3>The types of strategy.</h3>

In Software engineering, there are different types of strategy used by software engineers and these include:

  • Tactical strategy
  • Product management strategy
  • Lifecycle process strategy
  • Technology strategy
  • Support strategy
  • Customer strategy

Furthermore, there are three (3) main <u>levels</u> of strategy in software engineering and these are:

  1. Business-level strategy
  2. Functional-level strategy
  3. Corporate-level strategy

In this scenario, the level of strategy which the software engineers present at the meeting would concern themselves with would be highly dependent on the nature of the case or situation.

Read more on strategy here: brainly.com/question/26064163

6 0
2 years ago
Other questions:
  • In the 5 Code of Federal Regulations (C.F.R.), it is recommended that an individual has security awareness training before s/he
    8·2 answers
  • A smoking lounge is to accommodate 19 heavy smokers. The minimum fresh air requirement for smoking lounges is specified to be 30
    11·1 answer
  • What type of fuel does a 2 cycle engine use
    5·1 answer
  • Acquisition of resources from an external source is called?
    15·1 answer
  • In a creep test, increasing the temperature will (choose the best answer) A. increase the instantaneous initial deformation B. i
    5·1 answer
  • What did the discovery of the Cumberland Gap mean for exploration? PLEASE HELP ILL GIVE YOU BRAINLEIST!
    15·1 answer
  • Determine (with justification) whether the following systems are (i) memoryless, (ii) causal, (iii) invertible, (iv) stable, and
    10·1 answer
  • Exercises
    12·1 answer
  • What are the available motor sizes for 2023 ariya ac synchronous drive motor systems in kw?.
    12·1 answer
  • A book sitting on a shelf is an example of ____________.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!