Chapter-2
Chapter-2
Processes and
Process Management
Processes
• A process is a program in execution.
• All modern computers do many things at the
same time
• In a uni-processor system, at any instant, CPU
is running only one process
• But in a multiprogramming system, CPU
switches from processes quickly, running each
for tens or hundreds of ms
• Sometimes called pseudoparallelism since
one has the illusion of parallel processor.
The process model
Even though in actuality there are many
processes running at once, the OS gives each
process the illusion that it is running alone.
(a) Virtual time – the time used by just this
processes.
(b) Virtual memory – the memory as viewed by the
processes.
• System initialization.
• Execution of a process creation system call
by a running process.
• A user request to create a new process.
• Initiation of a batch job.
Process Termination
• Non-preemptive
– Picks a process to run and then lets it run
till it blocks or it voluntarily releases the
CPU
Categories of Scheduling Algorithms
• First-come first-served
• Shortest job first
• Shortest Remaining Time
Next
Scheduling in Batch Systems
• First-Come First-Served
– Non-preemptive
– The CPU is assigned in the order processes required
– When the running process blocks the following one in the queue is
selected
– When a blocked process becomes ready it is put on the end of the
queue.
– Not optimal
• Shortest Job First
– Non-preemptive
– Suppose we know the run-time in advance
– The CPU is assigned to the shortest job in the queue
– Optimal if all the jobs are available at the same time.
• Shortest Remaining Time Next
– Preemptive
– The scheduler here chooses the process whose remaining run-time
is the shortest.
– The time has to be known in advance
– New short jobs get good service
First-come-first-served (FCFS)
scheduling
▪ Processes get the CPU in the order
they request it and run until they
release it
P1 24
P2 3
P3 3
If they arrive in the order P1, P2, P3, we get:
P1 P2 P3
0 24 27 30
P2 P3 P1
0 3 6 30
Average waiting (0+3+6) / 3 = 3
time:
Shortest Job First (SJF) scheduling
❑ The CPU is assigned to the process that has the smallest
next CPU burst
❑ In some cases, this quantity is known or can be
approximated
Process Burst time (milli)
A 5
B 2
C 4
D 1
• Round-robin scheduling
• Priority scheduling
Round Robin
❑ Each process gets a small unit of CPU time
(time-quantum), usually 10-100 milliseconds
❑ For n ready processes and time-quantum q,
no process waits more than (n - 1)q
❑ Approaches FCFS when q grows
❑ Time-quantum ~ switching time
relatively large waste of CPU time
❑ Time-quantum >> switching time
long response (waiting) times, FCFS
Example: RR with Time Quantum = 20
• Arrival time = 0
• Time quantum =20 Process Burst Time
P1 53
P2 17
P3 68
p4 24
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97117121134154162
• Typically, higher average turnaround than SJF, but better
response
Size of time quantum
2 P5 P1 3 4
0 1 6 16 18 19
• Average waiting time
= (6 + 0 + 16 + 18 + 1) /5 = 8.2
Introduction To Deadlocks