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
Find the current Lx in the figure
AleksandrR [38]

Explanation:

\frac{1}{8}  +  \frac{1}{2}   \\ 1.6 + 1.4 = 3 \\  \frac{1}{3}  +  \frac{1}{9}   \\ 2.25 + 2 = 4.25 \: ohm

R total = 4.25 ohm

I total = Vt/Rt

I total= 17/4.25= 4 A

Ix= 600 mA

\frac{9}{9 + 3}  \times 4 = 3\\   \frac{2}{2 + 8} \times 3 = 0.6a \\  = 0.6 \: milli \: amper

6 0
3 years ago
Which rigid motion maps the solid-line figure onto the dotted-line figure?
Agata [3.3K]
I would love to answer but unfortunately there is no picture.
5 0
3 years ago
3.94 x 105) + (2.04 x 105)
Flura [38]
627.9 is the answer
6 0
3 years ago
Convert 850 nm wavelength into frequency, eV, wavenumber, joules and ergs.
Sholpan [36]

Answer:

Frequency = 3.5294\times 10^{14}s^{-1}

Wavenumber = 1.1765\times 10^6m^{-1}

Energy = 2.3365\times 10^{-19}J

Energy = 1.4579 eV

Energy = 2.3365\times 10^{-12}erg

Explanation:

As we are given the wavelength = 850 nm

conversion used : (1nm=10^{-9}m)

So, wavelength is  850\times 10^{-9}m

The relation between frequency and wavelength is shown below as:

Frequency=\frac{c}{Wavelength}

Where, c is the speed of light having value = 3\times 10^8m/s

So, Frequency is:

Frequency=\frac{3\times 10^8m/s}{850\times 10^{-9}m}

Frequency=3.5294\times 10^{14}s^{-1}

Wavenumber is the reciprocal of wavelength.  

So,  

Wavenumber=\frac{1}{Wavelength}=\frac{1}{850\times 10^{-9}m}

Wavenumber=1.1765\times 10^6m^{-1}

Also,  

Energy=h\times frequency

where, h is Plank's constant having value as 6.62\times 10^{-34}J.s

So,  

Energy=(6.62\times 10^{-34}J.s)\times (3.5294\times 10^{14}s^{-1})

Energy=2.3365\times 10^{-19}J

Also,  

1J=6.24\times 10^{18}eV

So,  

Energy=(2.3365\times 10^{-19})\times (6.24\times 10^{18}eV)

Energy=1.4579eV

Also,  

1J=10^7erg

So,  

Energy=(2.3365\times 10^{-19})\times 10^7erg

Energy=2.3365\times 10^{-12}erg

5 0
3 years ago
Design a fundamental mode asynchronous finite state machine that accepts input pair, A and B. The AB input sequence 00, 01,11, 1
dybincka [34]

Answer:

See explaination

Explanation:

A Finite state machines can be synchronous or asynchronous. The operation of asynchronous state machines does not require a clock signal. An Asynchronous state machine is classified basically on their operating mode, such as the fundamental mode, pulse mode or burst mode. An asynchronous state machine can have stable and transient states.

Please kindly refer to attachment for a step by step solution.

5 0
3 years ago
Other questions:
  • The flatbed truck carries a large section of circular pipe secured only by the two fixed blocks A and B of height h. The truck i
    14·2 answers
  • A socket can be driven using any of the following except for (A) a socket ratchet
    14·1 answer
  • What is the magnitude of the maximum stress that exists at the tip of an internal crack having a radius of curvature of 3 × 10-4
    15·1 answer
  • Create a separate function file fieldtovar.m that receives a single structure as an input and assigns each of the field values t
    15·1 answer
  • Storm sewer backup causes your basement to flood at the steady rate of 1 in. of depth per hour. The basement floor area is 2600
    9·1 answer
  • An engine has a piston with a surface area of 17.31 in2 and can travel 3.44 inches. What is the potential change in volume, disp
    10·1 answer
  • The hypotenuse of a 45° right triangle is
    5·1 answer
  • For some metal alloy, a true stress of 345 MPa (50040 psi) produces a plastic true strain of 0.02. How much will a specimen of t
    13·1 answer
  • 17. Swing arm restraints are intended to prevent a vehicle from falling off a lift.
    6·1 answer
  • How much does it cost to replace a roof on a 2,200 square foot house.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!