OS Note Chapter 1: Introduction

2023-03-26
3 min read

Computer-System Architecture and Organization

image-20230326下午25726009

I/O Devices: except CPU and memory

  • I/O devices and the CPU can work concurrently(同时)

CPU and Memory in Computer

  • Single processor
  • Multiple processors
  • Dual core
  • Non-Uniform Memory Access System (NUMA)

Device driver (software)

  • inside the kernel knows how to talk and manage the device
  • provides uniform interface between controller and kernel

Each device controller informs CPU that it has finished its operation by causing an interrupt.

An operating system is interrupt driven

  • Definition: An interrupt is a signal emitted by hardware or software when a process or an event needs immediate attention
    • Software: A trap or exception is a software-generated interrupt caused either by an error or a user request (system call)
    • Hardware: Device
  • ISR (Interrupt Service Routines) inside the kernel determine what action should be taken for each type of interrupt
  • The code of the kernel is in memory all the time but the code of the kernel is only executed when there is an interrupt, on demand!
  • Interrupt Handling Steps
    1. Preserves the state of the CPU by storing registers and the program counter(PC) for the software that was just interrupted (so that the same software can be restarted later).
    2. Determine type of interrupt
      • check Interrupt vector to get the address of corresponding ISR for this interrupt (used on all modern computers)
    3. Runs ISR in kernel to handle interrupt

How a Modern Computer Works: DMA

DMA (Direct Memory Access )

  • Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention
    • In the meantime the CPU can work on something else.
  • Only one interrupt is generated per block
  • High transfer speed: not byte by byte, but block by block

Operating System: intermediary(中间人) between a user and the computer hardware

image-20230326下午30147099

Definition

No universally accepted definition

Introduction to Operating System

An operating system is a program that acts as an intermediary between a user of a computer and the computer hardware.

User <— Operating System —> Computer Hardware

OS provides interface to a user, run a program for a user.

General goals

  • Execute user programs and make solving user problems easier
  • Make the computer system convenient to use
  • Use the computer hardware in an efficient manner

A definition

Everything a vendor ships when you order an operating system.

“Everything” include:

  • Kernel - part of the operating system, reside in memory at all times on the computer,
  • Others
    • system programs: all programs associated with the operating system, but not in kernel
    • application program: all programs not associated with the operating system
    • middleware(中间件): a set of software frameworks that provide additional services to application developers such as databases, multimedia, graphics

Goals

Goals Depends on computer/device types

  • User view: ease of use
  • System view: resource allocation

Personal computer

  • Feature: owned by individuals
  • OS goal: convenience, ease of use and good performance

Shared computer (e.g. mainframe or minicomputer)

  • Feature: shared by multiple users
  • OS goal: keep all happy, efficient use of Hardware and managing user programs

Mobile devices (e.g. smartphones and tablets)

  • Feature: resource poor
  • OS goal: optimized for usability and battery life, provides user interfaces such as touch screens, voice recognition

Embedded computers

  • Feature: little or no user interface
  • OS goal: run program

Operations (Operating system activities)

Operating system does a lot of management work

Caching

  • Copy information from slower into faster storage system
  • Purpose: Speed up data access

Process management

Program vs process
  • A process is a program in execution

    • program is a passive entity, on storage
    • process is an active entity, in memory
  • Process

    • creation, execution needs resources

      • CPU, memory, I/O, files
      • Initialization data
    • termination requires reclaim of any reusable resources

  • Process can be single-threaded (线程) process, or multi-threaded process

  • Each process has a program counter to specify location of next instruction to execute

Multiprogramming and Multitasking

Single process cannot always keep CPU and I/O devices busy

  • Multiprogramming: A subset of total jobs are kept in memory at the same time
    • Job scheduling: choose which jobs to load into memory and execute.
    • When job has to wait (for I/O for example), OS switches to another job
  • Multitasking: The CPU switches jobs so frequently to increase interactions with users
    • CPU scheduling: choose which job will run next If several jobs are ready to run at the same time

Secondary storage —–Job scheduling—–> memory —–CPU scheduling—–> CPU

Process Execution: Dual-mode

System call: request for operating system service

Dual-mode operation allows OS to protect itself and other system components

image-20230326下午41326060

Process Management Activities

Process management activities include:

  • Creating and deleting both user and system processes
  • Suspending and resuming processes
  • Process synchronization
  • Process communication
  • Deadlock handling

Memory management

To execute a program, all (or part) of the instructions of the program and data needed by the program must be in memory

Memory management determines what is in memory and when

Memory management activities include

  1. Keeping track of which parts of memory are currently being used and by whom
  2. Deciding which processes and data (or part of them) to move into and out of memory
  3. Allocating and de-allocating memory space as needed

File management

OS provides uniform, logical view of information storage

  • Abstracts physical properties to logical storage unit - file
  • Files are usually organized into directories
  • Access control determines who can access what
  • File system activities include
    1. Creating and deleting files and directories
    2. Mapping files onto secondary storage

Secondary storage management

Disks usually are used to store data that do not fit in main memory or data that must be kept for a “long” period of time

  • Proper management is of central importance
  • Entire speed of computer operation hinges on disk subsystem and its algorithms

Secondary storage management activities

  1. Mounting and unmounting
  2. Free-space management
  3. Storage allocation
  4. Disk scheduling
  5. Partitioning
  6. Protection

I/O

One purpose of OS is to hide peculiarities of hardware devices from the user

I/O subsystem responsible for

  • Memory management of I/O including buffering (storing data temporarily while it is being transferred), caching (storing parts of data in faster storage for performance), spooling (the overlapping of output of one job with input of other jobs)
  • General device-driver interface
  • Drivers for specific hardware devices

Protection and security

Protection

any mechanism for controlling access of processes or users to resources defined by the OS

Security

defense of the system against internal and external attacks

  • Huge range, including denial-of-service, worms, viruses, identity theft, theft of service
Systems generally first distinguish among users, to determine who can do what
  • User identities (user IDs, security IDs) include name and associated number, one per user
  • Group identifier (group ID) allows set of users to be defined

Types

Virtualization

Virtualization is a technology that allows us to abstract the hardware of a single computer into several different execution environments, thereby creating the illusion that each separate environment is running on its own private computer.

VMMs (Virtual Machine Managers)

Run natively, no longer run on host operating systems but rather are the host operating systems, providing services and resource management to virtual machine processes.

Examples: VMware ESX and Citrix XenServer

Virtualization Examples

  • Use cases
    • Apple laptop running Mac OS X host, Windows as a guest
    • Developing apps for multiple OSes without having multiple systems
    • Quality assurance testing applications without having multiple systems
    • Executing and managing compute environments within data centers

Operating System Examples

Commercial Operating Systems

  • Windows
  • MacOS

Free and Open Operating Systems

  • Examples
    • GNU/Linux and BSD UNIX (including core of Mac OS X), and many more
    • VMM like VMware Player (Free on Windows), Virtualbox (open source and free on many platforms - http://www.virtualbox.com)

Main Data Structures Used in OS

  • Singly linked list
  • Doubly linked list
  • Circular linked list
  • Binary search tree
  • Hash function can create a hash map
Avatar

Kirin

Technology is elegant and charismatic.