1 / 22

Module R2

Module R2. Overview. Process queues. As processes enter the system and transition from state to state, they are stored queues. There may be many different types of queues: Job queue: jobs waiting to be loaded as processes. State queues: queues for each process state.

garran
Download Presentation

Module R2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module R2 Overview

  2. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different types of queues: • Job queue: jobs waiting to be loaded as processes. • State queues: queues for each process state. • Device queues: processes waiting for access to a particular device.

  3. Executing Processes Process scheduling and dispatching involves: • Creating processes as new jobs are admitted to the system. • Maintaining various queues, and moving processes from one queue to another. • Using some algorithm to select a process from the ready queue, and loading and giving control to the selected process.

  4. R2: Implement the control structures to: • Implement 2 abstract data types • PCBs • Doubly linked queues • Operations • Create, initialize, and destroy PCB’s • Insert and remove PCB’s from queues • It will NOT load and dispatch processes

  5. 2 layers to R2 • Internal layer • Defining abstract data types and the operations for objects of those types • These functions will be invoked, by operations implemented at the user interface level • User interface layer • Add new commands to COMHAN to allow the testing of your internal operations

  6. Process Queues • Sample structure Typedef struct queue { PCB *front; PCB *rear; } Queue; • We suggest you implement a separate queue for each possible process state: ready, suspended ready, blocked, and suspended blocked.

  7. Ready queue Process10 Process3 Proess1 Front Previous Previous Previous=Null Next Next = NULL Rear Next Process5 Previous Next Priority=120 Priority = 50 Priority = 50 Priority = 10 Each queue is a doubly linked list!!!!!

  8. We implement the queues as a doubly linked list because: • Occasionally, a process to be terminated will be in the middle of the queue, it is more efficient to locate and “unlink it”, than to use traditional queue operations • Also, the ready queue is maintained in “priority” order, so new processes may be enqueued into the middle of the queue!

  9. Queue Operations • Find PCB: • Searches for a specific PCB by process name. • It will “search” one or more queues • If the process is not found a “NULL” pointer will be returned. • If found the function will return a pointer to the PCB

  10. Insert PCB • Traditional FIFO insertion • For the blocked, suspended blocked, and suspended ready queue, we will implement the traditional FIFO enqueue. • New processes are added at the END of the queue. • Priority insertion • For the READY queue, we will implement a “priority” insertion algorithm • New processes are inserted into the queue IN FRONT of all processes with a lower priority

  11. Process10 Process3 Process1 Previous Previous Previous=Null Next Next = NULL Next Process20 Process5 Previous Previous Next Next Priority = 50 Priority = 50 Ready queue Front Rear Priority=120 Priority = 50 Priority = 10

  12. Remove PCB • Receives a pointer to the PCB • A pointer to a queue • UNLINKS the PCB from the queue May be called after a “find PCB” request remove a specific PCB from a queue. • You may want to also implement a traditional “dequeue” operation.

  13. Process Control Blocks (PCBs) • Suggested structure // PCB structure typedef struct PCB{ struct IOCB iocb; char pname[20]; //Process name at least 8 characters int pclass; //A code identifying the process as an //application process or a system process int priority; // range -128 ~ +127 int state; // Running, Ready, Blocked, Suspended Ready, or // Suspended blocked struct PCB * previous; // pointer of the previous PCB in the queue struct PCB * next; // pointer of the next PCB in the queue unsigned char * stack_base; // Stack pointer to the base unsigned char *stack_p; //stackptr int memory; unsigned char *load; //pointer to where the process is loaded unsigned char *execution; //pointer to execution addr } PCB;

  14. PCB operations • Allocate PCB This operation will dynamically allocate a “new” PCB and return a pointer to it. If the allocation fails, a NULL pointer should be returned

  15. Free PCB Given a pointer to a PCB, this function is responsible for: • Freeing all storage contained in the PCB • Freeing the space associated with the PCB • Setting the incoming pointer to NULL

  16. Setup PCB Initializes the contents of a PCB!!! • Receives a pointer to a PCB • Input parameters for Name, priority, class, and state (always “ready” for R2) • Allocate memory for the stack and initialize the stack pointer (not used in R2) • Allocate a memory area for the process. (this is not used in R2, so the memory size should be set to zero and all related pointers set to NULL!!!!!!)

  17. User Interface operations! • Create_PCB • Allocates and sets-up a new PCB, it receives arguments for name, class and priority • Delete_PCB • Given a process name, this function will “find”, “remove”, and “free” a process! • Block • This function moves a process from the ready queue to the blocked queue (or from one suspended queue to the other.) • It receives the process name as an argument

  18. Unblock • This function moves a process from the blocked queue to the ready queue (or from one suspended queue to the other.) • It receives the process name as an argument • Suspend • This function moves a process from either the “ready” or “blocked” queue to the associated “suspended” queue. • It receives the process name as an argument

  19. Resume • This function moves a process from either of “suspended” queues back to either the “ready” or the “blocked” queues • It receives the process name as an argument Please note: These operations require that we “find” a PCB, “remove” it from one queue and “insert” it into another!

  20. Set Priority • This function is used to change the priority of a specific process. • It must “find” the process • Change the value of it’s priority • Show_PCB • Displays the contents of a single PCB • Receives the process name as an argument.

  21. Show All • This function prints information for ALL PCBs in the system!!!!! Displays the contents of EVERY queue!!! • Need to select an attractive display format!!! • Show Ready • This function displays information for all of the PCB in both the ready queue or the suspended ready queue.

  22. Show blocked • Shows information for all PCBs in either the blocked or suspended blocked queues.

More Related