Unit 2
Unit 2
• The former process moves from the Running state to the Not
Running state, and one of the other processes moves to the
Running state.
A Two-State Process Model
Process Termination
4. New: A process that has just been created but has not yet been
admitted to the pool of executable processes by the OS.
Memory tables are used to keep track of both main (real) and
secondary (virtual) memory. Some of main memory is reserved for
use by the OS; the remainder is available for use by processes.
I/O tables are used by the OS to manage the I/O devices and
channels of the computer system.
• At any given time, an I/O device may be available or assigned
to a particular process.
• If an I/O operation is in progress, the OS needs to know the
status of the I/O operation and the location in main memory
being used as the source or destination of the I/O transfer.
File tables.
• These tables provide information about the existence of files,
their location on secondary memory, their current status, and
other attributes.
Process Location
• A process must include a program or set of programs to be
executed.
• These programs have a set of data locations for local and
global variables and any defined constants.
• A process must consist of at least sufficient memory to hold
the programs and data of that process.
PROCESS DESCRIPTION
Process Attributes
1. Process identification:
Each process is assigned a unique numeric identifier, which may
simply be an index into the primary process table.
2. Processor state information:
• It consists of the contents of processor registers. While a
process is running the information is in the registers.
• When a process is interrupted, all of this register information is
saved so it can be restored when the process resumes
execution.
• All processor designs include a register or set of registers,
known as the program status word (PSW), that contains
status information.
3. Process control information:
This is the additional information needed by the OS to control
and coordinate the various active processes.
PROCESS CONTROL BLOCK
• The processes that are entering into the system are stored in
the Job Queue.
• First place a new process in the Ready queue and then it waits
in the ready queue till it is selected for execution.
Scheduling Queues
1. The process issue an I/O request, and then placed in the I/O
queue.
2. The process may create a new sub process and wait for
termination.
3. The process may be removed forcibly from the CPU, which
is an interrupt, and it is put back in the ready queue.
In the first two cases, the process switches from the waiting
state to the ready state, and then puts it back in the ready
queue.
Queuing Diagram representation of
Process Scheduling
Long-term scheduling
Medium-Term Scheduling
Short-Term Scheduling
• Processes which are in ready queue wait for CPU. A short term
scheduler chooses the process from ready queue and assigns
it to the CPU based on some policy.
• These policies can be First Come First Served (FCFS), Short Job
first (SJF), Priority based and Round Robin etc. Main objective
is increasing system performance by keeping the CPU busy.
• It is the transition of the process from Ready State to running
state. Actual allocation of process to CPU is done by
dispatcher.
• Short term scheduler is faster than long term scheduler and
should be invoked more frequently compared to long term
scheduler.
COMPARISON OF SCHEDULERS
TYPES OF SCHEDULING
There are two general categories:
• Non-preemptive:
In this case, once a process is in the Running state, it continues
to execute until
(a) it terminates or
(b) it blocks itself to wait for I/O or to request some OS service.
• Preemptive:
• The currently running process may be interrupted and
moved to the Ready state by the OS, i.e. control of GPU can
be taken from running process..
• The decision to preempt may be performed when a new
process arrives, when an interrupt occurs that places a
blocked process in the Ready state, or periodically, based on
a clock interrupt.
Preemptive vs. Non-preemptive
Draw the Gantt Chart and compute Average Waiting Time and
Average Completion Time.
Scheduling Algorithms: First-Come,
First-Served (FCFS)
* Example: Three processes arrive in order P1, P2, P3.
* P1 burst time: 24
* P2 burst time: 3
* P3 burst time: 3
* Waiting Time
* P1: 0 P1 P2 P3
* P2: 24 0 24 27 30
* P3: 27
* Completion Time:
* P1: 24
* P2: 27
* P3: 30
* Average Waiting Time: (0+24+27)/3 = 17
* Average Completion Time: (24+27+30)/3 = 27
Scheduling Algorithms: First-Come,
First-Served (FCFS)
1. Simple (+)
2. Short jobs get stuck behind long ones (-)
* If all you’re buying is milk, doesn’t it always seem like you
are stuck behind a cart full of many items
3. Performance is highly dependent on the order in which
jobs arrive (-)
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Shortest-Job-First Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
SCHEDULING ALGORITHMS
Priority Scheduling
Priority Scheduling(Summary)
* 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 (if a higher priority process enters, it receives the
CPU immediately)
* Non-preemptive (higher priority processes must wait until
the current process finishes; then, the highest priority ready
process is selected)
* SJF is a priority scheduling where priority is the predicted next
CPU burst time
* Problem ≡ Starvation – low priority processes may never
execute
* Solution ≡ Aging – as time progresses increase the priority of
the process
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Example of RR with Time Quantum = 4
0 4 7 10 14 18 22 26 30
Example of RR with Time Quantum = 4
Process Burst Time
P1 24
P2 3 P1 P2 P3 P1 P1 P1 P1 P1
P3 3 0 4 7 10 14 18 22 26 30
* Waiting Time:
* P1: (10-4) = 6
* P2: (4-0) = 4
* P3: (7-0) = 7
* Completion Time:
* P1: 30
* P2: 7
* P3: 10
* Average Waiting Time: (6 + 4 + 7)/3= 5.67
* Average Completion Time: (30+7+10)/3=15.67
Example of RR with Time Quantum = 4
Example of RR with Time Quantum = 20
* Waiting Time: A process can finish before the time quantum expires, and release the CPU.
* P1: (68-20)+(112-88) = 72
* P2: (20-0) = 20
* P3: (28-0)+(88-48)+(125-108) = 85
* P4: (48-0)+(108-68) = 88
* Completion Time:
* P1: 125
* P2: 28
* P3: 153
* P4: 112
* Average Waiting Time: (72+20+85+88)/4 = 66.25
* Average Completion Time: (125+28+153+112)/4 = 104.5
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Round Robin (RR) Scheduling
Threads
Threads
Single and Multithreaded Processes
Threads
Threads
Threads
Threads
Multithreading Models
Threads
User Level Threads
Disadvantages :
• There is a lack of coordination between threads and operating
system kernel.
Disadvantages:
* The kernel-level threads are slow and inefficient. For
instance, threads operations are hundred of times slower
than that of user-level threads.
* Since kernel must manage and schedule threads as well as
processes. It requires a full thread control block (TCB) for
each thread to maintain information about threads.
Multithreading Models
* Many-to-One
* One-to-One
* Many-to-Many
Many-to-One