Home page:http://www.cis.njit.edu/franz E-mail:franz@cis.njit.edu
This programming assigment is the first of a three-phase project to be implemented in this course. The project consists of writing a program to simulate some general aspects and services of operating systems. Each phase of the project adds to the work done in the previouse phase. Therefore, it is important that you properly document your program and that you write the code in a way that facilitates making modifications if that should become necessary. You have the choice of using Pascal or C/C++ to write your program.
The Process Control Block:
A basic structure used thoughout the program is the process control block (PCB). The PCB is a structure which the system creates when a process first arrives and which it maintains throughout the lifetime of the process. The PCB conatins all the relevent information that the system needs to keep track of a process. When a process terminates, the system deallocates its PCB. The type and amount of information stored in a PCB differs among various operating systems. In our case we will define a record type called PCB_Type with fields as shown below. In addition we will define a type called PCB_ptr as a pointer to records of type PCB_Type.
- Next: A pointer to the next PCB in the linked list. - Name: The name of the process (up to 8 characters). - Type: A field that indicates whether the PCB is free or in use. If the PCB is in use then it should indicate whether it represents a system or a user process. - State: This field indicates the current state of the process. The possible states are: Ready, Running, or Blocked. - Suspend : This field indicates whether the process is currently suspended or not. - Priority: This field stores the priority of the process. This is a numerical value in the range -127 to 127.The data structure used in the program is a queue. There are two queues to maintain, the Ready Queue and the I/O Queue. The Ready Queue consists of the PCBs of all the processes that are ready to run but waiting for the CPU to become available. The I/O Queue consists of the PCBs of all the processes that are blocked (i.e. unable to run) because they are waiting for an event or I/O operation to complete.
The PCB Support Subprograms:
The following seven procedures and functions are the basic operations for manipulating the PCBs. Their use will become clear in the second phase of the project.
1) FUNCTION GET_PCB: PCB_ptr; This function takes no parameters. When called, the function returns a pointer to a free PCB. 2) PROCEDURE FREE_PCB (pcb: PCB_ptr); This procedure takes a pointer to a PCB that is currently in use and deallocates it. 3) PROCEDURE BUILD_PCB (pcb: PCB_ptr; name:String8; pcb_type: Proc_Type; pcb_state: Proc_state; pcb_sus: Suspend); where the types String8, Proc_Type, Proc_State, and Suspend can be defined as follows: String8 = Array [1..8] of Char; Proc_type = ( FREE, SYSTEM, USER); Proc_state = ( READY, RUNNING, BLOCKED); Suspend =(SUSPEND, NOT_SUSPENDED); The procedure is called to initialize the various fields of a PCB to the desired values. The parameter 'pcb' is a pointer to the PCB whose fields are to be initialized. The other parameters contain the values used for initializing the fields of the PCB. 4) PROCEDURE INSERT_PCB(var queue: PCB_ptr; pcb: PCB_ptr; method:Insertion_type) This Procedure is called to insert a PCB into a queue. Since there are two queues (Ready and I/O queue), a pointer to the queue to be used is passed in the parameter 'queue'. The parameter 'pcb' is a pointer to the PCB to be inserted into the queue. The parameter method specifies whether the PCB to be inserted is added at the rear of the queue (FIFO) or according to its priority so as to maintain the queue in decreasing order of priority. The type Insertion_Type may be declared as follow: Insert_type=(FIFO, PRIORITY); 5) FUNCTION REMOVE_PCB(var queue: PCB_ptr): PCB_ptr; This function removes the PCB at the head of the queue specified by the parameter 'queue' and returns a pointer to the PCB removed. 6) PROCEDURE SET_PRIORITY(pcb: PCB_ptr; prty: integer); This procedure sets the priority in the PCB specified by the parameter 'pcb' to the value specified by the parameter 'prty' 7) PROCEDURE DISPLAY(queue: PCB_ptr); This procedure prints the values assigned to each field of the PCBs in the queue specified by the parameter 'queue'. The only purpose of the procedure DISPLAY is to allow you to verify whether the code you have written is correctly maintaining the Ready Queue and IO Queue. This procedure prints the values assigned to each field of the PCBs in the queue specificed by the parameter 'queue'. The only purpose of the procedure DISPLAY is to allow you to verify whether the code you have written is correctly maintaining the Ready Queue and IO Queue.In order to test your code for the above functions and procedures you can write a program similar to the one outlined on the following page. Please note that for the second phase of the project you will only need the functions and procedures. The main phase is only for testing purposes.
Program MainHand 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 Teaching Assistant, Weihong Wu wxw3770@megahertz.njit.edu.
Type String8= Array[1..8] of char; Proc_type = (FREE, SYSTEM, USER); Proc_state= (READY, RUNNING, BLOCKED); Suspend = (SUSPENDED, NOT_SUSPENDED); Insert_type = (FIFO, PRIORITY); PCB_ptr =^PCB; PCB = Record Next:integer; Name:Strings; Type:Proc_type; .... end; .... Var ReadyQueue, IOQueue: PCB_ptr; p, q, r :PCB_ptr; (* The 7 procedures and functions described on the previous pages*) Begin ReadyQueue =Nil; IoQueue =Nil; p:= GET_PCB; BUILD_PCB(p, 'Sys1', SYSTEM, READY, NOT_SUSPENDED); SET_PRIORITY(p,30); q:= GET_PCB; BUILD_PCB(q, 'Sys2', SYSTEM, READY, NOT_SUSPENDED); SET_PRIORITY(q,55); INSERT_PCB(ReadyQueue, p,PRIORITY); INSERT_PCB(ReadyQueue, q,PRIORITY); p:= GET_PCB; BUILD_PCB(p, 'user1', USER, READY, SUSPENDED); SET_PRIORITY(P,10); q:= GET_PCB; BUILD_PCB(q, 'user2', USER, READY, NOT_SUSPENDED); SET_PRIORITY(q,25); r:= GET_PCB; BUILD_PCB(r, 'user1', USER, READY, SUSPENDED); SET_PRIORITY(r,20);
CIS 332 Principles of Operating Systems Fall 1996 Franz Kurfess.