Subtopic Notes
16.1 Purposes of an Operating System
16. System Software
Operating System: A collection of software that manages computer hardware resources and provides common services for computer programs.
Program and Process:
- A program is the written code (static)
- A Process is the executing code (dynamic)
Maximizing the use of resources
- Memory Management
- Partitions main memory into static and dynamic partition and this will allow more that one program being run
- Removing processes from RAM when it is terminated
- Uses techniques like paging, segmentation, and virtual memory.
- Disk Management
- Manages and organizes file in secondary storage including HDD and SSD
- Compressing files to save space
- Uses disk scheduling to reduce access delay
- Uses method like defragmentation and disk checkup
- Managing CPU
- Ensures the CPU is kept busy by scheduling processes so it doesn’t stay idle.
- Uses multi-tasking
- Prevents starvation (where one process never gets CPU time)
- Input/Output Devices
- Manages device drivers to allow hardware to work smoothly
- Uses buffering to make sure devices can work at their own speed while CPU continues with other tasks.
- Ensures multiple processes can share I/O devices fairly
Providing User Interface (UI)
- Provides an interface (CLI, GUI, or menu-driven) to interact with hardware.
- Hides complexity as users don’t need to understand machine code or hardware details.
- Interface Types
- Command-line interface (CLI)/Character User Interface (CUI)
- Graphical User Interface (GUI)
- Dialogue Interface
- Menu Driven Interface
- Gesture Based Interface
Process Management
- Process of allocating the CPU’s resource on difference processes based on their needs
- This allows multitasking and prevents starvation
- Makes sure the CPU does not stay idle
- Multitasking:
- More than one program can be stored in memory, but only one can have CPU access at any given time
- The rest of the programs remain ready
- Process:
- A program being executed which has an associated Process Control Block (PCB) in memory
- PCB: a complex data structure containing all data relevant to the execution of a process
- Process states
- Ready: A new process arrived at the memory, and the PCB is created
- Running: A process in the ready state is given access to the CPU by the dispatcher, it changes to running state. It will get back to ready state once halted by an interrupt.
- Waiting (Blocked): A process cannot progress until some event has occurred. The process is notified of an event completion and returns to ready state
- Terminated: A process in the running state completes execution and changes to terminated state
- Scheduling
- Scheduling ensures that the computer system can serve all requests and obtain a certain quality of service.
- Low-level scheduling: Allocation of specific processor components to complete specific tasks.
- Preemptive: A running process can be interrupted by the OS to give the CPU to another process.
- Round-robin
- Allocates time slice to each process
- Can be a FIFO queue
- Does not prioritize
- As the number of processes increases, each process gets a smaller time slice, so urgent tasks may take longer to complete.
- Shortest Remaining Time
- The job with the least remaining execution time is given priority.
- Minimizes waiting time further but requires constant recalculation.
- Round-robin
- Non-preemptive: Once a process starts running, it cannot be stopped until it finishes or voluntarily gives up the CPU.
- First-come-first-served
- Non-preemptive
- FIFO (First In First Out) queue
- Simple to implement but can cause long waits if early jobs are large.
- Shortest Job First
- Jobs with the smallest estimated execution time run first
- Reduces average waiting time but needs knowledge of job length
- First-come-first-served
- Interrupt Handling
- When an interrupt occurs, the process currently running is moved back to the ready state.
- The interrupt service routine (ISR) is placed in the running state to be executed
- Once the interrupt has been serviced, the scheduler selects the next process to run
- Low-Level Scheduler (CPU Scheduler):
- Determines which process from the ready queue will be given the CPU next.
- Uses scheduling algorithms such as Round Robin, First Come First Served, Shortest Job First, or Shortest Remaining Time
- High-Level Scheduler (Job Scheduler):
- Decides which jobs from secondary storage are moved into the ready queue
- Helps control the level of multiprogramming in the system
Memory Management
- Segmentation
- Programs are divided into segments of various size by the programmer
- Segments are loaded as and when required during execution
- Virtual memory & Paging:
- Virtual Memory:
- Appears as if more memory is available than physically exists.
- Uses secondary storage to extend the address space
- Managed by paging
- Virtual memory is divided into equal blocks called pages
- Paging
- A process is divided into fixed-size pages.
- Main memory (RAM) is divided into frames of the same size.
- Virtual memory is also split into pages of equal size, making it possible to run programs larger than physical RAM.
- A page table translates logical addresses to physical addresses and keeps track of free frames.
- Not all pages of a program need to be loaded into memory at once.
- Pages are swapped in and out of memory as needed, managed by the Memory Management Unit
- If no free frame is available, a page in memory is replaced using a replacement algorithm:
- First In First Out
- Least Recently Used
- Least Frequently Used
- Page Frame: Main memory is split into fixed-size blocks, each block is called a page frame.
- Page Table: Stores the mapping information that links each page of a process to its corresponding page frame in main memory
- Process
- All pages on the disk initially
- One/more loaded into memory when process ‘ready’
- Pages replaced from disk when needed
- This can be done with a FIFO queue or usage-statistics-based algorithm
- Benefits
- Not all of the program has to be in memory at once
- Large programs can be run with or without large physical memory
- Disadvantage
- Expensive
- Disk thrashing: Perpetual loading/unloading of pages due to a page from disk immediately requiring the page it replaced.
- Virtual Memory:
OS Structure
An OS has to be structured to provide a platform for resource management and facilities for users. The logical structure provides 2 modes of operation:
- The user mode is the one available for the user or an application program.
- Privileged/kernel mode has the sole access to parts of the memory and to certain system functions that the user mode can’t access.
