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
a vertical cylindrical container is being cooled in ambient air at 25 °C with no air circulation. if the initial temperature of
Sloan [31]

Answer:

the surface heat-transfer coefficient due to natural convection during the initial cooling period.  = 4.93 w/m²k

Explanation:

check attachement for answer explanation

7 0
3 years ago
Read 2 more answers
An uncharged capacitor and a resistor are connected in series to a source of voltage. If the voltage = 7.41 Volts, C = 11.5 µFar
Musya8 [376]

Answer:

a) RC = 1.03 mseg.

b) Qmax = CV = 85.2 μC

c) Q = 53.9 μC

Explanation:

a) In a RC circuit, during the transient period, the capacitor charges exponentially (starting from 0 due to the voltage in the capacitor can´t change instantaneously) with time, being the exponent -t/RC.

This product RC, which defines the rate at which the capacitor charges, is called the time constant of the circuit.

In this case , it can be calculated as follows:

ζ = R C = 89.4 Ω . 11.5 μF = 1.03 mseg.

b) As the charge begins to build up the capacitor plates, a voltage establishes between plates, that opposes to the battery voltage. When this voltage is equal to the battery one, the capacitor reaches to the maximum charge, which is, by definition, as follows:

Q = C V = 11.5 μF . 7.41 V = 85.2 μC

c) During the charging process, the charge increases following this equation:

Q = CV (1 - e⁻t/RC)

When t = RC, the expression for Q is as follows:

Q = CV ( 1- e⁻¹) = 0.63 x CV = 53.9 μC

6 0
3 years ago
Explain why advances in technology can actually create more problems for engineers.
andrew11 [14]

Explanation:

Engineering is science in practical terms. It is the application of scientific findings in problem solving and creating a better world.

How does technological advancements create more problems for engineers?

  • Loss of job to automation: the world is driving at automating work processes through the use of  specially designed and crafted machinery. Work is now properly being done using machines with little to no human input in the whole process. This is a huge let off for engineers. Engineers have to compete with machines which are their own inventions for jobs now.
  • Fast paced work environment: machines can handle work more efficiently and faster than the people making them. There is an increasing race between engineers and their own inventions today for better product delivery. Unless a machine is faulty, they are more productive and efficient than man. This can cause engineers to want to catch up with their own inventions leading to a work life of stress.
  • Environmental problems they cannot solve: most inventions use components from the environment. They release effluents that are very difficult to be properly disposed or stored. This is a huge problem for engineers and can lead to ethical calls from the government and the populace. In short, they can create problems they are expected to solve but cannot solve.
  • Social problems: engineers can be portrayed as terrible beings for their own inventions. This leads to psychological problems on a good and creative invention. For example, rare earth metals in DR Congo are instrumental in making solar panels, but mining of these metals have forced several thousands of people into hard and intense labor on mines; there is a call on technological firms to stop exploiting people this way for their own gains.
  • Misuse of technology: any good technology can be put into the wrong use. A nuclear reaction can be packaged into a bomb and also, it can be the center of electricity generation on a commercial scale. How can engineers solve this kind of problem? Technological inventions are subjective in their usage.

Learn more:

New technology brainly.com/question/5768621

#learnwithBrainly

3 0
3 years ago
As the junior engineer at the Mesabi Range Hydraulic Engineering Company located in Ely, Minnesota, you have been tasked with de
katen-ka-za [31]

yes it will

Explanation:

5 0
4 years ago
How does the clearance volume affect the efficiency of the Otto cycle?
eduard

Answer:

Explanation:

A smaller clearance volume means a higher compression. A higher compression means better thermal efficiency. However a compression ratio too high might be troublesome, as it can cause accidental ignition of the fuel-air mix. This is the reason why Otto cycle engines have lower compressions that Diesel engines. In a Diesel engine the mix ignites by compression instead of a spark.

7 0
3 years ago
Other questions:
  • 4. A 25 km2 watershed has a time of concentration of 1.6 hr. Calculate the NRCS triangular UH for a 10-minute rainfall event and
    8·1 answer
  • A rubber wheel on a steel rim spins freely on a horizontal axle that is suspended by a fixed pivot at point P. When the wheel sp
    11·1 answer
  • What’s a pigtail when wiring
    7·1 answer
  • The work done by the system decreases the energy of the system. a)- True b)- False
    6·1 answer
  • A piece of corroded metal alloy plate was found in a submerged ocean vessel. It was estimated that the original area of the plat
    8·1 answer
  • Convert 850 nm wavelength into frequency, eV, wavenumber, joules and ergs.
    11·1 answer
  • Coderz robotics 101: challenge mission 3 part 3
    8·1 answer
  • A 1-w, 350-ω resistor is connected to 24 v. Is this resistor operating within its power rating?
    13·1 answer
  • Scrooge McNugget wants to store information (names, addresses, descriptions of embarrassing moments, etc.) about the many ducks
    6·1 answer
  • what i the maximum flow rate of glycerine at 20C in a 10cm diameter pipe that can be assumed to remain laminar
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!