You are on page 1of 36

Unit 2: Process Mgmt

UNIT 2
PROCESS MANAGEMENT: 8 HOURS

Chapters 3, 4 and 5 of TB1

DR. NEEPA SHAH 1

SYLLABUS CONTENT
 2.1 Process concept:
 Process Scheduling
 Operation on process
 Inter process communication
 2.2 Multithreaded Programming:
 Multithreading models
 Thread libraries
 Threading issues
 2.3 Process Scheduling:
 Basic concepts
 Scheduling algorithms
 Scheduling Criteria
 Thread scheduling
DR. NEEPA SHAH 2

Dr. Neepa Shah 1


Unit 2: Process Mgmt

PROCESS CONCEPT

 Program is passive entity stored on disk (executable file); process is active


 Program becomes process when an executable file is loaded into memory
 Execution of program started via GUI mouse clicks, command line entry of its name, etc.
 A dynamic instance of a computer program running on a computer
 The entity that can be assigned to and executed on a processor
 A unit of activity characterized by
 A single sequential thread of execution
 An associated set of system resources: memory image, open files, locks, etc.

DR. NEEPA SHAH 3

PROCESS CONCEPT CONTD.


 An operating system executes a variety of programs that run as a process.
 Process execution must progress in sequential fashion. No parallel execution of instructions of a single process
 Multiple parts
 The program code, also called text section
 Current activity including program counter, processor registers
 Stack containing temporary data
 Function parameters, return addresses, local variables

 Data section containing global variables


 Heap containing memory dynamically allocated during run time

DR. NEEPA SHAH 4

Dr. Neepa Shah 2


Unit 2: Process Mgmt

PROCESS IN MEMORY

 When a program is loaded into the


memory and it becomes a process,
it can be divided into four sections.

DR. NEEPA SHAH 5

MEMORY LAYOUT OF A C PROGRAM

DR. NEEPA SHAH 6

Dr. Neepa Shah 3


Unit 2: Process Mgmt

PROCESS STATE

 As a process executes, it changes state


 New: The process is being created
 Running: Instructions are being executed
 Waiting: The process is waiting for some event to occur
 Ready: The process is waiting to be assigned to a processor
 Terminated: The process has finished execution

DR. NEEPA SHAH 7

DIAGRAM OF PROCESS STATE

DR. NEEPA SHAH 8

Dr. Neepa Shah 4


Unit 2: Process Mgmt

PROCESS CONTROL BLOCK (PCB)

 A data structure maintained by the OS for every process for storing information associated with each process
(also called task control block)
 Identified by an integer process ID (PID).
 Keeps all the information needed to keep track of a process with the help of process attributes (also known
as Context of the process).
 Maintained for a process throughout its lifetime, and is deleted once the process terminates.

DR. NEEPA SHAH 9

PROCESS CONTROL BLOCK (PCB) CONTD.

 Process state – running, waiting, etc.


 Program counter – location of instruction to next execute
 CPU registers – contents of all process-centric registers
 CPU scheduling information- priorities, scheduling queue pointers
 Memory-management information – memory allocated to the process
 Accounting information – CPU used, clock time elapsed since start, time limits
 I/O status information – I/O devices allocated to process, list of open files

DR. NEEPA SHAH 10

10

Dr. Neepa Shah 5


Unit 2: Process Mgmt

PROCESS REPRESENTATION IN LINUX: DLL

Represented by the C structure task_struct

pid t_pid; /* process identifier */


long state; /* state of the process */
unsigned int time_slice /* scheduling information */
struct task_struct *parent; /* this process’s parent */
struct list_head children; /* this process’s children */
struct files_struct *files; /* list of open files */
struct mm_struct *mm; /* address space of this process */

DR. NEEPA SHAH 11

11

CONTEXT SWITCH

 When CPU switches to another process, the system must save the state of the old process and load
the saved state for the new process via a context switch
 Context of a process represented in the PCB
 Context-switch time is pure overhead; the system does no useful work while switching
 Time dependent on hardware support
 Some hardware provides multiple sets of registers per CPU ➔ multiple contexts loaded at once

DR. NEEPA SHAH 12

12

Dr. Neepa Shah 6


Unit 2: Process Mgmt

CPU SWITCH FROM PROCESS TO PROCESS

 A context switch occurs


when the CPU switches
from one process to
another.

DR. NEEPA SHAH 13

13

PROCESS SCHEDULING

 Objective of multiprogramming is to have some processes running all times, to


maximize CPU utilization
 Objective of time sharing is to switch the CPU among processes so frequently that
users can interact with each program while running
 Uniprocessor system can have only 1 running process. If more exists they have to
wait until CPU is free and can be rescheduled
 Process scheduler selects among available processes for next execution on CPU

DR. NEEPA SHAH 14

14

Dr. Neepa Shah 7


Unit 2: Process Mgmt

PROCESS SCHEDULING CONTD.

 Maintains scheduling queues of processes


 Job queue: set of all processes in the system
 Ready queue – set of all processes residing in main memory, ready and waiting to execute
 Generally stored as a linked list
 Ready queue header points to 1st and final PCBs in the list. Each PCB includes a pointer to next PCB in
ready queue
 Wait / Device queues – set of processes waiting for an event (i.e., I/O)
 Processes migrate among the various queues

DR. NEEPA SHAH 15

15

READY AND WAIT QUEUES

DR. NEEPA SHAH 16

16

Dr. Neepa Shah 8


Unit 2: Process Mgmt

REPRESENTATION OF PROCESS SCHEDULING: QUEUING DIAGRAM

DR. NEEPA SHAH 17

17

SCHEDULERS

 The CPU scheduler selects from among the processes in ready queue, and allocates a CPU core to one of them
 Queue may be ordered in various ways
 CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state (e.g., I/O request)
2. Switches from running to ready state (e.g., interrupt)
3. Switches from waiting to ready (completion of I/O)
4. Terminates
 For situations 1 and 4, there is no choice in terms of scheduling. A new process (if one exists in the ready queue) must
be selected for execution.
 For situations 2 and 3, however, there is a choice.

DR. NEEPA SHAH 18

18

Dr. Neepa Shah 9


Unit 2: Process Mgmt

PREEMPTIVE AND NONPREEMPTIVE SCHEDULING

 When scheduling takes place only under circumstances 1 and 4, the scheduling scheme is
nonpreemptive.
 Otherwise, it is preemptive.
 Non-preemptive: Once the CPU has been allocated to a process, the process keeps the CPU until it
releases it either by terminating or by switching to the waiting state.
 Preemptive: OS can force (preempt) a process from CPU at anytime to allocate CPU to another higher-priority
process
 Virtually all modern operating systems including Windows, MacOS, Linux, and UNIX use preemptive
scheduling algorithms.

DR. NEEPA SHAH 19

19

SCHEDULERS CONTD.

 Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates
CPU
 Sometimes the only scheduler in a system
 Short-term scheduler is invoked frequently (100 milliseconds)  (must be fast)
 Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue
 Long-term scheduler is invoked infrequently (seconds, minutes)  (may be slow)
 The long-term scheduler controls the degree of multiprogramming

DR. NEEPA SHAH 20

20

Dr. Neepa Shah 10


Unit 2: Process Mgmt

SCHEDULERS CONTD.

 Processes can be described as either:


 I/O-bound process – spends more time doing I/O than computations, many short CPU bursts
 CPU-bound process – spends more time doing computations; few very long CPU bursts
 Long-term scheduler strives for good process mix
 If all processes are I/O bound ready queue will be empty short term scheduler will have little to do
 If all processes are CPU bound, I/O waiting queue will almost always be empty, devices will go unused, system
will be unbalanced

DR. NEEPA SHAH 21

21

ADDITION OF MEDIUM TERM SCHEDULING

Medium-term scheduler
Removes partially executed processes from
memory (reduces the degree of
multiprogramming)
Some time later, these processes can be
reintroduced into memory and execution
can be continued from where it left off. This
scheme is called swapping. Process is
swapped-in/ out by medium term scheduler
Swapping may help to improve process mix
or if memory has to be freed up

DR. NEEPA SHAH 22

22

Dr. Neepa Shah 11


Unit 2: Process Mgmt

CPU - I/O BURST CYCLE

 Maximum CPU utilization obtained with multiprogramming


 CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution
and I/O wait
 CPU burst followed by I/O burst
 CPU burst distribution is of main concern

DR. NEEPA SHAH 23

23

DISPATCHER

 Dispatcher module gives control of the CPU to the


process selected by the CPU scheduler; this involves:
 Switching context
 Switching to user mode
 Jumping to the proper location in the user program to
restart that program
 Dispatcher should be as fast as possible, since it is
invoked during every process switch
 Dispatch latency – time it takes for the dispatcher to
stop one process and start another running

DR. NEEPA SHAH 24

24

Dr. Neepa Shah 12


Unit 2: Process Mgmt

SCHEDULING CRITERIA AND OPTIMIZATION

 CPU utilization – keep the CPU as busy as possible


 Throughput – # of processes that complete their execution per  Max CPU utilization
time unit
 Max throughput
 Turnaround time – amount of time to execute a particular
process  Min turnaround time
 Waiting time – amount of time a process has been waiting in the
ready queue
 Min waiting time
 Response time – amount of time it takes from when a request  Min response time
was submitted until the first response is produced.

DR. NEEPA SHAH 25

25

OPERATIONS ON PROCESSES

 System must provide mechanisms for:


 Process creation
 Process termination

DR. NEEPA SHAH 26

26

Dr. Neepa Shah 13


Unit 2: Process Mgmt

PROCESS CREATION

 Parent process create children processes, which, in turn create other processes, forming a tree of processes
 Resource sharing options
 Parent and children share all resources
 Children share subset of parent’s resources
 Parent and child share no resources
 Execution options
 Parent and children execute concurrently
 Parent waits until children terminate
 Address space
 Child duplicate of parent
 Child has a program loaded into it

DR. NEEPA SHAH 27

27

PROCESS TERMINATION

 Process executes last statement and then asks the operating system to delete it using the exit() system call.
 Returns status data from child to parent (via wait())
 Process’ resources are deallocated by operating system

 Parent may terminate the execution of children processes using the abort()/TerminateProcess()
system call. Some reasons for doing so:
 Child has exceeded allocated resources
 Task assigned to child is no longer required
 The parent is exiting, and the operating systems does not allow a child to continue if its parent terminates (Cascading
termination)

DR. NEEPA SHAH 28

28

Dr. Neepa Shah 14


Unit 2: Process Mgmt

INTERPROCESS COMMUNICATION

 Processes within a system may be independent or cooperating


 Cooperating process can affect or be affected by other processes, including sharing data
 Reasons for cooperating processes:
 Information sharing
 Computation speedup
 Modularity
 Convenience
 Cooperating processes need interprocess communication (IPC)
 Two models of IPC
 Shared memory
 Message passing

DR. NEEPA SHAH 29

29

COMMUNICATIONS MODELS
(a) Message passing (b) shared memory

DR. NEEPA SHAH 30

30

Dr. Neepa Shah 15


Unit 2: Process Mgmt

MANY OS IMPLEMENT BOTH MODELS

Message passing Shared Memory

 Allows maximum speed and convenience of


communication
 Useful for exchanging smaller amount of data  Faster than message passing
 Easier to implement than shared memory  System calls are required only to establish shared
 Implemented using system calls, hence require memory regions
more time consuming task of kernel intervention  Once shared memory is established, no assistance
from kernel is required (all accesses are treated as
routine memory accesses)

DR. NEEPA SHAH 31

31

2.2 MULTITHREADED PROGRAMMING:

MULTITHREADING MODELS
THREAD LIBRARIES
THREADING ISSUES

DR. NEEPA SHAH 32

32

Dr. Neepa Shah 16


Unit 2: Process Mgmt

MOTIVATION

 Most modern applications are multithreaded


 Threads run within application
 Process creation is heavy-weight while thread creation is light-weight
 Kernels are generally multithreaded
 Multiple tasks with the application can be implemented by separate threads
 Update display
 Fetch data
 Spell checking
 Answer a network request

DR. NEEPA SHAH 33

33

MOTIVATION CONTD.
 Web browser
 1 thread displays images/ text, another thread retrieves data from n/w
 Word processor
 Thread for displaying graphics, responding to keystrokes, performing spelling and grammar check in background
 Web server
 Several clients access it
 If server ran a traditional single threaded process, it would serve only 1 client at a time (increases wait time of client)
 Solution used before threads: every time server receives a request, it creates a separate process to service that request
which is very time consuming and resource intensive
 Hence create 1 process with multiple threads: When a request is made, thread will service the request and resume listening
for additional requests.

DR. NEEPA SHAH 34

34

Dr. Neepa Shah 17


Unit 2: Process Mgmt

SINGLE AND MULTITHREADED PROCESSES

DR. NEEPA SHAH 35

35

MULTITHREADED SERVER ARCHITECTURE

DR. NEEPA SHAH 36

36

Dr. Neepa Shah 18


Unit 2: Process Mgmt

BENEFITS
 Responsiveness
 Allows a program to continue even if a part is blocked
 Multithreaded browser allows user interaction in 1 thread while another loads an image
 Resource Sharing
 threads share memory and resources of process to which they belong easier than shared memory or message passing
 Economy
 In general, it is much more time consuming to create and manage processes than threads
 More economical to create and context switch threads
 Scalability
 Multithreading on a multi-CPU machine increases parallelism

DR. NEEPA SHAH 37

37

CONCURRENCY VS. PARALLELISM

 Concurrency supports more than one task making progress


 Single processor / core, scheduler providing concurrency

 Parallelism implies a system can perform more than one task simultaneously

DR. NEEPA SHAH 38

38

Dr. Neepa Shah 19


Unit 2: Process Mgmt

TYPES
 User-level thread
 Supported above kernel and implemented by thread library at user level
 No support from kernel as kernel is unaware
 Creation, scheduling, management is done in user space
 User level threads are fast to create and manage

 Kernel-Level Thread
 Supported directly by kernel (OS)
 Kernel performs Creation, scheduling, management in kernel space
 Slower to create and manage

DR. NEEPA SHAH 39

39

TYPES CONTD.

 Three primary user thread libraries:


 POSIX Pthreads
 Windows threads
 Java threads
 Kernel threads: virtually all general-purpose operating systems, including:
 Windows
 Linux
 Mac OS X
 iOS
 Android

DR. NEEPA SHAH 40

40

Dr. Neepa Shah 20


Unit 2: Process Mgmt

MULTITHREADING MODELS

 How user-level threads are mapped to kernel ones.


 Relationship must exists between user and kernel threads
 Many-to-One
 One-to-One
 Many-to-Many

DR. NEEPA SHAH 41

41

MANY-TO-ONE
 Many user-level threads mapped to single kernel thread
 One thread blocking causes all to block
 Multiple threads may not run in parallel on multicore system because only one may be in kernel at a time
 Thread management is done by the thread library in user space
 Few systems currently use this model
 Examples:
 Solaris Green Threads
 GNU Portable Threads

DR. NEEPA SHAH 42

42

Dr. Neepa Shah 21


Unit 2: Process Mgmt

ONE-TO-ONE

 Each user-level thread maps to kernel thread


 Creating a user-level thread creates a kernel thread
 More concurrency than many-to-one
 Number of threads per process sometimes restricted due to overhead (of creating kernel thread for every user-
level thread)
 Examples
 Windows
 Linux

DR. NEEPA SHAH 43

43

MANY-TO-MANY MODEL

 Allows many user level threads to be mapped to smaller or equal number of kernel threads
 Allows the operating system to create a sufficient number of kernel threads
 Windows with the ThreadFiber package

DR. NEEPA SHAH 44

44

Dr. Neepa Shah 22


Unit 2: Process Mgmt

TWO-LEVEL MODEL

 Similar to M:M, except that it allows a user thread to


be bound to kernel thread
 Examples
 IRIX
 HP-UX
 Tru64 UNIX
 Solaris 8 and earlier

DR. NEEPA SHAH 45

45

THREAD LIBRARIES

 Provides the programmer with API for creating and managing threads.
 2 ways of implementing thread library
1. Provide a library in user space with no kernel support.
1. All code and data structures for library exists in user space.
2. Invoking a function in the library results in a local function call in user space and not a system call.

2. Implement a kernel level library supported directly by OS.


1. All code and data structures for library exists in kernel space.
2. Invoking a function in the API for the library typically results in a system call.

DR. NEEPA SHAH 46

46

Dr. Neepa Shah 23


Unit 2: Process Mgmt

THREAD LIBRARIES CONTD.

 3 main thread libraries


 POSIX Pthreads
 Can be provided as user or kernel level library

 Win32
 Kernel level library on windows

 Java
 Allows threads to be created and managed in JAVA programs
 Since JVM runs on top of host OS, java thread API is implemented using thread library available on host system

DR. NEEPA SHAH 47

47

THREADING ISSUES

 After learning 1.2 (system calls)

DR. NEEPA SHAH 48

48

Dr. Neepa Shah 24


Unit 2: Process Mgmt

2.3 PROCESS SCHEDULING:


BASIC CONCEPTS
SCHEDULING ALGORITHMS
SCHEDULING CRITERIA
THREAD SCHEDULING

DR. NEEPA SHAH 49

49

SCHEDULING ALGORITHMS
1. First-Come, First-Served (FCFS) Scheduling (NP)
2. Shortest-Job-First (SJF) Scheduling / shortest next CPU burst (NP/P)
3. Priority Scheduling (P/NP)
4. Round Robin (RR) scheduling (P)
5. Multilevel Queue Scheduling P1 P2 P3 P1 P1
6. Multilevel Feedback Queue Scheduling 0
4 7 10 14 …….30
Turnaround time = Completion time – arrival time
Waiting time = turnaround time – burst time

DR. NEEPA SHAH 50

50

Dr. Neepa Shah 25


Unit 2: Process Mgmt

FIRST- COME, FIRST-SERVED (FCFS) SCHEDULING

Process Burst Time


P1 24
P2 3
P3 3
 Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:

P1 P2 P3
0 24 27 30

 Waiting time for P1 = 0; P2 = 24; P3 = 27


 Average waiting time: (0 + 24 + 27)/3 = 17

DR. NEEPA SHAH 51

51

FCFS SCHEDULING CONTD.

Suppose that the processes arrive in the order:


P2 , P3 , P1
 The Gantt chart for the schedule is:

P2 P3 P1
0 3 6 30

 Waiting time for P1 = 6;P2 = 0; P3 = 3


 Average waiting time: (6 + 0 + 3)/3 = 3
 Much better than previous case
 Convoy effect - short process behind long process

DR. NEEPA SHAH 52

52

Dr. Neepa Shah 26


Unit 2: Process Mgmt

SHORTEST-JOB-FIRST (SJF) SCHEDULING

 Associate with each process the length of its next CPU burst
 Use these lengths to schedule the process with the shortest time
 SJF is optimal – gives minimum average waiting time for a given set of processes
 Preemptive version called shortest-remaining-time-first
 How do we determine the length of the next CPU burst?
 Could ask the user
 Estimate

DR. NEEPA SHAH 53

53

EXAMPLE OF SJF

ProcessArrival Burst Time


P1 0.6
P2 2.8
P3 4.7
P4 5.3

P4 P1 P3 P2
 SJF scheduling chart
0 3 9 16 24

 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7

DR. NEEPA SHAH 54

54

Dr. Neepa Shah 27


Unit 2: Process Mgmt

EXAMPLE OF SHORTEST-REMAINING-TIME-FIRST
 Now we add the concepts of varying arrival times and preemption to the analysis
ProcessA arri Arrival TimeT Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
 Preemptive SJF Gantt Chart

P1 P2 P4 P1 P3
0 1 5 10 17 26

 Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec

DR. NEEPA SHAH 55

55

PRIORITY SCHEDULING

 A priority number (integer) is associated with each process

 The CPU is allocated to the process with the highest priority (smallest integer  highest priority)
 Preemptive
 Nonpreemptive

 SJF is priority scheduling where priority is the inverse of predicted next CPU burst time

 Problem  Starvation – low priority processes may never execute

 Solution  Aging – as time progresses increase the priority of the process (Priority Range: 127 (low) to 0 (high) )

DR. NEEPA SHAH 56

56

Dr. Neepa Shah 28


Unit 2: Process Mgmt

EXAMPLE OF PRIORITY SCHEDULING

ProcessA arri Burst TimeT Priority


P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2

 Priority scheduling Gantt Chart

 Average waiting time = 8.2

DR. NEEPA SHAH 57

57

ROUND ROBIN (RR)

 Each process gets a small unit of CPU time (time quantum q), usually 10-100 milliseconds. After this time has
elapsed, the process is preempted and added to the end of the ready queue.
 If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU
time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
 Timer interrupts every quantum to schedule next process
 Performance
 q large  FIFO
 q small  q must be large with respect to context switch, otherwise overhead is too high

DR. NEEPA SHAH 58

58

Dr. Neepa Shah 29


Unit 2: Process Mgmt

EXAMPLE OF RR WITH TIME QUANTUM = 4

Process Burst Time


P1 24
P2 3
P3 3
 The Gantt chart is:
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30

 Typically, higher average turnaround than SJF, but better response


 q should be large compared to context switch time
 q usually 10 milliseconds to 100 milliseconds,
 Context switch < 10 microseconds

DR. NEEPA SHAH 59

59

TIME QUANTUM AND CONTEXT SWITCH TIME

DR. NEEPA SHAH 60

60

Dr. Neepa Shah 30


Unit 2: Process Mgmt

PRIORITY SCHEDULING W/ ROUND-ROBIN

ProcessA arri Burst TimeT Priority


P1 4 3
P2 5 2
P3 8 2
P4 7 1
P5 3 3
 Run the process with the highest priority. Processes with the same priority run round-robin

 Gantt Chart with time quantum = 2

DR. NEEPA SHAH 62

62

MULTILEVEL QUEUE

 Ready queue is partitioned into separate queues, eg:


 foreground (interactive)
 background (batch)
 Processes are permanently assigned to 1 queue based on some property of process (memory size, priority, type)
 Each queue has its own scheduling algorithm:
 foreground – RR
 background – FCFS
 Scheduling must be done between the queues:
 Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation.
 Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in
RR and 20% to background in FCFS
DR. NEEPA SHAH 63

63

Dr. Neepa Shah 31


Unit 2: Process Mgmt

MULTILEVEL QUEUE CONTD.

 Prioritization based upon process type

DR. NEEPA SHAH 64

64

MULTILEVEL QUEUE CONTD.

 With priority scheduling, have


separate queues for each priority.
 Schedule the process in the highest-
priority queue!

DR. NEEPA SHAH 65

65

Dr. Neepa Shah 32


Unit 2: Process Mgmt

MULTILEVEL FEEDBACK QUEUE

 MQS has the advantage of low scheduling overhead, but it is inflexible (processes do not move from 1
queue to other, since they don’t change their nature)
 In MFQS, a process can move between the various queues.
 Multilevel-feedback-queue scheduler is defined by the following parameters:
 Number of queues
 Scheduling algorithms for each queue
 Method used to determine when to upgrade a process
 Method used to determine when to demote a process
 Method used to determine which queue a process will enter when that process needs service

DR. NEEPA SHAH 66

66

MULTILEVEL FEEDBACK QUEUE CONTD.

 If processes uses too much CPU time, it will be moved to lower priority queue
 I/O bound and interactive processes are in higher priority queues.
 Aging can be implemented using multilevel feedback queue
 Processes that waits for long in low priority queue may be moved to higher priority queue. This
form of aging prevents starvation

DR. NEEPA SHAH 67

67

Dr. Neepa Shah 33


Unit 2: Process Mgmt

MULTILEVEL FEEDBACK QUEUE CONTD.

 Scheduler will execute all processes in Q1 then Q2 and then Q3


 Process that arrives for Q2 will pre-empt a process in Q3. A
process in Q2 will be pre-empted by a process arriving for Q1

DR. NEEPA SHAH 68

68

MULTILEVEL FEEDBACK QUEUE: EXAMPLE

 Three queues:
 Q0 – RR with time quantum 8 milliseconds
 Q1 – RR time quantum 16 milliseconds
 Q2 – FCFS
 Scheduling
 A new process enters queue Q0 which is served in RR
 When it gains CPU, the process receives 8 milliseconds
 If it does not finish in 8 milliseconds, the process is moved to queue Q1

 At Q1 job is again served in RR and receives 16 additional milliseconds


 If it still does not complete, it is preempted and moved to queue Q2

DR. NEEPA SHAH 69

69

Dr. Neepa Shah 34


Unit 2: Process Mgmt

EXERCISE

• FCFS, SJF, RR (quantum: 1 milliseconds), NP Priority (low


number indicates higher priority)
• What is the turnaround time of each process for each of the
FCFS, SJF, RR (quantum: 10 milliseconds) scheduling algorithms?
• What is the waiting time of each process for each of these
scheduling algorithms?
• Which of the algorithms results in the minimum average
DR. NEEPA SHAH waiting time (over all processes)? 70

70

EXAMPLES: FCFS AND SJF

PROCESS BURST TIME


PROCESS ARRIVAL TIME BURST TIME
P1 8 P1 1 7
P2 3 P2 3 3
P3 5 P3 6 2
P4 3 P4 7 10
P5 9 8

DR. NEEPA SHAH 71

71

Dr. Neepa Shah 35


Unit 2: Process Mgmt

EXAMPLES: SRTF AND RR (TQ: 2)

PROCESS ARRIVAL TIME BURST TIME


P1 0 8 PROCESS BURST TIME
P2 1 4 P1 8
P3 2 2 P2 3
P4 3 1 P3 5
P5 4 3 P4 3
P6 5 2

DR. NEEPA SHAH 72

72

EXAMPLE: PRIORITY (NP AND P)

PROCESS PRIORITY BURST TIME ARRIVAL TIME


P1 2 1 0
P2 6 7 1
P3 3 3 2
P4 5 6 3
P5 4 5 4
P6 10 15 5
P7 9 8 6

DR. NEEPA SHAH 73

73

Dr. Neepa Shah 36

You might also like