Process Concept Process Concept (Cont.) : Processes Processes Processes Processes
Process Concept Process Concept (Cont.) : Processes Processes Processes Processes
Process Concept
Process Concept
(cont.)
• An operating system • Process – a program in
executes a variety of execution; process execution
programs: must progress in sequential
– Batch system – jobs
fashion
– Time-shared systems – user • A process includes:
programs or tasks – program counter
• Textbook uses the terms job – stack
and process almost – data section
interchangeably
3 4
5 6
1
Diagram of Process Process Control Block
State (PCB)
Info. associated with each process
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information
7 8
9 10
11 12
2
Process Creation Process Creation
(cont.) (cont.)
• Resource sharing • Execution
– Parent and children share all – Parent and children execute
resources concurrently
– Children share subset of parent’s – Parent waits until children
resources terminate
– Parent and child share no
resources
13 14
Processes Tree on
a UNIX System Process Termination
• Process executes last statement
and asks the operating system
to decide it (exit
exit)
exit
– Output data from child to parent
(via wait)
wait
– Process’ resources are
deallocated by operating system
• Parent may terminate execution
of children processes (abort
abort)
abort
17 18
3
Process Termination Relation Bet.
(cont.) Processes
– Child has exceeded allocated • Independent process cannot
resources affect or be affected by the
– Task assigned to child is no execution of another process
longer required
• Cooperating process can affect
– If parent is exiting
or be affected by the execution
• Some operating system do not allow
child to continue if its parent of another process
terminates
– All children terminated - cascading
termination
19 20
Multiple Threads
Threads (Cont.)
within a Task
• In a multiple threaded task,
while one server thread is
blocked and waiting, a
second thread in the same
task can run.
23 24
4
Process Scheduling Process Scheduling
Queues Queues (cont.)
• Job queue – set of all • Device queues – set of
processes in the system processes waiting for an I/O
• Ready queue – set of all device
processes residing in main • Process migration between the
memory, ready and waiting to various queues
execute
25 26
27 28
Addition of Medium
Schedulers
Term Scheduling
5
Schedulers (Cont.) Schedulers (cont.)
• Short-term scheduler is invoked • Processes can be described as
very frequently (milliseconds) either:
⇒ (must be fast) – I/O-bound process – spends more
• Long-term scheduler is invoked time doing I/O than computations,
many short CPU bursts
very infrequently (seconds,
minutes) ⇒ (may be slow) – CPU-bound process – spends more
time doing computations; few very
• The long-term scheduler long CPU bursts
controls the degree of
multiprogramming
31 32
CPU Scheduling
Basic Concepts
(cont.)
• Thread Scheduling
• Operating Systems Examples • Maximum CPU utilization
obtained with multiprogramming
• Java Thread Scheduling
• CPU–I/O Burst Cycle – Process
• Algorithm Evaluation execution consists of a cycle
of CPU execution and I/O wait
• CPU burst distribution
35 36
6
Alternating Sequence of
CPU And I/O Bursts CPU Scheduler
• Selects from among the
processes in memory that are
ready to execute, and allocates
the CPU to one of them
37 38
39 40
7
Scheduling Criteria
Scheduling Criteria
(cont.)
• Waiting time – amount of time a
• CPU utilization – keep the process has been waiting in the
CPU as busy as possible ready queue
• Throughput – # of processes • Response time – amount of time
that complete their it takes from when a request
was submitted until the first
execution per time unit
response is produced, not
• Turnaround time – amount of output (for time-sharing
time to execute a environment)
particular process
43 44
First-Come, First-Served
Optimization Criteria (FCFS) Scheduling
ProcessBurst Time
• Max CPU utilization
P1 24
• Max throughput
P2 3
• Min turnaround time P3 3
• Min waiting time • Suppose that the processes
• Min response time arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule
is:
P1 P2 P3
0 24 27 30
45 46
0 3 6 30
47 48
8
FCFS Scheduling Shortest-Job-First
(Cont.) (SJR) Scheduling
• Waiting time for P1 = 6; P2 = 0; • Associate with each process the
P3 = 3 length of its next CPU burst.
• Average waiting time: (6 + 0 Use these lengths to schedule
+ 3)/3 = 3 the process with the shortest
• Much better than previous case time
• Convoy effect short process
behind long process
49 50
Shortest-Job-First Shortest-Job-First
(SJR) Scheduling (SJR) Scheduling
(cont.) (cont.)
• Two schemes:
– preemptive – if a new process
– nonpreemptive – once CPU given to arrives with CPU burst length
the process it cannot be less than remaining time of
preempted until completes its CPU current executing process,
burst preempt. This scheme is know as
the
Shortest-Remaining-Time-First
(SRTF)
• SJF is optimal – gives minimum
average waiting time for a
given set of processes
51 52
Example of Non-
Example of Non-
Preemptive SJF
Preemptive SJF
(cont.)
ProcessArrival Time Burst Time
P1 0.0 7 • SJF (non-preemptive)
P2 2.0 4
P1 P3 P2 P4
P3 4.0 1
P4 5.0 4 0 3 7 8 12 16
53 54
9
Example of Preemptive Example of Preemptive
SJF SJF (cont.)
ProcessArrival Time Burst Time
P1 0.0 7 • SJF (preemptive)
P2 2.0 4
P1 P2 P3 P2 P4 P1
P3 4.0 1
0 2 4 5 7 11 16
P4 5.0 4
55 56
Examples of Examples of
Exponential Averaging Exponential Averaging
(cont.)
• α =0
– τn+1 = τn • If we expand the formula, we
– Recent history does not count get:
τn+1 = α tn+(1 - α) α tn -1 + …
• α =1 +(1 - α )j α tn -1 + …
– τn+1 = tn +(1 - α )n=1 tn τ0
– Only the actual last CPU burst
• Since both α and (1 - α) are
counts
less than or equal to 1, each
successive term has less weight
59
than its predecessor 60
10
Priority Scheduling
Priority Scheduling
(cont.)
• A priority number (integer) is • SJF is a priority scheduling
associated with each process where priority is the predicted
next CPU burst time
• The CPU is allocated to the
process with the highest • Problem ≡ Starvation – low
priority processes may never
priority (smallest integer ≡ execute
highest priority)
• Solution ≡ Aging – as time
– Preemptive progresses increase the
– nonpreemptive priority of the process
61 62
65 66
11
Time Quantum and Context Turnaround Time Varies
Switch Time With The Time Quantum
67 68
Multilevel Queue
Multilevel Queue
(cont.)
• Ready queue is partitioned into • Scheduling must be done between
separate queues: the queues
foreground (interactive) – Fixed priority scheduling; (i.e.,
background (batch) serve all from foreground then from
background). Possibility of
• Each queue has its own starvation.
scheduling algorithm – Time slice – each queue gets a
– foreground – RR certain amount of CPU time which it
– background – FCFS can schedule amongst its processes;
i.e., 80% to foreground in RR
69 – 20% to background in FCFS 70
71 72
12
Multilevel Feedback Example of Multilevel
Queue (cont.) Feedback Queue
– number of queues • Three queues:
– scheduling algorithms for each – Q0 – time quantum 8 milliseconds
queue – Q1 – time quantum 16 milliseconds
– method used to determine when to – Q2 – FCFS
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
73 74
Multiple-Processor
Real-Time Scheduling
Scheduling
• CPU scheduling more complex when • Hard real-time systems –
multiple CPUs are available required to complete a critical
• Homogeneous processors within a task within a guaranteed amount
multiprocessor of time
• Load sharing • Soft real-time computing –
• Asymmetric multiprocessing – requires that critical
only one processor accesses the processes receive priority over
system data structures, less fortunate ones
alleviating the need for data
77 78
sharing
13