This program is a modification of the solution to Project 3.  Because of higher priority on Officers and Noncoms, Grunts would get any haircuts.  As a result, the program is modified to Grunts' priority and guarantee Grunts to have haircut.  Grunts' priority will be increased in the following way.

I decided to add two more fields on chair structure.  The new fields are the number of waiting time and the tag whether it is Grunt who has higher priority due to a lot of waiting time.  As a resunlt, now all chairs have information of group, priority, haircut time, the number of waiting time, and tag that indicates the person is higher priority Grunt or not.

Every time, the barber cut person's hair, the process will search the Grunts in chairs and if the person is Grunts, then it will increase the number of waiting time.  If the number of waiting time is 5, then the process will change its group to NomCom and tag to "G", so now it is in NomCom group but we can distinguish the person is actually Grunt because of the tag.  The person will be moved into the NonCom queue at the tail of that queue as project required.

And if the Grunt's the number of waiting time is 9 then, the group will be changed to Officer and it still has "G" on its chair tag.  This time, the Grunt will be moved at the head of the queue but behind any Grunts who are already in Officer's queue.

When the process is print out the status of buffer, the Grunt who has higher priority will print "G" and its priority.

Additional problem: the new General is very fat so the General must sit two adjacent chairs.

As described the problem in the project, the new General is very fat and he must wait until two adjacent chairs available.  So I decided to check the input first.  If the input is General, then, check the first empty chair and next chair.  If two adjacent chairs are available for him, then just give him two chairs.  If two adjacent chairs are not available, I called another function and will keep check the chairs until two adjacent chairs are available.  When the function found two adjacent chairs, the function will return the starting index of two adjacent chairs. Then the sergeant process will assign two chairs for the fat General.

To have haircut for the General, I used the tag to distinguish whether it is General or not.  I put "O" on tag for general and second chair for "P" so the process can make right order for General and terminate the General from two adjacent chairs.

When the process is print out the status of buffer, the General who take two adjacent chairs will print "O" and its priority.

As I said in Project 3, the program has 20 chairs and a lot of people want to have haircut.  As same as the program, operating system and real system have limited, expensive resources, and people want to share systems at the same time.  As a result, it is very important that the operating system can manipulate shared memory and priorities of jobs.  The operating system should make sure that the process will not overwrite shared memory and schedule well jobs in the queue.

Also, operating system should be able to manipulate jobs that has low priority and waited for long time.  The operating system cannot let the jobs wait forever so it should have some priority change system for these jobs.

In addition, some jobs need to have more memory than normal and average size jobs.  In this case the operating system should find available space for this jobs so the big size job can be processed.  This procedure is as same as the General problem.