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
-Electronic control modules can easily evaluate the voltage and current levels of circuits to which they are connected and deter
erma4kov [3.2K]

Answer:

multiplexing

Explanation:

3 0
3 years ago
An eddy current separator is to separate aluminum product from an input streamshredded MSW. The feed rate to the separator is 2,
blsea [12.9K]

Answer:

<em>the % recovery of aluminum product is 80.5%</em>

<em>the % purity of the aluminum product is 54.7%</em>

<em></em>

Explanation:

feed rate to separator = 2500 kg/hr

in one hour, there will be 2500 kg/hr x 1 hr = 2500 kg of material is fed into the  machine

of this 2500 kg, the feed is known to contain 174 kg of aluminium and 2326 kg of rejects.

After the separation, 256 kg  is collected in the product stream.

of this 256 kg, 140 kg is aluminium.

% recovery of aluminium will be = mass of aluminium in material collected in the product stream ÷ mass of aluminium contained in the feed material

% recovery of aluminium = 140kg/174kg x 100% = <em>80.5%</em>

% purity of the aluminium product = mass of aluminium in final product ÷ total mass of product collected in product stream

% purity of the aluminium product = 140kg/256kg

x 100% = <em>54.7%</em>

8 0
3 years ago
The elevation of the end of the steel beam supported by a concrete floor is adjusted by means of the steel wedges E and F. The b
Wewaii [24]

Answer:

a) P ≥ 22.164 Kips

b) Q = 5.4 Kips

Explanation:

GIven

W = 18 Kips

μ₁ = 0.30

μ₂ = 0.60

a) P = ?

We get F₁  and F₂ as follows:

F₁ = μ₁*W = 0.30*18 Kips = 5.4 Kips

F₂ = μ₂*Nef = 0.6*Nef

Then, we apply

∑Fy = 0   (+↑)

Nef*Cos 12º -  F₂*Sin 12º = W

⇒   Nef*Cos 12º -  (0.6*Nef)*Sin 12º = 18

⇒   Nef = 21.09 Kips

Wedge moves if

P ≥ F₁ + F₂*Cos 12º + Nef*Sin 12º

⇒  P ≥ 5.4 Kips + 0.6*21.09 Kips*Cos 12º + 21.09 Kips*Sin 12º

⇒  P ≥ 22.164 Kips

b) For the static equilibrium of base plate

Q = F₁ = 5.4 Kips

We can see the pic shown in order to understand the question.

7 0
3 years ago
Read 2 more answers
a buyer can purchase 70 screwdrivers ten 4-inch length twelve 6 inch length twenty 8-inch length are needed. how many heavy 24-i
jasenka [17]

Answer:

28 , 24-inch screwdrivers

Explanation:

The total number of screwdrivers that can be purchased is = 70

4 - inch length screwdrivers = 10

6- inch length screwdrivers = 12

8- inch length screwdrivers = 20

Total = 20 +12 +10 = 42

Remaining = 70-42 = 28

So, heavy 24-inch screwdrivers = 28

3 0
3 years ago
A wire is 0.92 m long and 1.2 mm2 in cross-sectional area. It carries a current of 5.0 A when a 2.2 V potential difference is ap
Flura [38]

The solution is in the attachment

3 0
3 years ago
Other questions:
  • Where Does a Solar Engineer Work? <br> (2 sentences or more please)
    14·2 answers
  • A 2.599 g sample of a new organic material is combusted in a bomb calorimeter. The temperature of the calorimeter and its conten
    13·1 answer
  • A heat pump and a refrigerator are operating between the same two thermal reservoirs. Which one has a higher COP?
    10·1 answer
  • Turbine blades mounted to a rotating disc in a gas turbine engine are exposed to a gas stream that is at [infinity] = 1100°C and
    6·1 answer
  • Suppose we want to determine how many of the bits in a twelve-bit unsigned number are equal to zero. Implement the simplest circ
    14·1 answer
  • Simplify the following expressions, then implement them using digital logic gates. (a) f = A + AB + AC (b) f = AB + AC + BC (c)
    5·1 answer
  • Describing Tasks for Stationary Engineers Click this link to view O*NET’s Tasks section for Stationary Engineers. Note that comm
    12·2 answers
  • For laminar flow of air over a flat plate that has a uniform surface temperature, the curve that most closely describes the vari
    15·1 answer
  • List six clues that indicates that you are approaching an intersection
    10·1 answer
  • Discuss importance of good communication system​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!