Digital Systems Process Scheduling

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/27

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

28 Terms

1
New cards

Scheduling

  • A key concept in computer multitasking and multiprocessing operating system design, and in real-time operating system design

    • The way processes are assigned priorities in a priority queue

2
New cards

Process Scheduling

  • In operating systems (OS), process scheduling is the process of deciding which process to run on the CPU and for how long, ensuring efficient and fair resource allocation among multiple processes

  • It's a crucial function of the OS, especially in multitasking environments, where multiple processes compete for CPU time

3
New cards

Program vs Process

  • Program is a set of instructions written to perform a task, stored in memory

  • Process is the active execution of a program, using system resources like CPU and memory

  • Program is static, a process is dynamic, representing the program in action

  • When we execute a program that was just compiled, the Operating System will generate a process to execute the program

  • process (Job) refers to program code that has been loaded into a computer’s memory so that it can be executed by the central processing unit (CPU). A process can be described as an instance of a program running on a computer

<ul><li><p><span>Program is a set of instructions written to perform a task, stored in memory</span></p></li><li><p><span>Process is the active execution of a program, using system resources like CPU and memory</span></p></li><li><p><span>Program is static, a process is dynamic, representing the program in action</span></p></li><li><p><span>When we execute a program that was just compiled, the Operating System will generate a process to execute the program</span></p></li><li><p><span>process (Job) refers to program code that has been loaded into a computer’s memory so that it can be executed by the central processing unit (CPU). A process can be described as an instance of a program running on a computer</span></p></li></ul><p></p>
4
New cards

Process States

A process can be in one of the following states:

  1. Created/New: Process is being created

  2. Ready: Process is waiting to be assigned to CPU

  3. Running: Process is currently being executed by the CPU

  4. Blocked (Waiting): Process is waiting for an event (e.g., I/O completion)

  5. Terminated: Process has finished execution

<p>A process can be in one of the following states:</p><ol type="1"><li><p><span>Created/New: Process is being created</span></p></li><li><p><span>Ready: Process is waiting to be assigned to CPU</span></p></li><li><p><span>Running: Process is currently being executed by the CPU</span></p></li><li><p><span>Blocked (Waiting): Process is waiting for an event (e.g., I/O completion)</span></p></li><li><p><span>Terminated: Process has finished execution</span></p></li></ol><p></p>
5
New cards

Additional Process States to support Virtual Memory

Processes are "stored" on HD

  • Swapped out and waiting: (suspended & waiting) In systems that support virtual memory, a process may be swapped out, that is, removed from RAM and placed on HD by the scheduler. From here the process may be swapped back into the waiting state

  • Swapped out and blocked(suspended & blocked) Processes that are blocked may also be swapped out. It might be swapped back in again under the same circumstances as a swapped out

<p><span>Processes are "stored" on HD</span></p><ul><li><p><span>Swapped out and waiting: (suspended &amp; waiting) In systems that support virtual memory, a process may be swapped out, that is, removed from RAM and placed on HD by the scheduler. From here the process may be swapped back into the waiting state</span></p></li><li><p><span>Swapped out and blocked(suspended &amp; blocked) Processes that are blocked may also be swapped out. It might be swapped back in again under the same circumstances as a swapped out</span></p></li></ul><p></p>
6
New cards

CPU Scheduling Criteria

  • CPU Utilization: Keep CPU as busy as possible

  • Throughput: number of processes that complete their execution per time unit

  • Turnaround Time: amount of time to execute a particular process

  • Waiting Time: amount of time a process has been waiting in the ready queue

  • Response Time: Time taken from request submission to first response

  • Fairness: Ensure equal opportunity for all processes

7
New cards

Context Switching

  • The process of saving the state of a running process and loading the state of the next process

  • Introduces overhead but is essential for multitasking

<ul><li><p><span>The process of saving the state of a running process and loading the state of the next process</span></p></li><li><p><span>Introduces overhead but is essential for multitasking</span></p></li></ul><p></p>
8
New cards

Deadlock

Occurs when a group of processes is permanently blocked, each waiting for a resource held by another process in the group

Circular waiting on resources, preventing progress

9
New cards

Deadlock Example

Process A holds Resource X and needs Resource Y, while Process B holds Resource Y and needs Resource X. Neither process can continue because they are waiting for each other’s resources

10
New cards

Starvation

Low-priority processes never get CPU time

11
New cards

Starvation Example

In a CPU scheduling scenario, a process with a lower priority might never get scheduled if there are always higher-priority processes ready to run

12
New cards

Running Multiple Processes

  • In most OS, multi-tasking – running multiple processes on the machine interleaved over time

    • This may be the actual parallel running of processes (e.g, multiple CPUs or cores)

    • And/or time slicing between processes - quickly and frequently switching between which process is running to give the impression they are all running simultaneously

13
New cards

Types of Time Slicing

  • Cooperative – the process indicates when it is ok to stop for a moment

  • Pre-emptive – the OS decides when to switch and it’s done without the process’s involvement

    • Most OS use pre-emptive multi-tasking and the part of the kernel that decides who to switch between processes is the scheduler

14
New cards

Types of Scheduling

  1. Long-Term Scheduling (Job Scheduling)

  2. Medium-Term Scheduling

  3. I/O Scheduling

  4. Short-Term Scheduling (CPU Scheduling)

15
New cards

Short-Term Scheduling (CPU Scheduling)

  • Decides which process gets the CPU next

  • Runs frequently (every few milliseconds)

  • Uses scheduling algorithms like FCFS, Round Robin, SJF, Priority Scheduling

16
New cards

Scheduling Algorithms

  • First-Come, First-Served (FCFS) – Non-preemptive (Cooperative), runs in order of arrival

  • Shortest Job Next (SJN or SJF) – Runs the shortest process first

  • Round Robin (RR) – Each process gets a fixed time slice (time quantum)

  • Priority Scheduling – Higher priority processes execute first

  • Multilevel Queue Scheduling – Divides processes into different priority queues

17
New cards

First Come, First Serve (FCFS) Scheduling

  • The simplest scheduling algorithm

  • Processes are executed in the order they arrive in the ready queue

  • It follows a non-pre-emptive (Cooperative) scheduling approach

18
New cards

How Does FCFS Work?

  1. The process that arrives first gets executed first

  2. The CPU is allocated until the process completes execution

  3. The next process in the queue gets executed after the previous process finishes

19
New cards

FCFS Example

Turnaround Time (TAT) = Completion Time - Arrival Time

  • TAT(P1) = 5 - 0 = 5 , TAT(P2) = 8 - 1 = 7 , TAT(P3) = 16 - 2 = 14 , TAT(P4) = 22 - 3 = 19

Waiting Time (WT) = Turnaround Time - Burst Time

  • WT(P1) = 5 - 5 = 0 , WT(P2) = 7 - 3 = 4 , WT(P3) = 14 - 8 = 6 , WT(P4) = 19 - 6 = 13

<p>Turnaround Time (TAT) = Completion Time - Arrival Time</p><ul><li><p><span>TAT(P1) = 5 - 0 = 5 , TAT(P2) = 8 - 1 = 7 , TAT(P3) = 16 - 2 = 14 , TAT(P4) = 22 - 3 = 19</span></p></li></ul><p>Waiting Time (WT) = Turnaround Time - Burst Time</p><ul><li><p><span>WT(P1) = 5 - 5 = 0 , WT(P2) = 7 - 3 = 4 , WT(P3) = 14 - 8 = 6 , WT(P4) = 19 - 6 = 13</span></p></li></ul><p></p>
20
New cards

FCFS Advantages

  • Simple to implement

  • Fair since processes are scheduled in order of arrival

21
New cards

FCFS Disadvantages

  • Poor response time for long processes

  • Convoy effect: A long process delays all other processes

22
New cards

Round Robin (RR) Scheduling

  • A pre-emptive scheduling algorithm

  • Each process gets a fixed time (time quantum) for execution

  • If a process doesn't complete within the time quantum, it is pre-empted and moved to the end of the queue

23
New cards

How does RR Work?

  1. The CPU executes each process for a fixed time quantum (e.g., 4 ms)

  2. If a process completes within the quantum, it terminates

  3. If not, it is moved to the end of the queue and waits for the next turn

24
New cards

RR Example

  • P1 starts at 0 ms and runs for 4 ms (remaining: 1 ms)

  • P2 starts at 4 ms and runs for 3 ms (finishes)

  • P3 starts at 7 ms and runs for 4 ms (remaining: 4 ms)

  • P4 starts at 11 ms and runs for 4 ms (remaining: 2 ms)

  • P1 resumes at 15 ms and runs for 1 ms (finishes)

  • P3 resumes at 16 ms and runs for 4 ms (finishes)

  • P4 resumes at 20 ms and runs for 2 ms (finishes)

Average Turnaround Time = (15+6+18+19)/4 = 14.5 ms

Average Waiting Time = (10+3+10+13)/4 = 9 ms

<ul><li><p><span>P1 starts at 0 ms and runs for 4 ms (remaining: 1 ms)</span></p></li><li><p><span>P2 starts at 4 ms and runs for 3 ms (finishes)</span></p></li><li><p><span>P3 starts at 7 ms and runs for 4 ms (remaining: 4 ms)</span></p></li><li><p><span>P4 starts at 11 ms and runs for 4 ms (remaining: 2 ms)</span></p></li><li><p><span>P1 resumes at 15 ms and runs for 1 ms (finishes)</span></p></li><li><p><span>P3 resumes at 16 ms and runs for 4 ms (finishes)</span></p></li><li><p><span>P4 resumes at 20 ms and runs for 2 ms (finishes)</span></p></li></ul><p><span>Average Turnaround Time = (15+6+18+19)/4 = 14.5 ms</span></p><p><span>Average Waiting Time = (10+3+10+13)/4 = 9 ms</span></p>
25
New cards

RR Advantages

  • Pre-emptive: Avoids long waiting times for short processes

  • Better response time than FCFS

26
New cards

RR Disadvantages

  • Overhead due to frequent context switching

  • Choosing the wrong time quantum can impact performance

27
New cards

FCFS vs RR

Feature

FCFS

RR

Pre-emptive

No

Yes

Fairness

No (Convoy Effect)

Yes (Time Quantum)

Response Time

High (Bad)

Low (Good)

Overhead

Low

High (Context Switching)

28
New cards

Why is Scheduling Important?

  • Ensures fairness: No process is left waiting indefinitely

  • Maximises CPU utilisation: Prevents CPU idleness

  • Minimises response time: Provides quick interaction in time-sharing systems

  • Balances system load: Distributes work efficiently among processors

    • Efficient multitasking and resource utilization, ensuring that multiple processes can run concurrently without significant slowdowns or instability