Operating Systems - Projects and Exercises

Exercise 11 - Resource Management

The Resource Management required for the second project is very simple. The Real-Time processes need no i/o resources, so that resource allocation need only be implemented for the Lo-Priority processes.

In addition, you know in advance what resources are going to be required by the processes so they can all be allocated before the process is admitted to the feedback queue(s) and marked as READY to run.

The check, allocation and freeing of resources can be done at the same time as the check, etc for memory allocation, so it makes sense to have analogous function entry points (e.g. rsrcChk, rsrcAlloc, and rsrcFree).These will be discussed during this weeks tutorials.

The only other thing we need to do is merge the two different dispatchers we have written. To comply with the project specification we will also need to add the capability to insert different priority jobs into the three different Feedback queues - you can now see why the list of jobs in rr.txt all have priority 3 so that all the jobs are inserted at the lowest priority feedback queue, effectively limiting our model to a simple Round Robin queue.

The Full HOST Dispatcher

We should now be ready to put all the parts of the HOST dispatcher together:

  1. Initialize dispatcher queues (input queue, real time queue, user job queue, and feedback queues);
  2. Initialise memory and resource allocation structures;
  3. Fill input queue from dispatch list file;
  4. Start dispatcher timer (dispatcher timer = 0);
  5. While there's anything in any of the queues or there is a currently running process:
    1. Unload pending processes from the input queue:
      While (head-of-input-queue.arrival-time <= dispatcher timer)
      dequeue process from input queue and enqueue on either:
      1. Real-time queue or
      2. User job queue;
    2. Unload pending processes from the user job queue:
      While (head-of-user-job-queue.mbytes can be allocated and resources are available)
      1. dequeue process from user job queue,
      2. allocate memory to the process,
      3. allocate i/o resources to process, and
      4. enqueue on appropriate priority feedback queue;
    3. If a process is currently running:
      1. Decrement process remainingcputime;
      2. If times up:
        1. Send SIGINT to the process to terminate it;
        2. Free memory and resources allocated to the process (user processes only);
        3. Free up process structure memory;
      3. else if it is a user process and other processes are waiting in any of the queues:
        1. Send SIGTSTP to suspend it;
        2. Reduce the priority of the process (if possible) and enqueue it on the appropriate feedback queue
    4. If no process currently running && real time queue and feedback queue are not all empty:
      1. Dequeue a process from the highest priority queue that is not empty
      2. If already started but suspended, restart it (send SIGCONT to it)
        else start it (fork & exec)
      3. Set it as currently running process;
    5. sleep for one second;
    6. Increment dispatcher timer;
    7. Go back to 5.
  6. Exit.

Note that there is nothing really new in the above - it is a merging of logic from previous exercises.

Try this with the following example job list:

0, 1, 2, 128, 1, 0, 0, 1
1, 0, 1, 64, 0, 0, 0, 0
1, 1, 1, 128, 0, 0, 0, 0
1, 1, 2, 256, 1, 0, 0, 0
2, 1, 3, 256, 0, 0, 0, 2
3, 1, 2, 770, 1, 0, 0, 0

The order of execution will be:

T = 0   1   2   3   4   5   6   7   8   9  10  11
P0:  PFR  S   S   S   R |
P1:      QR |
P2:      PF   R |
P3:      PF   F   R   S   R |
P4:           P   P   P   P  FR   R   R |
P5:               P   P   P   P   P   P   FR  R |
where:
P: in pending queue waiting for resources
Q: queued in Real Time queue - not started
F: queued in feedback queue - not started
R: process running
S: process suspended in feedback queue
|: process terminated

Code should be in 'straight' C using the compiler of your choice (cc or gcc).

Always use nice to execute your test programs at lower priority to ensure they do not inconvenience other users if they go 'haywire'. e.g.:
 
   >nice a.out

The descriptions of the system functions above are drawn from sources that include manuals on the Sun Solaris system and the MAC OS X Darwin/BDS system, and also from 'Advanced Programming in the UNIX Environment', W. Richard Stevens, Addison-Wesley, 1993.

Go home top

For use only by students and instructors using the supplementary material available with the text book: "Operating Systems - Internals and Design Principles", William Stallings, Prentice Hall, 5th Edition, 2004. Not to be printed out or copied by any other persons or used for any other purpose without written permission of the author(s).

©