Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 1 . Part I: Implement the cigarette - smoker problem using shared memory and semaphores. The IPC mechanism is shared memory, like Assignment 1

11. Part I:
Implement the cigarette-smoker problem using shared memory and semaphores. The IPC
mechanism is shared memory, like Assignment 1. There is a shared buffer (array) between the
agent and each smoker. The shared buffer is a circular buffer.
Each shared buffer between the agent and a smoker is synchronized by a semaphore. In other
words, there are three buffers. The size of those buffers may be different. The agent puts two
ingredients in all three shared buffers each time. Each smoker takes those two ingredients and
processes accordingly. The smoker who smokes does NOT reply with a completion message,
because they are synchronized with semaphores.
For the agent process:
The agent spawns a child process using fork (). It also receives a request message from each
of the three smoker processes. The message includes the type (tobacco, paper, or matches) and
process ID of the smoker process. The process ID will then be put in the messages sent to the
smoker processes. When a request from all three smoker processes has arrived, the agent starts
produce ingredients.
The agent will need to generate two random numbers, each representing an ingredient. Those
two ingredients will be encoded in a message and sent to the three smoker processes. The
procedure will repeat when the agent receives a completion message from one of the smoker
processes.
Ingredients:
. Paper = represented by the first 3 digits of your Student Number
. Tobacco = represented by the middle 3 digits of your Student Number
. Matches = represented by the last 3 digits of your Student Number
For the smoker processes:
A smoker process first sends a message, including its process ID, to the agent. When it
receives a message from the agent, it checks what these two materials are. If they are not what
are required to make a cigarette, it simply discards them. If they are the two ingredients, it starts
smoking (print a message indicating it is smoking) for a second and then sends a completion
message to the agent.
When the program should stop? The program stops when it has run Y cycles. Before the agent
process stops, it sends two special values (e.g.,-1,-1; or none, none) to the smoker processes.
Upon receiving the special values, the smoker processes terminate. Y is an argument of the
command to start the process.
12. Part II.
Students with odd student id:
Implement the cigarette-smoker problem using message queues. Upon receiving a valid request
from a client, the server needs send a message back to the client. The client's process ID usually
is used as part of the client request message to uniquely identify the client. For a client, it sends
messages to the server via the interface and it uses another message queue read the message from
the server.
Students with even student id:
Spawn a separate thread which serves as a timer from the main program. The thread wakes up
every X seconds periodically (X is from the command line) and it reports the numbers of each
ingredient that have been sent to the smokers during the last X seconds. The numbers are shared
between the main program and the thread, so they need to be protected. To synchronize threads,
you can use mutex(es) instead of semaphore(s).

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_2

Step: 3

blur-text-image_3

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

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions