chapter 2 (part 2)

Download Chapter 2 (Part 2)

Post on 19-Nov-2014

2.002 views

Category:

Technology

2 download

Embed Size (px)

DESCRIPTION

 

TRANSCRIPT

  • 1. Chapter 2Memory and processManagement PART 2: PROCESSMANAGEMENT IN OS DEPARTMENT OF IT & COMMUNICATION POLITEKNIK TUANKU SYED SIRAJUDDIN

2. Learning Outcome By the end of this chapter, student will be able to:1) Explain role of control blocks and interrupt in the dispatching process2) Describe various types of scheduling processes3) Explain different types of scheduling algorithms4) Explain how queuing and the scheduler work together5) Differences between multiprogramming and time sharing6) Explain how to handle deadlock 3. ProcessProcess a program in execution.A process need resources (CPU time, files, I/O devices) to accomplish task.process execution must progress in sequential fashion 4. Process include:1)Program counter2)Process Stack containing temp data (subroutineparameters, return addresses, temp variables)3)Data section containing global variables. 5. Process state 6. .Process stateAs a processes executes, it changes state.Each process in on of the following state : NEW The process is being created. READY The process is waiting to be assigned to a pocessor. RUNNING Instruction are being executed. WAITING The process are waiting for some event to occur (I/O completion or reception of a signal) TERMINATED The process has finished execution. 7. Control blocksEach process is representer in the OS by a process control blok (PCB).There are several control fields that must be maintained in support of each active program.Often, a control block is created to hold: 1) a partitions key control flags, 2) constants 3) variablesThe control blocks (one per partition) are linked to form a linked list. 8. ..Control blocksThe dispatcher typically determines which program is to start by following the chain of pointers from control block to control block.A given control blocks relative position in the linked list might be determined by its priority or computed dynamically, perhaps taking into account such factors as: 1) programsize, 2) time in memory, 3) peripheral device requirements 4) andother measures of the programs impact on system resources. 9. Control blocksInformation abouteach program isstored in theprograms controlblock.The dispatcherdetermines whichprogram to startnext byfollowing a linkedlist ofcontrol blocks. 10. InterruptsAn interrupt is an electronic signal. Hardware senses the signal, saves key control information for the currently executing program, and starts the operating systems interrupt handler routine. At that instant, the interrupt ends.The operating system then handles the interrupt.Subsequently, after the interrupt is processed, the dispatcher starts an application program.Eventually, the program that was executing at the time of the interrupt resumes processing. 11. Example of how interrupt workStep 1: 12. Example of how interrupt workStep 2: 13. Example of how interrupt workStep 3: 14. Example of how interrupt workStep 4: 15. Example of how interrupt workStep 5: 16. Example of how interrupt workStep 6: 17. CPU SCHEDULINGBasic Conceptts :Objective of multiprogramming to have someprocess running at all time, to maximize CPUutilization.When one process in wait state OS will take theCPU away from that process and gives the CPU toanother one. This pattern continuesUniprecess ??? Only ONE running process. Ifmore than one ??? 18. .CPU SchedulerCPU scheduling decisions may take place whena process:1. Switches from running to waiting state2. Switches from running to ready state3. Switches from waiting to ready4. Terminates Scheduling under 1 and 4 is nonpreemptiveAll other scheduling is preemptive 19. ...CPU Scheduler Preemptive scheduling policy interrupts processing of a job and transfers the CPU to another job.- The process may be pre-empted by the operating system when:1) a new process arrives (perhaps at a higher priority), or2) an interrupt or signal occurs, or3) a (frequent) clock interrupt occurs. Non-preemptive scheduling policy functions without external interrupts.- once a process is executing, it will continue to execute until it terminates, or by switching o the waiting state. 20. CPU SchedulingScheduling criteria:1)CPU utilizationThe ratio of busy time of the processor to the total timepasses for processes to finish. Processor Utilization = (Processor busy time) /(Processor busy time + Processor idle time)To keep the CPU as busy as possible 21. CPU Scheduling2) ThroughputIf the CPU is busy executing process then workis being done.The measure of work done in a unit time interval. Throughput =(Number of processes completed) / (Time Unit)Long process would take one process/hourShort process might take 10 processes/second. 22. .CPU Scheduling3) Turnaround time How long it takes to execute a process. The sum of time spent waiting to get into memory, waiting in ready queue, execution time on CPU and doing I/O time. tat = time(process completed) time(process submitted)4) Waiting time The sum of periods spent waiting in the ready queue only.5) Response time Time from the submission of a request until the first response is produced. This criterion is important for interactive systems. rt = t(first response) t(submission of request) 23. .CPU SchedulingTypes of scheduling:1)long-term scheduling2)Medium-term scheduling3)Short-term scheduling 24. Long-term schedulingDetermine which programs admitted to system for processing - controls degree of multiprogramming Once admitted, program becomes a process, either: added to queue for short-term scheduler swapped out (to disk), so added to queue for medium-termscheduler 25. Medium term schedulingPart of swapping function between main memory and disk - based on how many processes the OS wants available at any one time - must consider memory management if no virtual memory (VM), so look at memory requirements of swapped out processes 26. Short term scheduling (dispatcher)Executes most frequently, to decide which process to execute next Invoked whenever event occurs that interrupts currentprocess or provides an opportunity to preempt currentone in favor of another Events: clock interrupt, I/O interrupt, OS call, signal 27. Scheduling AlgorithmCPU scheduling deals with the problem of deciding which of the processes in the readyqueue is to be allocated the CPU. 28. .Scheduling AlgorithmTypes of scheduling algorithm:Basic strategies1)First In First Out (FIFO) / First Come, First-Served.2)Shortest Job First (SJF)3)Shortest Remaining Time First (SRTF)4)Round Robin (RR)5)PriorityCombined strategies1)Multi-level queue2)Multi-level feedback queue 29. First Come First Serve (FIFO) Non-preemptive. Handles jobs according to their arrival time -- the earlier theyarrive, the sooner theyre served. The process the request the CPU first is allocated the CPUfirst. Simplest algorithm to implement -- uses a FIFO queue. Good for batch systems; not so good for interactive ones. Turnaround time is unpredictable. 30. Shortest Job First (SJF) Non-preemptive. Handles jobs based on length of their CPU cycle time. Use lengths to schedule process with shortest time. Optimal gives minimum average waiting time for a givenset of processes. optimal only when all of jobs are available at same time andthe CPU estimates are available and accurate. Doesnt work in interactive systems because users dontestimate in advance CPU time required to run their jobs. 31. Shortest Remaining Time First (SRTF) Preemptive version of the SJF algorithm. Processor allocated to job closest to completion. This job can be preempted if a newer job in READY queuehas a time to completion thats shorter. Cant be implemented in interactive system -- requiresadvance knowledge of CPU time required to finish each job. SRT involves more overhead than SJN. OS monitors CPU time for all jobs in READY queue andperforms context switching. 32. Round Robin (RR) FCFS with Preemption. Used extensively in interactive systems because its easy toimplement. Isnt based on job characteristics but on a predetermined sliceof time thats given to each job. Ensures CPU is equally shared among all active processesand isnt monopolized by any one job. Time slice is called a time quantum size crucial to system performance (100 ms to 1-2 secs) 33. Priority scheduling Non-preemptive. Gives preferential treatment to important jobs.Programs with highest priority are processed first. Arent interrupted until CPU cycles are completed or a natural wait occurs. If 2+ jobs with equal priority are in READY queue, processoris allocated to one that arrived first (first come first servedwithin priority). Many different methods of assigning priorities by systemadministrator or by Processor Manager. 34. Multi-level queue 35. Multi-level queue 36. Multi-level queue 37. Multi-level feedback queue (MLFQ) 38. Multi-level feedback queue (MLFQ) : Example 39. Queuing and schedulerAs one program finishes processing and space becomes available, which program is loaded into memory next?This decision typically involves two separate modules, a queuing routine and a scheduler 40. Queuing and scheduler1) As programs enter thesystem, they are placed on aqueue by the queuingroutine.2) When space becomesavailable, the schedulerselects a program from thequeue and loads it intomemory. 41. Multiprogramming and time sharing A timesharing system allows multiple users to interact with acomputer at the same time Multiprogramming allowed multiple processes to be active atonce, which gave rise to the ability for programmers tointeract with the computer system directly, while still sharingits resources In a timesharing system, each user has his or her own virtualmachine, in which all system resources are (in effect)available for use