0% found this document useful (0 votes)
3 views

Segment 2 (Operating System)

The document discusses processes and process management in operating systems, outlining the five-state model of processes and the types of process schedulers. It covers various CPU scheduling algorithms, including First Come, First Served, Shortest Job First, Round Robin, and Priority Scheduling, along with their advantages and disadvantages. Additionally, it addresses interprocess communication, context switching, and issues like starvation and aging in process scheduling.

Uploaded by

Jarin shova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Segment 2 (Operating System)

The document discusses processes and process management in operating systems, outlining the five-state model of processes and the types of process schedulers. It covers various CPU scheduling algorithms, including First Come, First Served, Shortest Job First, Round Robin, and Priority Scheduling, along with their advantages and disadvantages. Additionally, it addresses interprocess communication, context switching, and issues like starvation and aging in process scheduling.

Uploaded by

Jarin shova
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Chapter 2

Process

Mahmuda Haque Sweety


International Islamic University Chittagong
What is process?
A process is a program in execution.

What is process management?


The activities involved in managing the
execution of multiple processes in an
operating system
Layout of a process in memory:
Stack: The stack contains temporary data, such as function
parameters, returns addresses, and local variables.
Heap Section: Dynamically Memory to process during its run time
Data Section: Contains the global variable.
Text Section: The executable code
Five-state model:
New: The process is being created.
Running:Instructions are being executed.
Waiting: The process is waiting for some event to
occur (such as an I/O completion or reception of
signal).
Ready: The process is waiting to be assigned to a
processor
Terminated:The process has finished execution.
What is Process Scheduling

Process Scheduling is an OS task that schedules processes of


different states like ready, waiting, and running.

Type of Process Schedulers


There are mainly three types of Process Schedulers:
Long Term Scheduler:New to ready
Short Term Scheduler:ready To Running
Medium Term Scheduler: It is responsible for
suspending and resuming the process.

It mainly does swapping (moving


processes from main memory to disk
and vice versa)
Context switching:Context switching refers to a technique/method
used by the OS to switch processes from a given state to another one
for the execution of its function using the CPUs present in the system.
Interprocess Communication
1.Independent process
2.cooperating Process
IPC in Message-Passing Systems
 Naming
• send(P, message)—Send a message to process P.
• receive(Q, message)—Receive a message from process Q.
 Synchronization
• Blocking send. The sending process is blocked until the message is
received by the receiving process or by the mailbox.
• Nonblocking send. The sending process sends the message and
resumes operation.
• Blocking receive. The receiver blocks until a message is available.
• Nonblocking receive. The receiver retrieves either a valid message or a
null.
Buffering
Zero capacity: The queue has a maximum length of zero;

Bounded capacity: The queue has finite length n; thus, at most n

messages can reside in it .

Unbounded capacity: The queue’s length is potentially infinite; thus, any


number of messages can wait in it. The sender never
blocks.
Operations on Processes

Process Creation
Process Termination
• The child has exceeded its usage of some of the resources that it
has been allocated. (To determine whether this has occurred, the
parent must have a mechanism to inspect the state of its
children.)

• The task assigned to the child is no longer required.

• The parent is exiting, and the operating system does not allow a

child to continue if its parent terminates.


/* exit with status 1 */
exit(1);
**Parent may terminate the execution of children process using the abort()
system call.
** If a process terminates ,then all its childrfen must be terminated.This
problem is called Cascading Termination.

A parent process may wait for the termination of a child process by


using the wait() system call. The wait() system call is passed a
parameter that allows the parent to obtain the exit status of the
child. This system call also returns the process identifier of the
terminated child so that the parent can tell which of its children has
terminated:
pid t pid;
int status;
pid = wait(&status);

If no parent waiting (did not invoke wait()) process is a zombie


If parent terminated without invoking wait , process is an orphan
Communication in Client–Server Systems
 Sockets
 Remote Procedure Calls
 Pipes
 Remote Method Invocation (Java)
Sockets
Asocket is defined as an endpoint for communication
Communication using sockets
Remote Procedure Calls
Pipes
A pipe acts as a conduit allowing two processes to communicate. Pipes were
one of the first IPC mechanisms in early UNIX systems.
Ordinary Pipes:
Ordinary pipes allow two processes to communicate in standard producer–
consumer fashion: the producer writes to one end of the pipe (the write end)
and the consumer reads from the other end (the read end).
Named Pipes:
CPU Scheduling Algorithm
1.First Come, First Served (FCFS) Scheduling Algorithm
2. Shortest-Job-First (SJF) Scheduling Algorithm
i. Non-Preemptive SJF
ii. Preemptive SJF
3. Priority Scheduling Algorithm
i. Non-Preemptive Priority Scheduling Algorithm
ii. Preemptive Priority Scheduling Algorithm
4. Round Robin Scheduling Algorithm
5. Multilevel Queue Scheduling Algorithm
6. Multilevel Feedback Queue Scheduling Algorithm
CPU Scheduling Algorithm

 Burst Time (BT): The total time required by a process for


execution on the CPU.

 Arrival Time (AT): The time at which a process enters the ready
queue.

 Turnaround Time (TAT): The total time from process arrival to


completion (TAT = Completion Time - Arrival Time).

 Waiting Time (WT): The time a process spends waiting in the


ready queue (WT = Turnaround Time - Burst Time).
First-Come, First-Served Scheduling

The process which arrives first in the ready


queue is firstly assigned the CPU.
In case of a tie, process with smaller process
id is executed first.
It is always non-preemptive in nature.
First-Come, First-Served Scheduling
Process Id Arrival time Burst time
P1 3 4
P2 5 3
P3 0 2
P4 5 1
P5 4 3

0 2 3 7 10 13 14
p3 p1 p5 p2 p4
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time

Process Id Exit time Turn Around time Waiting time

P1 7 7–3=4 4–4=0

P2 13 13 – 5 = 8 8–3=5

P3 2 2–0=2 2–2=0

P4 14 14 – 5 = 9 9–1=8

P5 10 10 – 4 = 6 6–3=3
Advantages
It is simple and easy to understand.
It can be easily implemented using queue data structure.
It does not lead to starvation.

Disadvantages:
It does not consider the priority or burst time of the
processes.
It suffers from convoy effect
Shortest Job First:
• SJF Scheduling can be used in both preemptive and non-preemptive
mode.
• Preemptive mode of Shortest Job First is called as Shortest Remaining
Time First (SRTF).
• for n processes, time complexity = nlog(n)

• Critaria: Burst Time


Example of Shortest-remaining-time-first
 Now we add the concepts of varying arrival times and preemption to the
analysis
ProcessA arri Arrival TimeT Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
 Preemptive SJF Gantt Chart

P1 P2 P4 P1 P3
0 1 5 10 17 26

 Average waiting time = [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6.5 msec


Shortest Job First:
Preemptive mode of Shortest Job First is called as Shortest
Remaining Time First (SRTF); Mood : 1

0 1 2 3 4 5 6 7 8 9 10 11 12 13 16
p4 p2 p2 p1 p2 p2 p3 p3 p5 p5 p5 p4 p4 p4

0 1 3 4 6 8 11 16
p4 p2 p1 p2 p3 p5 p4
Shortest Job First:
Advantages
 SRTF is optimal and guarantees the minimum average waiting
time.
 It provides a standard for other algorithms since no other
algorithm performs better than it.

Disadvantages
 It can not be implemented practically since burst time of the
processes can not be known in advance.
 It leads to starvation for processes with larger burst time.
 Priorities can not be set for the processes.
 Processes with larger burst time have poor response time.
Round Robin Scheduling:

 CPU is assigned to the process on the basis of FCFS for


a fixed amount of time.
 This fixed amount of time is called as time quantum or
time slice.
 After the time quantum expires, the running process is
preempted and sent to the ready queue.
 Then, the processor is assigned to the next arrived
process.
 higher value of time quantum is better in terms of
number of context switch
 smaller value of time quantum is better in terms of
response time
Round-Robin Scheduling:
Process Id Arrival time Burst time
p1 0 4
p2 1 5
p3 2 2
p4 3 1
p5 4 6
p6 6 3

time quantum = 2 unit

Ready Queue:
P1, P2, P3, P1, P4, P5, P2, P6, P5, P2, P6, P5

0 2 4 6 8 9 11 13 15 17 18 19 21
p1 p2 p3 p1 p4 p5 p2 p6 p5 p2 p6 p5
Round Robin Scheduling:

Advantages

It gives the best performance in terms of average response time.


It is best suited for time sharing system, client server architecture and
interactive system.

Disadvantages
It leads to starvation for processes with larger burst time as they have
to repeat the cycle many times.
Its performance heavily depends on time quantum.
Priorities can not be set for the processes.
Priority Scheduling:
 Out of all the available processes, CPU is assigned to
the process having the highest priority.
 In case of a tie, it is broken by FCFS Scheduling.

 Priority Scheduling can be used in both preemptive


and non-preemptive mode.
 Priority scheduling in preemptive mode is best suited
for real time operating system.
Important Note:

The waiting time for the process having the highest priority
will always be zero in preemptive mode.

The waiting time for the process having the highest priority
may not be zero in non-preemptive mode.

Priority scheduling in preemptive and non-preemptive mode


behaves exactly same under following conditions

The arrival time of all the processes is same


All the processes become available
Priority Scheduling:

Higher number represents higher priority


Process Id Arrival time Burst time Priority

p1 0 4 2
p2 1 3 3
p3 2 1 4
p4 3 5 5
p5 4 2 5

0 4 9 11 12 15
p1 p4 p5 p3 p2
Priority Scheduling:
Advantages

It considers the priority of the processes and allows the


important processes to run first.
Priority scheduling in preemptive mode is best suited for
real time operating system.

Disadvantages

Processes with lesser priority may starve for CPU.


There is no idea of response time and waiting time.
Deterministic Evaluation:
 For each algorithm, calculate minimum average waiting time
 Simple and fast, but requires exact numbers for input, applies only to those
inputs

 FCS is 28ms:

Average waiting time: (0+10+39+42+49)/5= 28 ms

 Non-preemptive SFJ is 13ms:

Average waiting time: (10+32+0+3+20)/5= 13 ms


 RR is 23ms:(preemptive )

Average waiting time: (0+32+20+23+40)/5= 23 ms


Multilevel Queue Scheduling:

Another class of scheduling algorithms has been created for situations in which
processes are easily classified into different groups. For example, a common
division is made between foreground (interactive) processes and background
(batch) processes. A multilevel queue scheduling algorithm partitions the ready
queue into several separate queues .The processes are permanently assigned to
one queue, generally based on some property of the process, such as memory
size, process priority, or process type. Each queue has its own scheduling
algorithm.

For example, separate queues might be used for foreground and background
processes. The foreground queue might be scheduled by an RR algorithm, while
the background queue is scheduled by an FCFS algorithm.
Multilevel Queue Scheduling:
Problem called Starvation
Starvation
Starvation in operating system occurs when a process waits for an indefinite time to
get the resource it requires.

Solution of Starvation

A solution to the problem of starvation is aging. Aging is a technique of gradually


increasing the priority of processes that wait in the system for a long time.
Multilevel Feedback Queue Scheduling
Real-Time CPU Scheduling:
Two types of latencies affect the performance of real-time
systems:
1.Interrupt latency : time from arrival of interrupt to
start of routine that services interrupt
2.Dispatch latency –:time for schedule to take current
process off CPU and switch to another
Rate-Monotonic Scheduling
A priority is assigned based on the inverse of its period
Shorter periods = higher priority;
Longer periods = lower priority
P1 is assigned a higher priority than P2
Example:
p1 = 50 and p2 = 100.
The processing times are t1 = 20 for P1 and t2 = 35 for P2.
Missed Deadlines with Rate Monotonic Scheduling
Example:
p1 = 50 and p2 =80.
The processing times are t1 = 25 for P1 and t2 = 35 for
P2.
Earliest Deadline First Scheduling (EDF)
Priorities are assigned according to deadlines:

**The earlier the deadline, the higher the priority;


the later the deadline, the lower the priority
Example:
p1 = 50 and p2 =80.
The processing times are t1 = 25 for P1 and t2 = 35 for P2.

You might also like