Lecture 3 Processes
Lecture 3 Processes
Systems
MUGOYA SHARIFF
Email: [email protected]
Outline
Process states
Control block
Scheduling
Co-operating processes
Synchronization
04/29/2025 10:52 AM MU@KU 2
Process
• A program in execution is called a process
• It is an instance of a program that actually runs
• Two essential process elements are program code and a set
of data associated with that code.
• Process memory is divided into four sections:
• The program memory stores the compiled program code, read
in from non-volatile storage when the program is launched.
• The data section stores global and static variables, allocated
and initialized before executing the main program.
• The heap section is used to manage dynamic memory
allocation inside our program. In other words, it is the portion
of memory where dynamically allocated memory resides i.e.,
memory allocation via new or malloc and memory deallocation
via delete or free, etc.
• The stack section stores local variables defined inside our
program or function. Stack space is created for local variables
when declared, and the space is freed up when they go out of
scope.
04/29/2025 10:52 AM MU@KU 3
Process …
• Process Management: The operating system is responsible for
the following activities in connection with process management:
the creation and deletion of both user and system processes;
the scheduling of processes; and the provision of mechanisms
for synchronization, communication, and deadlock handling for
processes.
• Process, on the other hand, includes:
• Current value of Program Counter (PC)
• Contents of the processors registers
• Value of the variables
• The processes stack (SP) which typically contains temporary data
such as subroutine parameter, return address, and temporary
variables.
• A data section that contains global variables
04/29/2025 10:52 AM MU@KU 4
Process Control Block
• Each process is represented in the operating system by
a process control block (PCS)—also called a task control
block.Process state
process number
program counter
Registers
memory limits
list of open files
.
.
• Try this Qn: Suppose we use the example above but with the processes
arrived in the order P2, P3, P1. What is the average waiting time?
• The processes coming at P2, P3, P1 the average waiting time (6 + 0 + 3)/3 = 3
milliseconds whereas the processes are came in the order P1, P2, P3 the average
waiting time is 17 milliseconds
04/29/2025 10:52 AM MU@KU 17
Shortest-Job-First Scheduling (SJF)
• SJF algorithm is defined as • Example: Consider the
“when the CPU is available, it following processes and CPU
is assigned to the process burst in milliseconds:
that has the smallest next Process Burst Time
CPU burst”. If the next CPU
bursts of two processes are P1 6
the same, FCFS scheduling is
P2 8
used between two processes.
P3 7
• SJF is also called as Shortest-
Next CPU-Burst algorithm, P4 3
because scheduling depends
on the length of the next CPU
burst of a process, rather • Gantt Chart of SJF algorithm:
than its total length.
04/29/2025 10:52 AM MU@KU 18
SJF …ctd
Waiting Time for Processes:
• By looking at the above table the average waiting
Process Burst Time (ms) Waiting Time
time by using SJF algorithm is 7ms.
• SJF gives the minimum average waiting time for a P1 6 3
given set of processes. SJF is optimal.
• The average waiting time decreases because moving
P2 8 16
a short process before long process decrease the P3 7 9
waiting time of the short process more than it
increases the waiting time of the long process.
P4 3 0
Difficulty with SJF Average Waiting Time 7ms
• The difficulty with the SJF algorithm is ―knowing the
length of the next CPU request‖. With Short-Term
Scheduling, there is no way to know the length of the
next CPU burst. It is not implemented practically.
• tn be the length of the nth CPU burst (i.e. contains the most recent information).
• stores the past history.
• be our predicted value for the next CPU burst.
• α controls the relative weight of recent and past history in our prediction (0 ≤ α ≤1)
• If α=0, then , recent history has no effect
• If α=1 then , only the most recent CPU burst matters.
• If α = 1/2, so recent history and past history are equally weighted