Chapter 16.1 Flashcards
"Purposes of an Operating System"
what is an operating system
provides an interface between users and the hardware
what is the purpose of an OS?
- interacts with hardware and runs software.
- provides multiprogramming ability
- maximises resources - CPU time, memory, I/O system. (manages process, device, and memory management)
- provides a user interface (CLI, GUI, voice recog.)
- provides file system to store data and programs
- manages peripherals
resources list
cpu
memory
I/O devices
maximise memory
moving frequently accessed instructions to cache for faster recall (SRAM over DRAM)
making use of virtual memory
partitioning memory (to allow for multiprogramming)
kernel
program that controls all other programs. responsible for communication between hardware, software and memory.
how does the operating system hide the complexities of the hardware from the user?
provides interface (CLI, GUI) - user doesnt interact directly with hardware
uses device drivers to synchronize hardware
program
written/static code
process
executing code
how is multi-tasking achieved
scheduling is used to decide which processes should be carried out, which ensures the best use of computer resources (see scheduling)
kernel overlaps the execution of each process based on scheduling algorithms - CPU clock is also used!
process states:
running = process is being executed
ready = process is in the queue waiting for the processor’s attention
blocked = process is waiting for an event so it cannot be currently executed, e.g. I/O
why is blocked > running not possible?
when I/O operation is completed for process in the blocked state,
the process is transferred to the ready queue,
THEN the OS decides to allocate to processor
preemptive scheduling algorithms
if a higher-priority process comes then the CPU’s attention is allocated to that process. examples are:
round robin and shortest time remaining
non-preemptive scheduling algorithms
does not halt a process until it is completed or transitions to a waiting state. examples include:
first come first serve and shortest job first
round robin
preemptive. each process gets a fixed time slice (all processes are given the same priority). when the time is up, if it’s still not completed the process is moved to the end of the ready queue.
benefit: starvation doesn’t occur, processes are given equal time slices
drawback: requires frequent switching, which can result in a high overhead
first come first served
non-preemptive. each process is queued as it is received and is executed one by one.
benefit: starvation also doesn’t occur, every process eventually gets a chance to run.
drawback: is inefficient, less complex features
shortest job first
non-preemptive. ready queue is sorted in ascending length of processes, shortest to longest.
benefit: more processes can be executed in a smaller amount of time, reduces average waiting time
drawback: prioritizes shorter processes, starvation is a possibility.
also doesn’t consider process priority
shortest remaining time
preemptive. the processes are placed in ready queue as they arrive in ascending order but when a process with a shorter burst/remaining time arrives,
the running process is moved to the queue and the shorter process is set to run.
benefit: more processes get completed in a shorter time
drawback: starvation can occur
purpose of scheduling
to allow multitasking
to ensure fair use of the processor, of the peripherals,
and of memory.
to ensure higher priority tasks are executed sooner
to prevent starvation of processes
to keep the CPU busy/efficient use of CPU
to minimise the user waiting time
how does the kernel of the OS act as an interrupt handler?
other interrupts are disabled
state of current process is saved on the kernel stack
kernel calls the ISR (interrupt service routine) to deal with the interrupt.
interrupts are restored
interrupt
a signal from some device indicating that an event has occurred, seeking the attention of the processor
how is low level scheduling used to manage interrupt handling
An interrupt is of high priority therefore low-level scheduling will move the job straight into running, without going through the queue.
low-level scheduling
decides which process in ready queue should be moved to running state, based on position and priority.
decides which program currently in memory should access the CPU.
medium-level scheduling
occasionally takes a program back to the disk due to main memory being overcrowded
high-level scheduling
makes decisions about which programs stored on the disk should be moved into memory to run and be executed
paging
a page is a fixed size block of memory
since the block size is fixed, not all blocks may be fully used which can lead to internal fragmentation
OS decides the actual page size
segmentation
segment is a variable size block of memory (increases the risk of external fragmentation)
divided by the programmer
segments are loaded when required during execution
each segment is loaded into a dynamic partition
virtual memory
- secondary storage is used to extend the RAM/main memory,
- so the CPU can access more memory space than available RAM
- only the data in use needs to be in main memory, so data is swapped between RAM and virtual memory as needed
- virtual memory created is temporary
the difference between paging and segmentation
paging divides memory into fixed size blocks, segmentation divides memory into variable size blocks
the OS decides page size, the user decides the segment size
access times for paging is faster than for segmentation
disk thrashing
when pages are required in RAM as soon as they are moved to disk - pages in RAM and in virtual are interdependent
there is continuous swapping of the same pages, perpetual loading
deadlock occurs (no useful processing occurs)
processing time is used for swapping pages, processing speed is reduced
how is paging used to manage virtual memory
divide RAM memory into frames
divide virtual memory into blocks of the same size called pages
frames and pages are a fixed size
set up a page table to translate logical (main) to physical (virtual) addresses, which keeps track of all free frames
swap pages in memory with new pages from disk when needed
page replacement algorithms
first in first out = page most recently swapped is swapped back
least used = page which is used the least is swapped
longest resident = page which has been present for the longest time is swapped
page
virtual memory (secondary storage) is divided into blocks of a fixed size
page frame
the main memory is divided into page frames of the same size as the virtual memory pages
page table
maps the pages to page frames and keeps track of all free frames