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

Purpose of Operating System (Comp-Sci)

Uploaded by

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

Purpose of Operating System (Comp-Sci)

Uploaded by

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

AS & A LEVEL COMPUTER SCIENCE 9618

PURPOSE OF AN OPERATING SYSTEM


USER USER USER USER USER

APPLICATIONS
SOFTWARE

OPERATING SYSTEM
Provides
interface
between
HARDWARE DEVICES users and
(RAM)(CPU)(I/O DEVICES)(PRINTER) hardware

1 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

PURPOSE OF AN OPERATING SYSTEM


Resource management focuses on utilizing the resources and maximize the use of
resources
Deals with input | output operation
EXAMPLES OF RESOURCES
1. CPU
2. Memory
3. Input / Output devices

2 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

DIRECT MEMORY ACCESS

1. We use DMA controller to give access to memory directly. It allows the


hardware to access the main memory independently of the CPU
2. It frees up the CPU to allow it to carry out the other tasks

3 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

DIRECT MEMORY ACCESS


1. DMA initiates the data transfer
2. While CPU carries out other tasks
3. Once the data transfer is complete, an interrupt signal is sent to the CPU from
the DMA
KERNEL
 If an application wants to access a hardware component such as flash light so it
first goes to kernel and seek permission to use it.
 Kernel: Is the part of operating system responsible for communicating
between hardware, software and memory.
 Responsible for process management, device management and memory
management

4 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

DIRECT MEMORY ACCESS

HOW OPERATIN SYSTEM HIDES THE COMPLEXITIES OF THE HARDWARE FROM


THE USER
Operating system provides interface for example GUI which helps to use the
hardware
Operating system uses devices drivers to synchronize the hardware

5 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

PROCESS MANAGEMENT
DIFFERENCE BETWEEN PROGRAM AND PROCESS
Program is the written code
Process is the executing code

MULTI-TASKING
1. Multi tasking in an operating system allows a user to perform more than one
computer task at a time.
2. To ensure multi-tasking operates correctly ( for example process do not
clash), scheduling is used to decide which processes should be carried out
3. Multi-tasking ensures the best use of computer resources by monitoring each
state of process
4. It should seem that many processes are executed at the same time
5. In fact, kernel overlaps the execution of each process based on scheduling
algorithms.

6 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

PROCESS MANAGEMENT
DIFFERENCE BETWEEN PROGRAM AND PROCESS
Program is the written code
Process is the executing code

MULTI-TASKING
1. Multi tasking in an operating system allows a user to perform more than one
computer task at a time.
2. To ensure multi-tasking operates correctly ( for example process do not
clash), scheduling is used to decide which processes should be carried out
3. Multi-tasking ensures the best use of computer resources by monitoring each
state of process
4. It should seem that many processes are executed at the same time
5. In fact, kernel overlaps the execution of each process based on scheduling
algorithms.

7 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

PROCESS MANAGEMENT
PREMPTIVE: Preempt( to take action, to steal ). When CPU is allocated to a
particular process and if at that time a higher priority process comes then CPU is
allocated to the process
NONPREEMPTIVE: Does not take any action until the process is terminated

PREEMPTIVE NONPREEMPTIVE
Resources are allocated to a process for Once the resources are allocated to a
a limited time process, the process retains them until
it has completed its burst time( amount
of time required by a process for
executing on CPU)
Process can be interrupted while it is The process can not be interrupted
running while running
More flexible of scheduling More rigid form of scheduling

8 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

PROCESS MANAGEMENT
WHY AN OPERATING SYSTEM NEEDS TO USE SCHEDULING ALGORITHMS
To allows multitasking to take place
To ensure fair usage of processor
To ensure fair usage of peripherals
To ensure fair usage of memory
To ensure higher priority tasks are executed sooner
To ensure all processes have the opportunity to finish
To minimize the amount of time users must wait for their results
To keep CPU busy at all time
To ensure the largest possible number s of jobs in given amount of time

PROCESS STATES
1. Running
2. Ready
3. Blocked

9 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

CASE 1: NO INTERRUPTS | I/O REQUESTS

Program not process


TERMINATE
NEW
Secondary
Memory
Program waits for CPU Time

READY STATE READY STATE

Program running on CPU

10 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

CASE 2:| I/O REQUESTS


NON-PREEMPTIVE

Program not process


TERMINATE
NEW
Secondary
Memory
Program waits for CPU Time

READY STATE READY STATE

Program running on CPU


I/O operation occurs
Process waits for event or I/O
BLOCKED STATE
request

11 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

CASE 2:| I/O REQUESTS PREEMPTIVE

Program not process


TERMINATE
NEW
Secondary Interrupt / Higher priority
Memory
Program waits for CPU Time

READY STATE READY STATE

Program running on CPU


I/O operation occurs
Process waits for event or I/O
BLOCKED STATE
request

12 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

PROCESS STATES
READY STATE
1. The process is not being executed
2. The process is in the queue waiting for the processor’s alteration or time slice

RUNNING STATE
1. The process is being executed
2. The process is currently using its allocated processor time or time slice

BLOCKED STATE
• The process is waiting for an event so it can not be executed at the moment
for example input/output

13 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

CONDITIONS FOR TRANSITION BETWEEN STATES


READY - RUNNING
1. Current process no longer running ( processor is available)
2. Process was at the head of ready queue ( Process has highest priority)
3. OS allocates processor to process so that process can execute

RUNNING - READY
1. When process is executing it is allocated a time slice
2. When time slice is completed, interrupt occurs and process can no longer use
processor even though it is capable of further processing

BLOCKED STATE
• Process is executing ( running state ) when it needs to perform input or output
operation and it is placed in blocked state until input or output operation is
completed

14 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

PROCESS STATES
Qtn: Explain why a process can not be moved from the blocked state to running
state ?
1. When I/O operation completed for process in blocked state
2. Process is transferred to ready state
3. OS decided which process to allocate to processor

Qtn: Explain why a process cannot move directly from the ready state to blocked
state ?
1. To be in blocked state process must initiate so I/O operation
2. To initiate operation process must be executing
3. If the process is in ready state, it can not be executing

15 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

SCHEDULER
HIGH LEVEL SCHEDULER
Decides which processes are to be loaded from backing store into ready queue

LOW LEVEL SCHEDULER


Decides which of the processes in ready state should get use of processor or
which processor is put into running queue based on position or priority

SCHEDULING ROUTINE ALGORITHMS


1. First come first served scheduling
2. Shortest job first scheduling
3. Shortest remaining time first scheduling
4. Rand Robin

16 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

FIRST COME FIRST SERVED SCHEDULER


Non – preemptive
Based on arrival time
Uses first in first out ( FIFO ) principle

PROCESS ARRIVE SEQUENCE BURST TIME Waiting Time (Average) for a


process
P1 1 23 MS = 0 + 23 + 27 + 36 \ 4
P2 2 4 MS = 21.5 MS
P3 3 9 MS
P4 4 3 MS

The queue will be:


P1 P2 P3 P4

0 27 36 39
23

17 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

SHORTEST REMAINING TIME FIRST


1. Preemptive
2. The process are placed in ready queue as they arrive
3. But when a process with a shortest burst time arrives the existing process is
removed
4. The shorter process is then executed first

18 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

SHORTEST REMAINING TIME FIRST

P1 P2 P2 P2 P4 P3 P1

0 1 2 3 5 8 17 39

At Time 1 MS At Times 2 MS At Times 3 MS


P1 P2 P1 P2 P3 P1 P2 P3 P4
22 4 22 3 9 22 2 9 3

T.A = COMPLETION TIME – ARRIVAL TIME


W.T = T.A – B.T

19 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

ROUND ROBIN
1. Preemptive
2. A fixed time slice is given to each process, this is known as time quantum
3. The running queue is worked out by giving each process its time slice in the
correct order.
4. If a process completes before the end of its time slice then the next process is
brought into ready queue for its time slice

20 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

ROUND ROBIN
Time Quantum = 5 MS

21 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

INTERRUPT HANDLING
USER MODE AND KERNEL MODE

22 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

INTERRUPT HANDLING
Interrupt: Is a kind of signal to OS from the device which is connected to
computer. Sometimes interrupts are within the computer
The processor will check for interrupt signals and will switch to kernel mode.
If any of the following type of interrupt signals are sent
1. Device Interrupt ( printer out of paper)
2. Exceptions ( Instruction faults such as division by zero )
3. Traps / Software Interrupt ( Process requesting a resource )
IDT
IPL
Interrupt Dispatch Table to
Interrupt Priority Level
determine the current response
numbered ( 0 -31 )
to interrupt

23 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

INTERRUPT HANDLING
1. When an interrupt is received, other interrupts are disabled so that the
process that deals with the interrupt can not itself be interrupted.
2. The state of the current task / process is saved on the kernel stack
3. The source of interrupt is identified, for example is it hardware, an exception
or a trap. The priority of interest is checked
4. The system now jumps to the interrupt service routine (using the IDT)
5. Once completed, the state of the interrupted process is restored using the
values stored on the kernel stack, the process then continues
6. After as interrupt has been handled, the interrupt needs to be restored so that
any further interrupts can be dealt with

24 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

MEMORY MANAGEMENT

25 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

MEMORY MANAGEMENT
Rest of pages which are not present in main memory they are stored in hardware
PAGE REPLACEMENT
1. Page replacement occurs when a requested page is not in memory ( flag = 0)
2. When paging in / out from memory, it is necessary to consider how the
computer can decide which page(s) to replace to allow the requested page to be
loaded. When a new page is requested but it is not in memory a page fault
occurs
PAGE REPLACEMENT ALGORITHM
1. First In First Out
2. Optimal Page Replacement: Looks forward in line to see which frame it can
replace in the extent of page fault
3. Longest Resident: A particular page which is present for longest time is swapped
( Time to entry should be present in Page table )
4. Least Used : A particular page which is used less is swapped ( Number of time
the page has been accessed should be present in Page Table )

26 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

MEMORY MANAGEMENT
Qtn: Explain why the algorithms ( Longest resident / Least used ) may not be the
best choice for different memory management
1. Longest Resident: page in for lengthy period of time may be accessed often
therefore not good candidate for being removed
2. Least used : A page just entered has a low least value so likely to be a candidate
for immediately being swapped out

27 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

SEGMENTATION

28 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

DIFFERENCES BETWEEN PAGING AND


SEGMENTATION
PAGING SEGMENTATION

A page is a fixed size block of memory A segment is a variable size block of


memory
Since the block size is fixed, it is Memory blocks are variable size, this
possible that all blocks may not be fully increases the risk of external
used, this can lead to internal fragmentation
fragmentation
The user provides a single value, this The user will supply the segment
means that the hardware decides the number and segment size
actual page size
Procedure ( modules ) cannot be Procedure can be separated when
separated when using paging using segmentation

29 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

VIRTUAL MEMORY
Secondary storage is used to extend RAM
So CPU can access more memory space than a variable RAM
Only part of program / data in use needs to be in RAM
Data is swapped between RAM and disk
HOW PAGING IS USED TO MANAGE VIRTUAL MEMORY
1. Divides memory RAM into frames
2. Divide memory into blocks of sane size called pages
3. Frames / pages are fixed size
4. Set up a page table to translate logical address to physical address
5. Keep track of all free frames
6. Swap pages in memory with new pages from disk when needed

NOTE:
One drawback of using virtual memory is disk thrashing

30 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618

DISK THRASHING
1. Pages are required back in RAM as soon as they are moved to disk
2. There is a continuous swapping (of the same pages )
3. No useful processing happens because pages that are in RAM and on disk are
inter-dependent
4. Nearly all processing time is used for swapping pages

31 Davis_Kazibwe@2023KIS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy