CSOPESY_introduction_OS_up_to_computing_environments

RAW FILE

This note has not been edited yet. Content may be subject to change.

original file

01 Introduction

What Operating Systems Do

  • OS is a software, manages computer hardware and provides a basis for application programs
  • user view: varies by device (PC, mobile, embed)
    • goal: ease of use, performance
    • embedded systems: computers working to control something, the goal is to run without user intervention
  • system view
    • OS acts as a resource allocator (managing CPU, mem, storage)
    • acts as control program (prevents errors, improper use)
  • kernel: core of the OS, program running at all times
    • system programs - associated with the OS, not necessarily part of the kernel
    • middleware - framework that provides additional services for application devs
    • it's the basic code that can run everything
      • sockets are like middleware so you can send/receive something over the network

buffer overflow - enroach onto another program and reach havoc of it → the OS handles that problem

user ↔ app programs ↔ operating system → computer hardware

Windows Operating System Components

_attachments/Pasted image 20251008112437.png

  • user mode and kernel mode
  • dll are the libraries you use (dynamic link libraries) so that you can use the hardware

Linux Operating System Structure

_attachments/Pasted image 20251008112445.png

  • also has libraries to connect to the kernel

Android Operating System Structure

_attachments/Pasted image 20251008112454.png

  • uses linux kernel

  • included a hardware abstraction layer

  • java/python was implemented because applications are machine-specific (? didn't hear this properly)

  • java and python are slow against c because c/c++ are native

Computer System Organization

_attachments/Pasted image 20251008112506.png

  • Hardware: a system has one or more CPUs and device controllers (like USB) connected via a common bus
    • each device controller → has device driver software
    • device driver: understands controller, provides rest of the OS with a uniform interface to the device (ex. keyboards are HID-compliant)
  • Interrupts: primary mechanism for hardware to signal the CPU
    • a signal from the hardware to the CPU
    • when it occurs, the CPU saves its state, abandons whatever its doing, and transfers execution to a dedicated interrupt handler - interrupt service routine; when finished, it "exits" from that code and goes back to what it was doing (similar to a function)
  • Storage Structure: hierarchy of storage based on speed, size, and cost
  • Volatile: main memory (DRAM)
  • Nonvolatile: HDDs and nonvolatile memory (NVM) devices
  • Direct Memory Access (DMA): a controller that transfers data directly between a device and memory, freeing the CPU from this task

what does SASM (assembly) do?

  • when you compile something, it turns into assembly code. c also tells it to convert the assembly code to machine code
  • when you use the print or get macro in SASM, we are using an interrupt

Interrupt

_attachments/Pasted image 20251008112529.png
the interrupt handler is just a set of software within the same CPU, think of function usage

  • Interrupt Mechanism: hardware signals the CPU to request service
    • CPU saves state and transfers execution to an interrupt handler routine
    • this routine services the interrupt and then the CPU resumes the original task
  • Interrupt-Driven I/O: the primary mechanism for hardware to signal the CPU that an I/O operation is complete
    • a device controller informs the CPU by raising an interrupt
  • Interrupt Vector: you have a lot of devices that have its own interrupt handler/service routine. a table of pointers to interrupt service routines stored in low memory ...
    • an interrupt/vector number is used as an index into this table to quickly find the correct handler
  • Types
    • Non-maskable Interrupts: there are some interrupts that cannot be turned off. reserved for critical, unrecoverable events (memory errors)
    • Maskable Interrupts: can be turned off by the CPU for critical instruction sequences, used by device controllers
  • Interrupt Priority: a system of priority levels allow the CPU to handle high priority interrupts before low priority ones, ensuring urgent tasks are completed first

../_attachments/Pasted image 20250904120457.png

_attachments/Pasted image 20251008112707.png

Storage

_attachments/Pasted image 20251008112817.png

  • Storage Hierarchy: organized based on speed, cost, and volatility. the closer to the CPU, the faster and more expensive the memory
  • main memory (RAM):
    • volatile: loses contents when power is turned off
    • directly accessible by the CPU
  • secondary storage:
    • non volatile: stores data permanently
    • HDDs and NVM devices
  • Direct Memory Access (DMA): a controller that transfers data directly between a device and memory, freeing the CPU from this task (because it's usually a 2-step task of I/O → CPU → memory)

Computer System Architecture

  • Single-Processor Systems: a single CPU with one core, plus special-purpose processors for devices
  • Multiprocessor Systems: systems with multiple CPUs or cores that can run tasks in parallel
    • Symmetric Multiprocessing (SMP): each processor is a peer and can perform all tasks
      • this one is older
      • there are processor0 (with CPU0) and processor1 (with CPU1) and each are directly connected to the main memory
    • Multicore Systems: multiple cores on a single chip, which is more efficient
      • both CPU core0 and core1 have their own L1 caches and connect to a common L2 cache
  • Clustered Systems: multiple individual systems (nodes) linked together for high availability and high-performance computing ([multiple computers](Distributed System vs. Clustered System - GeeksforGeeks) interconnected and working together)

_attachments/Pasted image 20251008112947.png
symmetric multiprocessing system vs multi-core system

Operating System Operations

  • Bootstrap Program: firmware (piece of software) code that loads the kernel when the computer starts, loads the operating system
    • OS is in the secondary memory
    • when you dual-boot you can choose what OS to start up
  • multiprogramming & multitasking: techniques to keep the CPU busy by running multiple processes concurrently
  • dual-mode operation: provides user mode and kernel mode to protect the OS from malicious user programs (with the mode bit indicating the current mode)
  • timer: hardware timer interrupts the CPU after a specified periodm ensuring the OS maintains contro and prevents a single process from running indefinitely

round-robin technique to make it look like all the programs are running together

Multi-tasking Systems

  • the OS must ensure reasonable response time
  • common method for doing so is virtual memory, a technique that allows the execution of a process that is not completely in memory
  • enables users to run programs that are larger than actual physical memory (because it uses the storage alongside physical memory and just keeps swapping)
  • abstracts main memory into a large, uniform array of storage, separating logical memory as viewed by the user from physical memory
  • frees programmers from concern over memory-storage limitations (like in python, java, unless you're using malloc in C)

Kernel and User Mode

../_attachments/Pasted image 20250904120531.png
_attachments/Pasted image 20251008115201.png
diagram: user mode to kernel mode

  • OS and the users share the hardware and software resources of the computer system
    • must ensure that an incorrect or malicious program cannot cause other programs to execute incorrectly
  • operating system must be able to distinguish between execution of OS code and user-defined code
    • most computer systems provide hardware support that allows differentiation among various modes of execution thru the mode bit
  • modes of operation: Kernel Mode, User Mode
  • Privileged instructions: machine instructions that only executes in kernel mode

Resource Management

  • Process Management: OS creates, deletes, schedules, and synchronizes processes
  • Memory Management: the OS tracks and allocates memory to processes, deciding what pages to move in and out of physical memory
  • File-System Management: the OS provides a logical view of storage and manages file and directory structures
  • Mass-Storage Management: the OS manages disk scheduling, free-space allocation, and partitioning for secondary storage
  • Caching: data copied to a faster storage system (cache) to improve performance
    • OS manages movement of data in storage hierarchy
    • so that file access is faster

when you delete a file - means it went to a different directory, it's just marked "deleted" in the file header

Process Management

  • Process Definition: program in execution
    • a process needs resources like CPU time, memory, and I/O devices to accomplish its tasks
  • Process Lifecycle
    • a process is a passive entity like a file that becomes active when loaded into memory
  • Multiple processes can be in memory and ready to run simultaneously
  • The OS switches the CPU between them to maximize utilization
    • Process Control Block (PCB): a data structure that stores all information needed to manage a process, including its state, program counter, CPU registers, and scheduling information
  • a process ends its execution by calling exit() at which point it resources are reclaimed by the OS

../_attachments/Pasted image 20250904121224.png

Memory Management

  • Main memory is a large array of bytes that the CPU and I/O devices can quickly access - it is the only large storage device that the CPU can address directly
  • Logical vs Physical: for a program to be executed, it must be loaded into memory
    • as the program runs, it generates logical addresses that are mapped to physical addresses in main memory
  • the OS is responsible for the ff activities in connection with memory management:
    • keeping track of which parts of memory are currently being used and which process is using them
    • allocating and deallocating memory space as needed
    • deciding which processes (or parts of processes) and data to move into and out of memory

Security and Protection

  • Protection: a mechanism for controlling access of programs, processes, or users to system resources
    • mechanism must provide means to specify the controls to be imposed and to enforce the controls
    • reliability can be improved by detecting latent errors at the interfaces between component systems
  • security: defends the system against external and internal attacks, ensuring the integrity of data and resources
  • user IDs and group IDs: used to distinguish users and groups, enabling the OS to enforce protection and security policies
    • a user sometimes needs to escalate privileges to gain extra permissions for an activity

sudo → u want to do something on the system itself → escalating privileges

skip to kernel data structures first, skipping virtualization and distributed systems

Kernel Data Structures

CS 1332 Data Structures and Algorithms Visualizations
../_attachments/Pasted image 20250904121510.png

  • Lists: used to represent collections of data values as a sequence, can be singly linked, doubly linked, or circularly linked. (uses pointers)
  • Stacks: LIFO
    • heap and stack can collide because stack is going up, heap is going down
  • Queues: FIFO
  • Trees: used to represent data hierarchically
    • Hash Maps: used to associate keys with values for fast data retrieval
    • Bitmaps: string of binary digits used to represent the status of items, such as free disk blocks

Virtualization

  • abstracts the hardware of a single computer into multiple execution environments
  • allows multiple OS to run concurrently, provides isolation between environments, facilitates system development, testing, and consolidation
    • virtual machine
  • Emulation is different, you're simulating computer hardware in software which is typically used when the source CPU type is different from the target CPU type
  • Cloud Computing: major form of virtualization where resources are delivered as a service over a network

Distributed Systems

  • collection of separate, networked computers that provide a unified environment
  • advantages: resource sharing, computational speedup, improved reliability
  • Networks
    • Local-Area Networks (LANs): connect computers in a small geographical area (e.g. a building)
    • Wide-Area Networks (WANs): link computers over large distances (e.g. the Internet)

Computing Environments

  • Traditional Computing: PCs connected to a network, often with local servers
  • Mobile Computing: computing on handheld devices like smartphones and tablets, which are characterized by portability, touch-screen interfaces, and specialized hardware (e.g. GPS, accelerometers)
  • Client-Server Computing: server systems satisfy requests from client systems (e.g. file servers, compute servers)
  • Peer-to-Peer Computing: (kind of a hybrid server, the trackers are like servers) all nodes are considered peers and can act as both clients and servers
  • Cloud Computing: resources are delivered as a service over a network
  • Real-Time Embedded Systems: systems with rigid time constraints, running real-time operating systems for specific tasks (e.g. car engines, industrial control systems)