Operating Systems - Lecture #6: Process Management

Transcription

Operating SystemsLecture #6: Process ManagementWritten by David Goodwinbased on the lecture series of Dr. Dayou Liand the book Understanding Operating Systems 4th ed.by I.M.Flynn and A.McIver McHoes (2006)Department of Computer Science and Technology,University of Bedfordshire.Operating Systems, 201304th March 2013

OutlineLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire1 Introduction2 SchedulingIntroductionScheduling3 Process statusProcess statusProcess control blockMultithreading4 Process control blockProcess schedulingpolicies5 MultithreadingProcess schedulingalgorithmssummary6 Process scheduling policies7 Process scheduling algorithms8 summaryOperating Systems35

Lecture #6 ProcessManagementDavid GoodwinUniversity rocess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35

PROCESS MANAGEMENT CONCEPTSLecture #6 ProcessManagement Concept of a process TerminologyDavid GoodwinUniversity ofBedfordshireIntroduction4 Job (also known as program) is an inactive unit such as a filein diskScheduling This entity contains at least two types of elements: programProcess statuscode and a set of dataProcess control block Process (also called task) is an executed program code onMultithreadingthe processor, that is, a part of an active entity a Thread is a portion of a process that can be runProcess schedulingpoliciesindependentlyProcess schedulingalgorithms In multiprogramming environment, the processor is used bymultiple programs/processessummary Process manager needs to arrange the execution of theprograms/processes (to make a schedule for them) topromote the most efficient use of resources (includinghardware and software) and to avoid competition anddeadlockOperating Systems35

Lecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionScheduling5Process statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35Scheduling

Job and Process SchedulingLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire Schedulers Job schedulerIntroductionScheduling6Process status Initialise each job Only concerned with selecting jobs from a queue of incomingjobsProcess control block Places them in a process queue (READY queue)Multithreading Process scheduler Determines which jobs get the CPU, when, and for how long. Also decides when processing should be interrupted decides when each step will be executed recognises when a job has concluded and should beProcess schedulingpoliciesProcess schedulingalgorithmssummaryterminated Hierarchy Job scheduler is the high-level scheduler Process scheduler is the low-level schedulerOperating Systems35

Process ShedulerLecture #6 ProcessManagement Common trait among most computer programs: theyDavid GoodwinUniversity ofBedfordshirealternate between CPU cycles and IO cycles Process scheduler is a low-level scheduler that assigns CPUIntroductionScheduling7Process statusProcess control blockMultithreadingProcess schedulingpoliciesthe execute the processes of those jobs placed in the readyqueue by the job scheduler. Although CPU cycles vary from program to program, thereare some general types of jobs: IO-Bound jobs e.g. printing a series of documents. ManyProcess schedulingalgorithmsbrief CPU cycles and long IO cycles. CPU-Bound jobs e.g. finding the first 300 prime numbers.summaryLong CPU cycles and shorter IO cycles. Total statistical effect approximates a Poisson distribution. Highly interactive environment has a third level - begin amiddle-level scheduler - finding it advantagious to removeactive jobs from memory; allowing jobs to complete faster.Operating Systems35

Lecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess status8Process control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35Process status

PROCESS STATUSTwo-state modelLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess status9Process control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35 Process queue Processes are divided intothreads The threads form a“ready queue” waiting forbeing processed in theprocessor Two-state model A process is in “running”state if it is executed onthe processor It is in “not running”state otherwise

PROCESS STATUSLecture #6 ProcessManagement Five-state model StatesDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess status10Process control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35 Running: the process is currently executed on the processorReady: a process is prepared to executeWaiting: a process waits for resourcesHold: a process is just createdExit: a process is released from pool of executable programsby OS

PROCESS STATUSLecture #6 ProcessManagement State transitions:1 HOLD to READY:David GoodwinUniversity ofBedfordshire When OS is prepared to take an additional process. InitiatedIntroductionby job scheduler; availability of memory and devices checked.SchedulingProcess status2READY to RUNNING:3RUNNING to EXIT: Process scheduler chooses a ready process to execute.11Process control block Currently executed process has completed or a run time error.MultithreadingProcess schedulingpoliciesInitiated by job or process scheduler.4Process schedulingalgorithmsRUNNING to WAIT: Handled by process scheduler, initiated by job instruction forsummaryI/O or other resources request.5WAIT to READY: Handled by process scheduler, initiated when I/O or otherresources become available.6RUNNING to READY: Handled by process scheduler; maximum allowable time isreached or other criterion e.g. a priority interrupt.Operating Systems35

Lecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess control blockProcess statusProcess control block 12MultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35

Process Control BlocksLecture #6 ProcessManagementProcess control block (PCB): Any process is uniquelycharacterised by a list of elements: Identifier: a unique identifier which distinguishes aDavid GoodwinUniversity ofBedfordshireprocess from othersIntroductionSchedulingProcess statusProcess control block 13 State: a process can have different states Priority: this shows the priority level of a process relativeto other process Program counter: the address of the instruction to beMultithreadingProcess schedulingpoliciesexecuted next of a process (program code) Memory pointers: include those point to program codeProcess schedulingalgorithmsand data associated of a process, plus any memoryblocks shared with other processessummary Context data: These are date that are presented inregisters in the processor while a process is running I/O status information: includes I/O requests and theavailability of files and I/O devices Accounting information: includes time and numbercounteredOperating Systems35

Process StateLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire This contains all of the information needed to indicate theIntroductionSchedulingProcess statusProcess control block 14MultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35current state of the job such as:process status word current instruction counter and registercontents when a job isn’t running.register contents if the job has been interrupted and iswaiting.main memory information including the address where thejob is stored.resources information about all resources allocated tothe job, being hardware units or files.process priority used by systems with priority schedulingalgorithm.

AccountingLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire Information for billing purposes and performancemeasurement. Typical charges include:Introduction Amount of CPU time used from beginning to end ofSchedulingexecution.Process statusProcess control block 15Multithreading Total time the job was in the system until exited. Main storage occupancy - how long the job stayed in memoryuntil it finished execution.Process schedulingpolicies Secondary storage used during execution. System programs used (compilers, editors, utilities, etc.) Number and type of IO operations, including IO tranmissionProcess schedulingalgorithmssummarytime (includes use of channels, control units, devices) Time spent waiting for IO completion Number of input records read, and number of output recordswrittenOperating Systems35

Lecture #6 ProcessManagementDavid GoodwinUniversity Process statusProcess control blockMultithreading16Process schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35

PROCESS MANAGEMENTMultithreadingLecture #6 ProcessManagement Multithreading A process can be divided into multiple threadsDavid GoodwinUniversity ofBedfordshire Multithreading is a “condition” for a processor manager toIntroductionmake a schedule for multi-processesScheduling An example of a process and threadsProcess statusProcess control blockMultithreading17Process schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems35 Get input for Job AIdentify resourcesExecute the processInterruptSwitch to Job BGet input for Job BIdentify resourcesExecute the processTerminate Job BSwitch back to Job AResume executinginterrupted process Terminate Job A

Lecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionProcess schedulingpoliciesSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpolicies18Process schedulingalgorithmssummaryOperating Systems35

Process scheduling policiesLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpolicies19Process schedulingalgorithmssummary A good process scheduling policy: Maximise throughput - run as many jobs as possible in agiven amount of time Minimise reponse time - quickly turn around interactiverequests Minimise turnaround time - move entire jobs in and out ofthe system quickly Minimise waiting time - move jobs out of the ready queue asquickly as possible Maximise CPU efficiency - keep the CPU busy 100% of thetime Ensure fairness for all jobs - give every job an equal amountof CPU and IO time A scheduling strategy that interrupts the processing of a jobOperating Systemsand transfers the CPU to another job is preemptivescheduling policy The alternative is nonpreemptive scheduling policy whichfunctions without external interrupts35

Lecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionProcess schedulingalgorithmsSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms20summaryOperating Systems35

Process scheduling algorithmsFCFS - First-come-first-servedLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire Batch environment Jobs/processes arrive at the times that are too close to oneanother Those jobs/processes are collected in batches First-come-first-serve (FCFS)IntroductionSchedulingProcess statusProcess control blockMultithreading A READY queue for storing ready processes that areProcess schedulingpolicies When a process is in RUNNING state, its execution will beProcess schedulingalgorithmsinitialised by Job scheduler21completed in one go, that is, these is no waiting state in thisalgorithm Average turnaround time (τ ) Total time needed for every process completed divided by thesummarynumber of processes in the queue Depends on how the processes are queued in the READYqueueOperating Systems35

Process scheduling algorithmsFCFS - First-come-first-servedLecture #6 ProcessManagement Example: Process A has CPU cycle (ta 5 ms)Process B has CPU cycle (tb 2 ms)Process C has CPU cycle (tc 1 ms) When the 3 processes become ready in the order of ABCDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms22τ (5 7 8)/3 6.67 When the 3 processes become ready in the order of BCAsummaryτ (2 3 8)/3 4.33Operating Systems35

Process scheduling algorithmsSJF - Shortest job FirstLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire Shortest job first [next] (SJF) [SJN] Process that uses the shortest CPU cycle will be selected forrunning first Example:Processes:A B C DCPU cycle (ti ): 526 4IntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms23summaryTb 2, Td 6, Ta 11, Tc 17τ (Tb Td Ta Tc )/4 9Operating Systems35

Process scheduling algorithmsSJF - Shortest job FirstLecture #6 ProcessManagement Optimal in terms of occupying the least CPU timeProcesses:A B C Example:CPU cycle (ti ): 521David GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmsτ (1 3 8)/3 424summaryOperating Systems35

Process scheduling algorithmsSRT - Shortest remaining timeLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire Real-time environment Shortest remaining time (SRT)IntroductionScheduling Process that the mostly close to complete will be processProcess statusfirst, and even this process can be pre-empted if a newerprocess in READY queue has a shorter complete time ExampleArrival time:0123Process:abcdCPU cycle:6314Process control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms25summaryτ (14 4 1 6)/4 6.25Operating Systems35

Process scheduling algorithmsRound-RobinLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms26summaryOperating Systems35 Round robin Time is divided into slices called time quantum Processes in the READY queue will be processed in FIFO Process scheduler will pick up a process from the front of theREADY queue and allocate it to CPU when a time slide starts When the time slide ends but the processing has not beencomplete, the scheduler will send the remaining part of theprocess back to the end of the READY queue It can only be resumed when it gets to the front of the queue

Process scheduling algorithmsRound-RobinLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire ExampleIntroductionArrival time:Process:CPU cycle:SchedulingProcess statusProcess control block0a81b42c93d5MultithreadingProcess schedulingpoliciesProcess schedulingalgorithms27summary τ (20 7 24 22)/4 18.25Operating Systems35

Process scheduling algorithmsPriority schedulingLecture #6 ProcessManagement Priority scheduling Allowing process with the highest priority to be processed first The processing is not interrupted unless the CPU cycle of theprocess is completed or a natural wait occurs If more than one process has the same priority, the one whichjoins the ready queue first is processed first Priorities:David GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess statusProcess control blockMultithreading Memory requirements - jobs requiring large amounts ofProcess schedulingpoliciesProcess schedulingalgorithms28summaryOperating Systems35memory could be allocated lower priorities than thoserequiring small amounts of memory Number and type of device - jobs requiring many deviceswould be allocated lower priorities Total CPU time - jobs having long CPU cycle, or estimatedrun time, would be given lower priorities Amount of time already spent in the system - some systemsincrease priority of jobs that have been in the system for anunusually long time. This is known as aging

Process scheduling algorithmsMultilevel feedback queueLecture #6 ProcessManagement Multilevel feedback queue When time out for a high-priority process, it is added to thetail of the queue consisting of lower priority level processesDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms29summaryOperating Systems35

Process scheduling algorithmsMultilevel feedback queueLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshire Priority inversion and inheritance Priority inversion problem: a high-priority process waits on alow-priority process that is starved by a medium-priorityprocess (for example, releasing some resources) ExampleIntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms30summaryOperating Systems35 Three processes, a, b and c with p(a) 2, p(b) 3 and p(c) 4Process c waits on aa is starved by b (b is never put in waiting state)Process a cannot compete with b and therefore b is alwaysrunning and a and c never get chance to run It looks like c with p(c) 4 had lower priority than b withp(b) 3

Process scheduling algorithmsMultilevel feedback queueLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess status Solution – priority inheritance Elevating the priority a to 4 so that it can compete with band win in competitionProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms31summaryOperating Systems35

process scheduling algorithms - comparisonLecture #6 ProcessManagement FCFS - nonpreemptive - batch - unpredictable turnaround - Easyto implementDavid GoodwinUniversity ofBedfordshire SJN - nonpreemptive - batch - indefinite postponement - minimiseaverage waitingIntroductionScheduling Priority scheduling - nonpreemptive - batch - indefinitepostponement - fast completion of important jobsProcess statusProcess control block SRT - Preemptive - batch - overhead from context switching - fastcompletion of short jobsMultithreadingProcess schedulingpoliciesProcess schedulingalgorithms32summary Round robin - Preemptive - interactive - requires selection of goodtime quantum - fair CPU allocation and reasonable response timesfor interactive users Multiple-level queues - Preemptive/nonpreemptive batch/interactive - overhead from monitoring queues - flexible,counteracts indefinite postponement with aging, fair treatment ofCPU-bound jobs by incrementing time quantums on lower priorityqueuesOperating Systems35

Lecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingsummaryProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems3335

Key TermsLecture #6 ProcessManagementDavid GoodwinUniversity ofBedfordshireIntroductionSchedulingProcess statusProcess control blockMultithreadingProcess schedulingpoliciesProcess schedulingalgorithmssummaryOperating Systems3435agingcontext switchingCPU-boundfirst come, first servedhigh-level schedulerIO-boundindefinite postponementinterruptinterrupt handlerjob schedulerjob statuslow-level schedulermiddle-level schedulermultiple-level queuesnatural wait

Key TermsLecture #6 ProcessManagementnonpreemptive scheduling policyDavid GoodwinUniversity ofBedfordshirepreemptive scheduling policypriority schedulingIntroductionprocessSchedulingProcess statusprocess control block (PCB)Process control blockMultithreadingprocess schedulerProcess schedulingpoliciesprocess scheduling algorithmprocess scheduling policyProcess schedulingalgorithmssummary35process statusround robinshortest job next (SJN)shortest remaining time (SRT)taskOperating Systemsthread35

Lecture #6: Process Management Written by David Goodwin based on the lecture series of Dr. Dayou Li and the book Understanding Operating Systems 4thed. by I.M.Flynn and A.McIver McHoes (2006) Department of Computer Science and Technology, University of Bedfordshire. Operating Systems, 2013 04th March 2013File Size: 1MB