Home
1Introduction
1

Chapter 1 · Midterm syllabus · Lectures 1–3

Introduction

What an operating system does, how it runs (interrupts, dual mode, timer), its process, memory and storage management, protection, virtualization, distributed systems, computing environments and open-source OSes.

← → move between slides · F full screen · M slide list

Before we start

Why this matters

Every program you have ever run asked the operating system for something: memory, a file, the screen, the CPU itself.

This chapter answers what that program is, why it is always running, and how it stays in control even when a user program misbehaves.

The ideas here — processes, memory, storage, protection — are the map for the rest of the course.

What operating systems do

What does the term operating system mean?

An operating system is “fill in the blanks”.

What about:

  • Car
  • Airplane
  • Printer
  • Washing machine
  • Toaster
  • Compiler
  • Etc.
Each of these has software that manages hardware for someone. Which of them would you call an operating system? Keep your answer in mind; the next slides give the definition.

What operating systems do

What is an operating system?

A program that acts as an intermediary between a user of a computer and the computer hardware.

Operating system 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

What operating systems do

Computer system structure

A computer system can be divided into four components:

  • Hardware – provides basic computing resources
    • CPU, memory, I/O devices
  • Operating system
    • Controls and coordinates use of hardware among various applications and users
  • Application programs – define the ways in which the system resources are used to solve the computing problems of the users
    • Word processors, compilers, web browsers, database systems, video games
  • Users
    • People, machines, other computers

What operating systems do

Computer system structure (cont.)

Abstract view of the components of a computer.

What operating systems do

What operating systems do

  • Depends on the point of view
  • Users want convenience, ease of use and good performance
    • Don’t care about resource utilization
  • But a shared computer such as a mainframe or minicomputer must keep all users happy
    • Operating system is a resource allocator and control program making efficient use of HW and managing execution of user programs
  • Users of dedicated systems such as workstations have dedicated resources but frequently use shared resources from servers
  • Mobile devices like smartphones and tablets are resource poor, optimized for usability and battery life
    • Mobile user interfaces such as touch screens, voice recognition
  • Some computers have little or no user interface, such as embedded computers in devices and automobiles
    • Run primarily without user intervention

What operating systems do

Operating system definition

  • No universally accepted definition
  • “Everything a vendor ships when you order an operating system” is a good approximation
    • But varies wildly
  • “The one program running at all times on the computer” is the kernel, part of the operating system
  • Everything else is either
    • A system program (ships with the operating system, but not part of the kernel), or
    • An application program, all programs not associated with the operating system
  • Today’s OSes for general purpose and mobile computing also include middleware – a set of software frameworks that provide additional services to application developers such as databases, multimedia, graphics

What operating systems do

Computer startup

  • Bootstrap program is loaded at power-up or reboot
    • Typically stored in ROM or EPROM, generally known as firmware
    • Initializes all aspects of system
    • Loads operating system kernel and starts execution
power on→bootstrap (firmware)→load kernel→start daemons→ready

Animated

Booting, step by step

Operating-system operations

Operating-system operations

  • Bootstrap program – simple code to initialize the system, load the kernel
  • Kernel loads
  • Starts system daemons (services provided outside of the kernel)
  • Kernel is interrupt driven (hardware and software)
    • Hardware interrupt by one of the devices
    • Software interrupt (exception or trap):
      • Software error (e.g., division by zero)
      • Request for operating system service – system call
      • Other process problems include infinite loop, processes modifying each other or the operating system

Animated

Handling an interrupt, step by step

Operating-system operations

Multiprogramming

  • Single user cannot always keep CPU and I/O devices busy
  • Multiprogramming organizes jobs (code and data) so the CPU always has one to execute
  • A subset of total jobs in system is kept in memory
  • One job selected and run via job scheduling
  • When job has to wait (for I/O for example), OS switches to another job

Operating-system operations

Multiprogramming (cont.)

Operating-system operations

Multitasking (timesharing)

A logical extension of multiprogramming – the CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing.

  • Response time should be < 1 second
  • Each user has at least one program executing in memory → process
  • If several jobs ready to run at the same time → CPU scheduling
  • If processes don’t fit in memory, swapping moves them in and out to run
  • Virtual memory allows execution of processes not completely in memory

Operating-system operations

Dual-mode operation

  • Dual-mode operation allows OS to protect itself and other system components
    • User mode and kernel mode
  • Mode bit provided by hardware
    • Provides ability to distinguish when system is running user code or kernel code
    • When a user is running → mode bit is “user”
    • When kernel code is executing → mode bit is “kernel”
  • How do we guarantee that user does not explicitly set the mode bit to “kernel”?
    • System call changes mode to kernel, return from call resets it to user
  • Some instructions designated as privileged, only executable in kernel mode

Operating-system operations

Dual-mode operation (cont.)

Transition from user to kernel mode.

Interactive

Transition from user to kernel mode

Operating-system operations

Timer

  • Timer to prevent infinite loop (or process hogging resources)
    • Timer is set to interrupt the computer after some time period
    • Keep a counter that is decremented by the physical clock
    • Operating system sets the counter (privileged instruction)
    • When counter reaches zero generate an interrupt
    • Set up before scheduling process to regain control or terminate program that exceeds allotted time
Without a timer, a user program in an infinite loop would never give the CPU back, because the OS only runs when an interrupt or system call happens.

Process management

Process management

  • A process is a program in execution. It is a unit of work within the system. Program is a passive entity; process is an active entity.
  • Process needs resources to accomplish its task
    • CPU, memory, I/O, files
    • Initialization data
  • Process termination requires reclaim of any reusable resources
  • Single-threaded process has one program counter specifying location of next instruction to execute
    • Process executes instructions sequentially, one at a time, until completion
  • Multi-threaded process has one program counter per thread
  • Typically system has many processes, some user, some operating system running concurrently on one or more CPUs
    • Concurrency by multiplexing the CPUs among the processes / threads

Process management

Process management activities

The operating system is responsible for the following activities in connection with process management:

  • Creating and deleting both user and system processes
  • Suspending and resuming processes
  • Providing mechanisms for process synchronization
  • Providing mechanisms for process communication
  • Providing mechanisms for deadlock handling

Memory management

Memory management

  • To execute a program all (or part) of the instructions must be in memory
  • All (or part) of the data that is needed by the program must be in memory
  • Memory management determines what is in memory and when
    • Optimizing CPU utilization and computer response to users
  • Memory management activities
    • Keeping track of which parts of memory are currently being used and by whom
    • Deciding which processes (or parts thereof) and data to move into and out of memory
    • Allocating and deallocating memory space as needed

Storage management

File-system management

  • OS provides uniform, logical view of information storage
    • Abstracts physical properties to logical storage unit – file
    • Each medium is controlled by device (i.e., disk drive, tape drive)
      • Varying properties include access speed, capacity, data-transfer rate, access method (sequential or random)
  • File-system management
    • Files usually organized into directories
    • Access control on most systems to determine who can access what
    • OS activities include
      • Creating and deleting files and directories
      • Primitives to manipulate files and directories
      • Mapping files onto secondary storage
      • Backup files onto stable (non-volatile) storage media

Storage management

Mass-storage management

  • Usually disks used to store data that does 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

OS activities

  • Mounting and unmounting
  • Free-space management
  • Storage allocation
  • Disk scheduling
  • Partitioning
  • Protection

Storage management

Caching

  • Important principle, performed at many levels in a computer (in hardware, operating system, software)
  • Information in use copied from slower to faster storage temporarily
  • Faster storage (cache) checked first to determine if information is there
    • If it is, information used directly from the cache (fast)
    • If not, data copied to cache and used there
  • Cache smaller than storage being cached
    • Cache management important design problem
    • Cache size and replacement policy

Storage management

Characteristics of various types of storage

Movement between levels of storage hierarchy can be explicit or implicit.

Level12345
Nameregisterscachemain memorysolid-state diskmagnetic disk
Typical size< 1 KB< 16 MB< 64 GB< 1 TB< 10 TB
Implementation technologycustom memory with multiple ports, CMOSon-chip or off-chip CMOS SRAMCMOS SRAMflash memorymagnetic disk
Access time (ns)0.25 – 0.50.5 – 2580 – 25025,000 – 50,0005,000,000
Bandwidth (MB/s)20,000 – 100,0005,000 – 10,0001,000 – 5,00050020 – 150
Managed bycompilerhardwareoperating systemoperating systemoperating system
Backed bycachemain memorydiskdiskdisk or tape

Storage management

I/O subsystem

  • 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

Security and protection

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
    • User ID then associated with all files, processes of that user to determine access control
    • Group identifier (group ID) allows set of users to be defined and controls managed, then also associated with each process, file
    • Privilege escalation allows user to change to effective ID with more rights

Virtualization

Virtualization

  • Allows operating systems to run applications within other OSes
    • Vast and growing industry
  • Virtualization – OS natively compiled for CPU, running guest OSes also natively compiled
    • Consider VMware running WinXP guests, each running applications, all on native WinXP host OS
    • VMM (virtual machine manager) provides virtualization services
  • Use cases involve laptops and desktops running multiple OSes for exploration or compatibility
    • 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

Virtualization

Virtualization (cont.)

Computing environments – virtualization.

Distributed systems

Distributed systems

  • Collection of separate, possibly heterogeneous, systems networked together
    • Network is a communications path, TCP/IP most common
      • Local Area Network (LAN)
      • Wide Area Network (WAN)
      • Metropolitan Area Network (MAN)
      • Personal Area Network (PAN)
  • Network operating system provides features between systems across network
    • Communication scheme allows systems to exchange messages
    • Illusion of a single system

Computing environments

Computing environments

Traditional

stand-alone and networked general-purpose machines

Mobile

smartphones and tablets

Client–server

servers answer client requests

Peer-to-peer

every node is a peer

Cloud computing

computing, storage and apps as a service

Real-time embedded

fixed time constraints

Computing environments

Traditional

  • Stand-alone general-purpose machines
  • But blurred as most systems interconnect with others (i.e., the Internet)
  • Portals provide web access to internal systems
  • Network computers (thin clients) are like Web terminals
  • Mobile computers interconnect via wireless networks
  • Networking becoming ubiquitous – even home systems use firewalls to protect home computers from Internet attacks

Computing environments

Mobile

  • Handheld smartphones, tablets, etc.
  • What is the functional difference between them and a “traditional” laptop?
  • Extra feature – more OS features (GPS, gyroscope)
  • Allows new types of apps like augmented reality
  • Use IEEE 802.11 wireless, or cellular data networks for connectivity
  • Leaders are Apple iOS and Google Android

Computing environments

Client–server

  • Client–server computing
    • Dumb terminals supplanted by smart PCs
    • Many systems now servers, responding to requests generated by clients
      • Compute-server system provides an interface to client to request services (i.e., database)
      • File-server system provides interface for clients to store and retrieve files

Computing environments

Client–server (cont.)

Clients send requests over the network to a server.

Computing environments

Peer-to-peer

  • Another model of distributed system
  • P2P does not distinguish clients and servers
    • Instead all nodes are considered peers
    • May each act as client, server or both
    • Node must join P2P network
      • Registers its service with central lookup service on network, or
      • Broadcast request for service and respond to requests for service via discovery protocol
    • Examples include Napster and Gnutella, Voice over IP (VoIP) such as Skype

Computing environments

Peer-to-peer (cont.)

A peer-to-peer system.

Computing environments

Cloud computing

  • Delivers computing, storage, even apps as a service across a network
  • Logical extension of virtualization because it uses virtualization as the base for its functionality
    • Amazon EC2 has thousands of servers, millions of virtual machines, petabytes of storage available across the Internet, pay based on usage
  • Many types
    • Public cloud – available via Internet to anyone willing to pay
    • Private cloud – run by a company for the company’s own use
    • Hybrid cloud – includes both public and private cloud components
    • Software as a Service (SaaS) – one or more applications available via the Internet (i.e., word processor)
    • Platform as a Service (PaaS) – software stack ready for application use via the Internet (i.e., a database server)
    • Infrastructure as a Service (IaaS) – servers or storage available over Internet (i.e., storage available for backup use)

Computing environments

Cloud computing (cont.)

  • Cloud computing environments composed of traditional OSes, plus VMMs, plus cloud management tools
    • Internet connectivity requires security like firewalls
    • Load balancers spread traffic across multiple applications

Computing environments

Cloud computing (cont.)

A cloud computing environment.

Computing environments

Real-time embedded systems

  • Real-time embedded systems most prevalent form of computers
    • Vary considerably, special purpose, limited purpose OS, real-time OS
    • Use expanding
  • Many other special computing environments as well
    • Some have OSes, some perform tasks without an OS
  • Real-time OS has well-defined fixed time constraints
    • Processing must be done within constraint
    • Correct operation only if constraints met

Free and open-source operating systems

Free and open-source operating systems

  • Operating systems made available in source-code format rather than just binary closed-source and proprietary
  • Counter to the copy protection and Digital Rights Management (DRM) movement
  • Started by Free Software Foundation (FSF), which has “copyleft” GNU Public License (GPL)
    • Free software and open-source software are two different ideas championed by different groups of people (gnu.org/philosophy)
  • Examples include GNU/Linux and BSD UNIX (including core of Mac OS X), and many more
  • Can use VMM like VMware Player (free on Windows), VirtualBox (open source and free on many platforms – virtualbox.org)
    • Use to run guest operating systems for exploration

Worked example 1 of 2

Worked example 1

A system has one CPU and runs one job at a time. The job computes for 3 ms, waits 4 ms for the disk, computes 2 ms, waits 3 ms, computes 2 ms. What is the CPU utilization? How does multiprogramming help?
Show the solution

CPU busy time = 3 + 2 + 2 = 7 ms out of 3 + 4 + 2 + 3 + 2 = 14 ms, so utilization is 7 / 14 = 50%.

With multiprogramming, other jobs are kept in memory; whenever this job waits for the disk, the OS switches the CPU to another job, so the 7 ms of waiting can be used. Try it in the multiprogramming tool on the slide.

Worked example 2 of 2

Worked example 2

Which of these must be privileged instructions? (a) set the value of the timer, (b) read the clock, (c) clear memory, (d) turn off interrupts, (e) switch from user to kernel mode, (f) access an I/O device.
Show the solution

Privileged: (a), (c), (d), (f). A user who could set the timer or turn off interrupts could keep the CPU forever; clearing memory or touching devices directly would bypass protection.

(b) reading the clock is harmless. (e) is special: user code cannot set the mode bit itself; it switches to kernel mode only through a trap (system call), which jumps to OS code chosen by the kernel.

Practice

Practice (1 of 2)

Try each one on paper first, then check your answer.

1. What are the three goals of an operating system?
Show the answer
Execute user programs and make solving user problems easier; make the computer system convenient to use; use the computer hardware in an efficient manner.
2. Distinguish the kernel, system programs and application programs.
Show the answer
The kernel is the one program running at all times. System programs ship with the OS but are not part of the kernel. Application programs are all programs not associated with the operating system.
3. Name two kinds of software interrupt (trap).
Show the answer
A software error such as division by zero, and a request for an operating-system service (a system call). Other process problems such as infinite loops also lead the OS to step in.

Practice

Practice (2 of 2)

Try each one on paper first, then check your answer.

4. Why is a timer needed?
Show the answer
To prevent a process from looping forever or hogging resources: the OS sets a counter (privileged) that is decremented by the clock; at zero an interrupt returns control to the OS.
5. Explain the difference between multiprogramming and multitasking.
Show the answer
Multiprogramming keeps several jobs in memory so the CPU always has one to run when the current job waits. Multitasking (timesharing) switches so often that users can interact with each program; response time should be under one second.
6. Match each cloud service to an example: SaaS, PaaS, IaaS — a database server ready to use; storage for backups; a word processor in the browser.
Show the answer
SaaS: word processor in the browser. PaaS: database server ready for application use. IaaS: storage available over the Internet for backups.

Check yourself

Quiz

Summary · End of Chapter 1

Summary

  • An OS is an intermediary between users and hardware: a resource allocator and a control program.
  • The kernel runs all the time; the OS is interrupt driven, and traps carry system calls and errors.
  • Multiprogramming keeps the CPU busy; timesharing makes it interactive.
  • Dual mode (a hardware mode bit) and privileged instructions protect the OS; a timer keeps it in control.
  • The OS manages processes, memory, files, mass storage, caches and I/O, and provides protection and security.
  • Virtualization, distributed systems, cloud, mobile and real-time embedded systems are the main computing environments.