Process Management - Scheduling
Process Management - Scheduling
Process Management - Scheduling
File Systems
Security
Networking
What is a Process?
An executable (active)program
Associated data needed by the program
Execution context of the program
Allinformation the operating system needs to
manage the process (memory contents,
register values, internal representation …etc)
3
What is a Process?
The process is the unit of work in an OS.
System processes are created by the OS to
perform tasks on the user’s or system’s
behalf.
User processes are created more directly by
the user’s actions. They include application
programs and system utilities.
Process versus Program
A program is static
just a bunch of bytes
A process is dynamic
transitions between different states.
No one-to-one mapping between Program
and Process
What is in a Process?
As a process
executes, it moves
from state to state
Process is
preempted
Process State
Process is
Running: currently Process makes a scheduled
request that cannot be
being executed immediately satisfied
on the CPU
8
Process Operations
Create/terminate process
Set/get process parameters
Block process
Awaken process
Switch process
Schedule process
9
Process Table
Used by the OS to manage processes
One entry for each process
Typical contents in a process table entry:
Saved registers
Process state Called
Process ID PCB
Owner/group ID “Process
Control Block”
Priority
Memory usage
Open files
Cumulative running time
10
Processes
I/O Bound processes
CPU Bound processes
Threads
Created when we allow more than one locus of
control in a single memory space
Called (LWP: light weight processes or Threads)
12
Scheduling
Scheduling
14
Criteria for good Scheduling
algorithm
Fairness
Efficiency
Response time
Turnaround time
Throughput
Scheduling algorithms
Preemptive scheduling: allows
logically runnable processes to be
temporarily suspended
Nonpreemptive scheduling: classic
batch systems, run to completion
Terminology
Waiting time
Burst time
Turnaround time
Average turnaround time
Weighted turnaround time
Average weighted turnaround time
First Come, First Served (FCFS)
Batch scheduling technique
Jobs processed in the order they arrived
Implemented with a queue
Disadvantage:
Long jobs introduce large delays until short
jobs are executed.
i.e. overall average time to wait is affected by the
order in which jobs/processes arrive.
18
Example
Shortest Job First (SJF)
Batch scheduling technique
Process jobs in increasing order of running
time
Optimal: minimizes average turnaround time
Requires knowledge of running time
20
Shortest Remaining Time Next
(SRTN)
Preemptive SJF.
The process in the ready queue with the shortest
execution time is chosen to execute.
New process with run time less than the
remaining time of the current process preempt.
Round-Robin
Time-sharing analog of FCFS
Processes taken in turn
Processes given a time slice (called quantum),
then pre-empted
Time slice ~ 0.1-0.01 seconds
Implemented with a circular queue
22
Example (FCFS vs RR)
Example
10 jobs and each takes 100 seconds
FCFS (non-preemptive scheduling)
job 1: 100s, job2: 200s, ... , job10: 1000s
Round Robin (preemptive scheduling)
time slice 1sec and no overhead
job1: 991s, job2: 992s, ... , job10: 1000s
Comparisons
Round robin is much worse (turnaround time) for jobs about the
same length
Round robin is better for short jobs and different length jobs
Priority Scheduling
Each process has priority
Often give preference to interactive processes over compute-
bound processes
Or associate specific user processes with priorities
Or e.g. microkernel design (OS processes have highest priority)
Process with the highest priority is selected
24
Multilevel Feedback Queue
A technique for implementing dynamic
priorities
One queue per priority level
Processes can be boosted to higher
priority
E.g. when they are blocked for sometime
Processes move to lower priority queues at
the end of time slices
25
Multilevel Feedback Queue
(cont.)
26
Priority Inversion
Occurs with Static Priorities.
When a high priority process is waiting on a low priority
process that is starved by a medium priority process.
Example:
Processes a (3), b (5), c (7)
c is waiting on a
a is waiting on b
b is compute-bound and never blocks
Process a does not have a chance to run
Process c will not have a chance to run either although its
priority is 7!! as if b is higher than c
Dynamic priority
Solves Priority Inversion directly
Involves temporarily raising the priority of a
process if a higher priority process blocks
waiting on it.
Example:
Change priority of a to 7
Process b cannot starve a
a completes task
Thus c completes task
Return priority of a to 3
Scheduling Parameters
Quantum is the length of a time slice
Longer quanta give more run time
In some OSs, lower priority levels had
longer quanta
longer quanta for “foreground” process
In some OSs I/O Bound process gets
higher priority.
29
Two-Level Scheduling
When a new process is allocated & there is not enough
memory
write the memory of a process (that has not run in a long time)
to the disk.
When it is scheduled,
read it and write another one to disk
With Round Robin,
The scheduled process will always be the one on the disk
This is called Thrashing
Solution: two levels of scheduling
Long term: decide which processes are resident in memory
Short term: decide next process to run among only those in
memory
30
Context Switching
Reassigning CPU among competing processes
rapid enough that we have the illusion that they
run simultaneously.
31
Context Switching
Give CPU to another process:
32
Context Switching (cont.)
33
Process Creation
Fork creates copy of parent
Execv produces a process running new
program
Mechanism:
Createnew process table entry
Copy parent memory (fork)
Load new program (for execv)
34
Process Termination
Initiated by ending process or another
process
Mechanism:
Close open files
Reduce reference count on shared resources
Free nonshared memory
Send exit status to parent (or other waiting
process)
35