CS 110 Operating Systems
Priority Barber Shop Project
Version 0.9
Due Date - 1 December, 9PM
NO LATES
Introduction
This is a
modification of
the solution to
Basic Barber Shop Project
(semaphores, shared memory, and multilevel queues).
The Barber Shop operation has been reported to the
Inspector General. It seems in its current instantiation,
starvation is possible,
i.e., Grunts can wait all day for haircuts
because Officers and
NonComs have priority.
In an effort to keep the Grunts happy and the IG
off your tail, you have decided to modify your queue and
priority system.
Now
Grunts are guaranteed to have their priority
increased in the following way.
-
After waiting a maximum of 5 haircuts (where the current
haircut counts as a haircut), a Grunt is moved
into the NonCom queue at the tail of
that queue (i.e., given the priority of a NonCom
and put on the NonCom queue), where
queueing continues on a 1st come 1st serve basis.
-
After waiting a maximum of 4 more haircuts,
a Grunt is moved into the Officer queue,
but this time
at the head of the queue
but behind any Grunts who are already there,
(i.e., given the priority of an Officer
and moved to the Officer queue,
but not in front of any Grunts already there)
where
queueing continues on a 1st come 1st serve basis.
-
Yes, it is true that a Grunt can move up in front of
a NonCom, but being a Grunt does have some privileges.
In order to handle this mess,
the Barber Shop has changed its queueing system.
There are still a max of 20 chairs.
People are managed in chairs by setting priorities
associated with the chair.
For example, if a Grunt enters in chair 11, he
can be viewed as having priority 0 (Grunt level) and
in a FIFO queue of Grunts.
When he is moved because of slow processing to the NonCom level,
the Grunt is still in chair 11, but now has priority 1 (NonCom level)
and in a FIFO queue of NonComs.
When he is moved because of slow processing to the Officer level,
the Grunt is still in chair 11, but now has priority 2 (Officer level)
and in a FIFO queue of Officers.
Hair cuts still take the time
as found in the input stream.
Implementation Notes:
-
You should use a file containing random sleep times
(integers between 01 and 05 for Grunts,
between 11 and 15 for NonComs, and
between 21 and 25 for Officers
to drive your
Producer process:
-
the first digit provides the
food chain position
-
the second digit provides the
time for a haircut.
-
For the chairs,
one implementation choice is to make each chair a structure,
(rank, time waiting, queue, position in queue).
You can implement such a structure using arrays
(thus shared memory is still viable).
-
You are to manage the Barber Shop wait area as
priority queues, where each queue is a FIFO list.
People do not move to new chairs, rather through list
and priority queue management, the Producer and Consumer
know the next chair, i.e.,
person to get their hair cut or available chairs.
One approach is to have a free list of chairs and 3 other
lists, one for each level's FIFO list.
-
The Sergeant, the Producer, must also manage the wait
area (incoming area, the sidewalk)
outside the Barber Shop. He cannot let someone in
unless there is a chair at the appropriate level.
Each time he awakes
(time defaults to 3, but is a startup parameter),
he checks his waiting area (the input file)
and,
he will
seat someone as long as
there is room in the Barber Shop.
-
You
Do Not
have a pointer
datatype for the Barber Shop.
Use arrays with a
MAX_SIZE
and implement an array version
of a linked list for the waiting area.
-
You still need another process,
the Lieutenant,
who monitors the overall Barber Shop.
Because he is still young and ignorant,
every 2 seconds the lieutenant
pokes his head into the Barber Shop to determine:
-
Total number of Officers that have entered the system.
-
How many Officers are waiting in the Barber Shop.
-
How many Officers have gotten their hair cut.
-
Total number of NonComs that have entered the system.
-
How many NonComs are waiting in the Barber Shop.
-
How many NonComs have gotten their hair cut.
-
Total number of Grunts that have entered the system.
-
How many Grunts are waiting in the Barber Shop.
-
How many Grunts have gotten their hair cut.
-
How many Grunts are currently waiting in other queues,
i.e., have moved up in priority.
-
Total number of empty chairs.
-
Total number of occupied chairs.
-
Who is in the Barber Chair - Officer, NonCom, or Grunt.
-
The Lieutenant
numbers each output sequentially
(easier to watch the time fly).
-
Possible output also includes the 3 queues (everyone in the
queue, their chair number, etc.) - see
discussion of parameters.
Also, use the format of the example output found on the
web page.
-
Termination.
When the input file is empty,
the Sergeant terminates, but
the Barber continues until the last
long hair has had his
hair cut
and the Lieutenant continues until
both the Sergeant and Barber have
terminated.
Look at some of the semaphore operations
for ways to do this.
Thus,
the final output from the Lieutenant should show an
equal number of long hairs entering the system and
short hairs produced with an empty waiting room.
-
There are 3 parameters to the program:
-
Parameter 1 -
How long (in seconds) the Consumer process should
sleep before starting, default = 1.
-
Parameter 2 -
Used to determine if the Barber Shop contents
should be printed out by the Monitor/Lieutenant (print entire circular
buffer: default = 0, no print).
-
Parameter 3 -
How long the Producer should sleep between
each search of the wait area,
default = 3.
Due Dates:
Dec 1, 9PM
What to Turn-In:
-
Submit code in the usual way
-
To my box:
-
NO CODE
but rather
a detailed intro program comment that describes your
overall implementation:
-
including where you make the determination
as to whether to move a Grunt or not,
e.g., a separate process/procedure based on aging
or ?
This is a key point of your solution.
(Note, by process I mean a procedure, while it is true
you could create a separate system process that is not
necessary).
-
A paragraph how your program relates to scheduling,
memory management, and/or
virtual memory management in
an operating system (this is not just a coding project :-)
think about relationships with fixed size memory areas, priorities,
etc. )
-
Your comments need to be complete and detailed!!!
-
Also, see the Grade Sheet for this project when posted.
It involves a new set of inputs
to be run against your unchanged
program, but
you are to turn in the above prior to the runs
found on the grade sheet.
Where to Turn-In:
To the plastic bin outside Professor Erlinger's office.
References:
-
Solaris man pages for
fork, semctl, and shmctl
-
Chapter 3, UNIX Network Programming,
W. Richard Stevens.
On reserve in the library.
-
If you find other good references, please let me know.
Notes:
I reserve the right to change the problem statement
when someone demonstrates the ambiguity of said
problem statement.
Last modified Dec 2, 01 by mike@cs.hmc.edu