Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

How many processes are running? Which is which (refer to the if/else block)?

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.

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

Find in degrees for 0 Answered: 1 week ago

Answered: 1 week ago

Question

What are the assumptions of the test based on the ????-ratio?

Answered: 1 week ago