Purpose of Operating System (Comp-Sci)
Purpose of Operating System (Comp-Sci)
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
2 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
3 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
4 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
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
10 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
11 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
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
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
16 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
0 27 36 39
23
17 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
18 Davis_Kazibwe@2023KIS
AS & A LEVEL COMPUTER SCIENCE 9618
P1 P2 P2 P2 P4 P3 P1
0 1 2 3 5 8 17 39
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
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