Home page:http://www.cis.njit.edu/franz E-mail:franz@cis.njit.edu
The process control Block:
The following fields should be added to your PCB structure:
- ADDRESS: the address in memory where the process is currently allocated. - SIZE: the amount of memory needed by a process.
The priority of a process is first generated by the procedure NextEvent. However, the priority of a process will change based on whether the process is I/O-bound or CPU-bound in the following way. Everytime a process uses its quantum entirely (CPU-bound) its priority is lowered by 10% before inserting it back into the ready queue. If, on the other hand, a process blocks (IO-bound) before its quantum has expired, the priority of the process is increased by 10% before removing it from the ready queue and inserting it into the I/O queue. You should always make sure that the priority of a USER process remains in the range of (-128 .. 0), and that the priority of a SYSTEM process remains in the range (1 .. 128).
We will assume that we have 256K of main memory. This memory is to be managed using the variable-size partion scheme. Memory is allocated in multiples of 1K Bytes. A bit map is used to keep track of which parts of the memory are in use and which parts are free.
Whenever a new process arrives (event #1), it must be allocated the memory it needs to be able to run. If no allocation can be found then one or more processes will be suspended in order to release enough memory for the new process to be allocated. Upon termination, the memory held by a process is returned back to the system.
Since the memory is allocated in multiples of 1K all we need to implement in the bit map is an array of 256 elements, where each element of the array can be either true or false indicating whether the corresponding 1K block is in use or free:
BitMap: array[0..255] of Boolean;
Besides the bit map, we need two procedures: one to perform the allocation and another to perform the deallocation of the memory:
Procedure Allocate(size: Integer; Var Flag: Boolean; Var Addr: Integer);
The procedure allocate is called whenever memory is to be allocated. The parameter size is the amount of memory that is requested. If the allocation was successful the parameter Flag is set to true and the parameter Addr is set to the memory address where the allocation is made. If the allocation could not be made then the parameter Flag is set to false. The procedure allocate determines whether the allocation can be made or not by examining the bit map. Its task is to find the first sequence (First Fit) of free memory bits in the bit map that satisfies the request. In the case where an allocation is made, the corresponding bits in the bit map are changed to indicate that the 1K blocks involved in the allocation are no longer free. The deallocation of memory is done by calling the procedure Deallocate:
Procedure Deallocate(Addr, Size: Integer);
The procedure Deallocate is called when the memory of a process is to be deallocated. The parameters Addr and Size specify the location and the size of the memory to be deallocated. Deallocating memory is done simply by changing the appropriate bits in the bit map.
When a new process arrives we have to allocate it the memory that it needs. This can be done by calling the procedure Allocate which examines the bit map to try to find a free contiguous block of memory of the required size. If the procedure allocate is unable to make the allocation, then we have to create free memory by suspending one or more processes. When process gets suspended its allocated memory is reclaimed (by calling the procedure Deallocate) and we are able to generate enough free memory to allocate the newly arrived process.
In deciding which process to suspend we will first consider the I/O queue. If we are unable to free up the required memory then we will consider suspending one or more processes from the ready queue. When a process that is in the ready queue or I/O queue becomes suspended it remains in the same queue (i.e its state does not change).
Whenever a process terminates we reclaim the memory that it held. Since this increases the amount of free memory the system has, we try to reallocate as many suspended processes as we can. We will first attempt to reallocate the processes in the Ready queue and then to reallocate the processes in the I/O queue.
A process in the Ready queue can only be dispatched if it is not suspended. Since the Ready queue contains the processes whose state is READY but which may or may not be suspended, the dispatcher will have to find and dispatch the first process from the Ready queue that is not suspended.
When a process is scheduled it is inserted into the Ready queue according to its priority.
The output of the program should be a detailed account of all the events that have occured. This includes showing which processes are suspended and when do they become not suspended. As in the previous phase we are interested in determining the average turn-around and wait times.
This is the new version of the file EventGen to be used with the third phase of the project. Please note that two parameters have been added to the procedure NextEvent: Priority and size. These parameters will only be defined in event #1. The parameter `priority' is the initial priority assigned to the process. The parameter `size' is the memory required by the process.
Unit EventGen; Interface
type String8 = string[8]; procedure NextEvent(RunProc: String8; var event: Integer; var name: String8; var ptype: Integer; var priority: Integer; var size: Integer);
Implementation;
var Bprocs: array[1..50] of string8; Ucount, Scount, Bcount: Integer; procedure NextEvent(RunProc: String8; var event: Integer; var name: String8; var ptype: Integer; var priority: Integer; var size: Integer); var r:real; S: string[3] B: Integer; begin r :=random if Bcount > 5 then r := 0.1; if r < 0.2 then begin if Bcount = 0 then event :=0 else begin event :=4; B := random(Bcount) + 1; name := Bprocs[B] Bprocs[B] := Bprocs[Bcount]; Bcount := Bcount - 1; end end else if r< 0.5 then begin event := 1; ptype := Trunc( random + 0.5); if ptype = 0 then begin Ucount := Ucount + 1; Str(Ucount, S); name := 'USER' + S; Priority := -80 + random(35); size := 20 + random(40); end else begin Scount := Scount + 1; Str(Scount, S); name := 'SYS' + S; priority := 30 + random(35); Size := 20 + random(40); end; end else if r < 0.6 then begin event := 2; name := RunProc end else if r < 0.8 then begin if RunProc = '' then event := 0 else begin event := 3; Bcount := Bcount + 1; Bprocs[Bcount] := RunProc; name := RunProc; end; end else event := 0 end; Begin Ucount := 0; Scount := 0; Bcount := 0; End.Hand in this assignment via electronic mail; also keep a copy of the assignment in your computer for future use. The program must be well documented. Documentation is a very important part of a software product. The TA will run you program on megahertz, so before handing it in you should test your program on megahertz. You can include some information about how to compile you program on megahertz, the parameters, etc. This assignment will contribute 20 points towards your homework/assignment score. Late submission or copying other student's code will be penalized. Please send your answers via electronic mail to the CIS 332 class account cis332fk@cis.njit.edu. It is easier for us to handle if you don't split it up into too many messages, and if you include plain ASCII files in your mail (instead of attachments).
CIS 332 Principles of Operating Systems Fall 1996 Franz Kurfess.