Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3.5 Pipes A Unix pipe is a one-way communication channel. A pipe is used to pass a character stream from one process to another. On

image text in transcribed

3.5 Pipes A Unix pipe is a one-way communication channel. A pipe is used to pass a character stream from one process to another. On the command line, you've already seen a pipe: /ps -el less will take output from ps and pipe it to less so you can view it Pipes are declared using the pipe function. The pipe function takes an array of two integers and returns two file descriptors: the read end be pto], and p1 be the write end. A file descriptor is a tag that describes a resource to the operating system. You pass the file descriptor to the operating system on read and write calls so the operating system knows which resource you're reading from or writing to. There are limits to how many file descriptors can be open in any process, and because they are system resources, there is also a system limit on the total i.e., how many pipes can be there one time) Observe the output of this program and explain. #include #define MSGSIZE 16 int main(O char msg "How are you?" char inbuff [MSGSIZE] int p[2]; int ret; Pipe (p); ret fork if (ret 0) write(p[1], msg, MSGSIZE); else sleep(1); read (po], inbuff, MSGSIZE) printf ("%s ", inbuff); exit (0); Include answers to the following questions in your report 2 pts How many processes are running? Which is which (refer to the if/else block)? 6 pts Trace the steps the message takes before printing to the screen, from the array msg to the array inbuff, and identify which process is doing each step. 2 pts Why is there a sleep statement? Think about what happens if one process runs first. Think back to lab 2 what would be a better statement to use instead of sleep for this sall example? You might have to reverse the role of parent and child

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

What is cost plus pricing ?

Answered: 1 week ago

Question

1. What are the types of wastes that reach water bodies ?

Answered: 1 week ago

Question

Which type of soil has more ability to absorb water?

Answered: 1 week ago