0% found this document useful (0 votes)
7 views30 pages

Lecture 2-Processes Management

The document covers key concepts in process management and CPU scheduling within operating systems, including the process lifecycle, context switching, and various CPU scheduling algorithms such as FCFS, SJF, and Round Robin. It explains the differences between processes and threads, detailing user-level and kernel-level threads, as well as the significance of the Process Control Block (PCB) in managing process information. Additionally, it includes activities and case studies to illustrate scheduling scenarios and the impact of different algorithms on process performance.

Uploaded by

piyushmishra1049
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)
7 views30 pages

Lecture 2-Processes Management

The document covers key concepts in process management and CPU scheduling within operating systems, including the process lifecycle, context switching, and various CPU scheduling algorithms such as FCFS, SJF, and Round Robin. It explains the differences between processes and threads, detailing user-level and kernel-level threads, as well as the significance of the Process Control Block (PCB) in managing process information. Additionally, it includes activities and case studies to illustrate scheduling scenarios and the impact of different algorithms on process performance.

Uploaded by

piyushmishra1049
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

Lecture-2

Process Management & CPU Books


Scheduling
Operating System Concepts
Core Topics: Ninth Edition
 Process Lifecycle Avi Silberschatz Peter Baer Galvin Greg Gagne

 Context Switching, PCB, Threads (User vs Kernel) Operating Systems: Internals and Design
Principles
 CPU Scheduling Algorithms (FCFS, SJF, Priority, Round William Stallings
Robin, Multilevel)
What is Processes?

A process is a program in
execution.
Process in Memory and Operations

Used for local


variables

Used for dynamic


memory
allocation, and is
managed via calls

Stores global and static


variables, allocated and
initialized prior to executing
main.

comprises the
compiled program
code
Process Life Cycle (Process States)
Process Life Cycle (Process States)
Process Control Block (PCB)
Information associated with each process

(also called task control block)

• Process state – running, waiting, etc

• Program counter – location of instruction to next execute

• CPU registers – contents of all process-centric registers

• CPU scheduling information- priorities, scheduling queue pointers

• Memory-management information – memory allocated to the process

• Accounting information – CPU used, clock time elapsed since start, time limits

• I/O status information – I/O devices allocated to process, list of open files
Thread

 Despite of fact that a thread must execute in processes, the processes and its associated threads are different
concept.

 Process are used to group resources together and threads are the entities scheduled for execution on the
CPU.

 A thread is a single sequence stream within in a process. Because threads have some of the properties of
processes, they are sometime called light weight processes.

 In a process, threads allows multiple executions of streams. In many respect, threads are popular way to
improve application through parallelism.

 The CPU switches rapidly back and forth among the threads giving illusion that the threads are running in
parallel.
Processes Vs Thread
Types of Threads

User-Level Thread
 The user-level threads are managed by users and the kernel is not aware of it.
 These threads are faster to create and manage.
 The kernel manages them as if it was a single-threaded process.
 It is implemented using user-level libraries and not by system calls. So, no call to the operating system is
made when a thread switches the context.
 Each process has its own private thread table to keep the track of the threads.
Kernel-Level Thread
 The kernel knows about the thread and is supported by the OS.
 The threads are created and implemented using system calls.
 The thread table is not present here for each process. The kernel has a thread table to keep the track of all
the threads present in the system.
 Kernel-level threads are slower to create and manage as compared to user-level threads.
Context Switching

• CPU Switch
From
Process to
Process
What is CPU Scheduling in OS?
CPU Scheduling or Process scheduling
CPU Scheduling Terminology

 CPU utilization – keep the CPU as busy as possible

 Throughput – # of processes that complete their execution per time unit

 Burst time/ execution time/ running time: is the time process require for running on CPU

 Waiting time: time spend by a process in ready state waiting for CPU

 Arrival time: when a process enter the ready state

 Exit time: when process completes execution and exit from system

 Turn around time: total time spend by a process in the system

 TAT = ET – AT or BT + WT

 Response time: Time between a process enter ready queue and get scheduled on the CPU for the first time
Scheduling Algorithm Optimization Criteria
Activity Slow Learner

Scenario: 1
Imagine a computer system running a multi-programmed operating system. Three processes – P1, P2, and P3
– are loaded into memory.
P1 has just been created and is ready to run.
P2 is currently using the CPU.
P3 has requested input from the keyboard and is waiting for it.
After a few seconds:
•P2 finishes its time slice and is moved back to the ready queue.
•The OS selects P1 to run on the CPU.
•Meanwhile, the keyboard input requested by P3 is received, and it moves to the ready queue.
Activity Slow Learner

Case Study Questions:

 What is the current state of P1, P2, and P3 at the beginning of the scenario?

 What causes P2 to leave the CPU and move to the Ready state?

 Why is P3 in the Waiting state initially?

 After the keyboard input is received, what is the new state of P3?

 Describe the state transitions for P1 in this scenario.


Activity Slow Learner (MCQs)
Q1. Which process state indicates the process is next process selected to run?
waiting for an event such as I/O completion? A. Random selection
A. Running B. User request
B. Ready C. Scheduler algorithm
C. Waiting D. Manual execution
D. Terminated Q5. What is the final state of a process after it
Q2. What does the OS do when a process finishes its completes its execution?
time slice? A. Waiting
A. Terminates the process B. Ready
B. Moves it to the waiting queue C. Terminated
C. Moves it to the ready queue D. Running
D. Restarts the process
Q3. What triggers a process to move from the Waiting
state to the Ready state?
A. Completion of I/O or the awaited event
B. Expiration of time slice
C. Arrival of new process
D. Process crash
Q4. In a preemptive multitasking system, how is the
Activity Slow Learner (Story-Based Scenario)

A toy factory has one machine that makes toys. Four toy orders (like processes)
arrive at different times and take different amounts of time to finish.
Time to Finish (Burst
Order (Process) Arrival Time (in mins)
Time)
O1 0 5
O2 1 3
O3 2 8
O4 3 6

The manager must decide which order to process first. They can use different
scheduling rules.
Activity Slow Learner
Simple Scheduling Algorithms
Analysis Questions (With Support Prompts)
Explained:
1. Using FCFS, what is the order of processing?
 FCFS (First Come First Serve): Serve the
2. Which order will finish first in SJF?
order that came first.
3. In Round Robin (Time Slice = 2 mins), which order gets the
 SJF (Shortest Job First): Finish the order that
CPU again after the first round? (Hint: Go around in circles.)
takes the least time.
4. What happens if one order always has a higher priority than the
 RR (Round Robin): Give each order a chance
others? (Hint: Will the others ever get processed?)
for 2 minutes, then rotate.
5. Which algorithm is fairest to all orders? (Hint: Think about
 Priority Scheduling: Orders are given a rank.
equal turns.)
Higher priority goes first
Activity Slow Learner(Simple Multiple-Choice Quiz)

Q1. What does FCFS stand for? D. Random time


A. Fastest CPU First
Q4. In a factory with only one machine (CPU), how
B. First Come First Serve
many orders can be "running" at one time?
C. Finish CPU Fast
A. 2
D. First CPU Service
B. 4
Q2. In SJF, which order is chosen? C. 1
A. The biggest D. All
B. The one with the shortest time
Q5. What problem happens if we always choose
C. The one with highest number
highest priority only?
D. The last one
A. Everyone is happy
Q3. Round Robin gives each process: B. Some orders may starve
A. No time C. It runs faster
B. One chance only D. The machine breaks
C. Equal time slices
Activity Moderate Learner (Case study)
Scenario:2

A modern multitasking operating system is managing four processes: P1, P2, P3, and P4. The system uses a
preemptive priority-based CPU scheduling algorithm, where a lower number indicates higher priority.
•P1 (Priority: 2) is in the Ready queue. P2 (Priority: 1) is Running on the CPU. P3 (Priority: 3) is in the
Waiting state for disk I/O. P4 (Priority: 1) is New and just admitted into memory.
The following events occur:
 P2 initiates a file read operation and enters the Waiting state.
 The scheduler now chooses the highest priority process from the Ready queue.
 P4 finishes loading and enters the Ready queue.
 The disk I/O for P3 completes, and it is moved to the Ready queue.
 After some time, P4 completes execution and terminates.
Case Study Analysis Questions

1. After P2 initiates the file read, which process is selected next by the scheduler? Why?

2. What happens when P4 moves from New to Ready? How does it affect scheduling?

3. When P3 completes I/O and returns to the Ready state, is it selected to run

immediately? Justify your answer using priority levels.

4. What is the complete life cycle path (states) that P2 follows in this scenario?

5. Why does P4 terminate without entering the Waiting state? What does this imply

about its execution?


Activity Moderate Learner (MCQs Asked in Placement Drives)
Q1. In a preemptive priority-based scheduling system, which factor B. It can be scheduled for CPU

must the OS consider when selecting the next process? C. It has not yet been admitted to the Ready queue

A. I/O burst time D. It is waiting for memory deallocation

B. Process priority
Q4. Why does a process enter the Terminated state?
C. Process age
A. After being idle too long
D. Parent-child relationship
B. Due to preemption

Q2. What causes a context switch between two processes in the C. After successful or abnormal completion

scenario above? D. If it is moved to the Ready queue

A. Process termination
Q5. Which of the following best describes the difference between
B. A higher-priority process entering the Ready queue
Ready and Waiting states?
C. Manual user interruption
A. Ready waits for I/O; Waiting waits for CPU
D. Process entering the Waiting state
B. Ready is scheduled for CPU; Waiting waits for event completion

Q3. Which of the following is true about a process in the New state? C. Waiting is selected by scheduler; Ready is not

A. It can request I/O D. There is no difference


Activity Moderate Learner (Story-Based
Scenario)
You are a junior system administrator at a mid-sized company. The system handles four user
requests (processes), and your task is to analyze how different CPU scheduling algorithms
affect performance.
Process Arrival Time (ms) Burst Time (ms) Priority (1 = High)
P1 0 5 3
P2 1 3 1
P3 2 8 2
P4 3 6 4

👉 Use a Gantt chart format to visualize process execution.


FCFS (First Come First Serve), SJF (Shortest Job First – Non-Preemptive), Priority Scheduling
(Non-Preemptive)
Activity Moderate Learner
Calculate Metrics for each algorithms
Process Completion Time Turnaround Time Waiting Time
P1
P2
P3
P4

1. Which algorithm had the lowest average waiting time?


2. Which process waited the longest in each algorithm?
3. How does arrival time affect performance in SJF and Priority Scheduling?
4. If this were a real-time system, which algorithm would be most suitable and
why?
Activity Moderate Learner(Simple Multiple-Choice Quiz)

Q1. In FCFS, which process is scheduled first? C. Has lowest priority


A. The one with highest priority D. Skipped by CPU
B. The one with shortest burst time
Q4. Which scheduling algorithm may cause starvation?
C. The one that arrives first
A. FCFS
D. Chosen randomly
B. Round Robin
Q2. What is the main advantage of SJF? C. SJF
A. Reduces turnaround time D. Priority Scheduling
B. Always fair
Q5. Average waiting time is:
C. Ignores burst time
A. Always zero
D. Supports parallel processing
B. The same in all algorithms
Q3. In Priority Scheduling, a process with priority = 1: C. Total waiting time ÷ number of processes
A. Will be scheduled last D. Completion time - Burst time
B. Has the highest priority
Fast Learner Activity
Scenario: 3
A university's operating system lab Field P1 P2 P3
team has developed a custom OS
Process ID 101 102 103
kernel. During testing, they observe
an unusual behavior: two processes, Process State Running Running Waiting (I/O)

P1 and P2, both marked as Program Counter 0x004A 0x1F3C 0x03B2


"Running" simultaneously on a
CPU Registers Saved Saved Saved
single-core system.
Upon investigation, the team Scheduling Info Priority 2 Priority 1 Priority 3

inspects the Process Control Memory Limits 0x0000–0x1FFF 0x2000–0x3FFF 0x4000–0x5FFF


Blocks (PCBs) of all active
I/O Status No pending I/O No pending I/O Disk read pending
processes. Below are the PCB
fields for P1, P2, and P3: Accounting Info 8 ms CPU time 5 ms CPU time 3 ms CPU time
Fast Learner Activity (Analysis Questions)

1. Identify the error in PCB management. What state should P1's PCB have been updated to when

P2 was scheduled?

2. Explain the role of the PCB's Program Counter and CPU Registers during context switching.

3. How could such an error lead to system instability or incorrect resource management?

4. Propose two mechanisms that could prevent or detect PCB synchronization issues.

5. Suppose P3 completes its I/O. Describe the full sequence of changes in its PCB if it becomes the

next scheduled process.


Fast Learner Activity
Q1. Which PCB field helps the OS resume a process after C. CPU registers
preemption? D. Process priority
A. Accounting Info
B. Memory Limits Q4. What must happen to the PCB during a context
C. Program Counter switch?
D. Process State A. Delete the PCB of the current process
B. Save the CPU context to the PCB
Q2. In a well-functioning scheduler, how many PCBs can C. Remove the I/O status
have the “Running” state on a single-core CPU at a time? D. Reinitialize memory limits
A. 0
B. 1 Q5. A mismatch between a process’s actual execution
C. 2 state and its PCB state can lead to:
D. Unlimited A. Improved CPU scheduling
B. Accurate accounting
Q3. Which of the following is NOT typically stored in a C. Race conditions and resource conflicts
PCB? D. Better I/O throughput
A. Open file descriptors
B. CPU temperature
Fast Learner Activity
Three process p1, P2 and P3 arrive at time zero. Their total execution time is 10ms, 15ms, and 20ms
respectively. They spent first 20% of their execution time in doing I/O, next 60% in CPU processing and
the last 20% again doing I/O. For what percentage of time was the CPU free? Use Round robin algorithm
with time quantum 5ms. Execution
Process I/O burst CPU burst I/O Burst
time

P1 10 2 6 2

P2 15 3 9 3

P3 20 4 12 4

You might also like