Introduction to Operating
Systems
Jakub Olejnik
These slides are a much inexact translation of the material
available at [Link]
The authors of the original slides were kind enough to share
their files with me thus help me in translation.
Literature
Lecture
• A. Silberschatz „Operating Systems Concepts”
• A. Tanenbaum „Modern Operating Systems”
• webpage (in polish) – the OS section
[Link]
Laboratory classes
• C. Newham, B. Rosenblatt „Learning the bash
shell”
• Unix/Linux manual pages
Basic Concepts of Operating
Systems
Lecture 1
What’s in this lecture?
• Definition of an Operating System, its place
and its role in computer system.
• What kind of Operating Systems are there?
• Operating Systems Concepts – how do the
OS’s work?
What is an Operating System?
A definition
An Operating System is a set of computer
programs which operate the computer’s
devices directly and whose task is to present
to a user an unified environment for writing
and running programs in an convenient and
efficient way.
thus…
An OS is a proxy between the user programs and
the actual hardware.
User and his programs
virtual machine API
Operating System
drivers
Actual Hardware
Structure of an Operating System
There are basicaly three types of OS’
components i.e.:
graphical or text-based
shells
The operating system
system programs: `CD’
commands, adm consoles
Kernel modules
hardware
The Tasks of Operating System
• Defining the user interface (shell)
• Providing a file system
• Providing environment to run user programs
– mechanisms of actual code execution, safety.
– mechanisms of process synchronization, communication
• Managing the I/O devices
• Providing procedures for handling basic errors
Re s o u rc e M a n a ge m e nt
Resource Management
Re s o u rc e – any software or hardware component
essential to processing
• Resource allocation – assigning resources to processes
• Resource allocation planning – choosing optimal
allocation strategy
• Access authorization and resource protection –
restricting resource access in accordance with permissions
granted
• Resource recycling – managing reusable resources
• Accounting – maintaining access register
Resources managed by Operating System
• Processor – each program gets a chance to be executed
• Memory
– allocation of memory space to processes
– memory protection and address transformation
• I/O devices
– providing access to keyboards, mice, mass storage devices,
printers, scanners, plotters etc.
• Information (file system)
– organizing information on disks, providing access
– protection and access authorization
Basic classification of Operating Systems
OS’s classified with respect to processing
• Interactive Systems (on-line systems)
– users directly interact with operating system
– task execution starts immediately after submission
• Common OS’s serve as examples
• Batch Systems (off-line systems)
– task execution can be delayed
– users can not interfere with task execution after their task
has been submitted
• Not many examples of pure off-line systems
• Partial examples include: mainframes, job scheduling, print
spooling, bulk transaction processing eg. ELIXIR
Batch System – a historical example
Early batch system
– Programmers bring cards to 1401
– Operator reads cards onto tape
– puts tape on 7094 which does computing
– puts tape on 1401 which prints output
OS’s classified with respect to number of
programs executed
• Single-tasking systems
– it is not possible to start a new user program until previous
task has finished
– Examples: the well-known MS-DOS and many earlier OS’s
• Multi-tasking/Multiprogramming systems
– Multiple can be executed `at the same time’
– OS’s provides mechanism of context switching to time-
share the CPU
– Basic strategies:
pre-emptive, co-operative multitasking, real-time systems
OS’s classified with respect to number of users
supported
• Single-user systems
– all of computer’s resources are accessed by only one user
thus mechanisms of protection and authorization are not
necessary
– Examples: MS-DOS, AmigaOS, Win95/98, WinXP home ed. – in a way.
• Multi-user systems
– Many users can access computer’s resources thus
mechanisms of protection and authorization are vital
– Examples: UNIX, Linux, Windows server families
Other types of OS’s
• Real-time operating systems
• Distributed (network) systems
• Server, Mainframe systems
• PC systems
• Multiprocessor systems
• Embedded systems
• Smart card systems
How does an Operating System work?
Von Neumann architecture
• Instruction codes as well as operands (args to instr.)
are stored in the memory
• Instructions are executed in the order in which they
are located in memory
• Memory location of next command is stored in PC/IP
• The order of instruction execution can be changed by
flow control instructions (jumps, cond. jumps by
PC:=PC + label)
• After instruction execution the instruction *(PC) is
loaded, decoded and PC:=PC + length(*PC)
Instruction cycle in detail – 1
• Instruction cycle (FDX-cycle) – the sequence of
actions that the processor (CPU) performs to execute
each machine code instruction in a program.
• Instruction cycle consists of phases.
• Typical phases of FDX-cycle are
– instruction loading phase – memory is read
– operand loading phase – memory is read
– instruction execution phase
– operand storing phase – memory is written
Instruction cycle in detail – 2
1. Fetch the instruction – PC is presented on address bus,
instruction code is read from data bus to CIR
2. Instruction is decoded by decoding unit
3. Fetch operands – Operand's effective address is fetched from
memory (optionally), the operand itself is fetched
4. Execution
5. Store results – Operand is stored in the memory
6. Check for interrupts
if an interrupt has been raised its number (source) is identified and the
context is switched to appropriate interrupt handle routine
if no interrupt has been raised go to 1.
Modern CPUs
Nowadays, processors implement mechanisms to
speed up the instruction cycle:
• Pipelines
– when one instruction is being decoded why not fetch the
next one
• Superscalar execution
– why not have more execution units
• Multithreading
– multiple threads parallelism
• Multi-core CPUs
– multithreading without sharing computing unit, CPU
cashe, TLB
Interrupts
An interrupt is a state of computer system in reaction
to an asynchronous event (an event which happens
independently of processing and its precise moment of
occurrence cannot be predicted) .
It consists in the processor automatically saving its
state of execution (context switch), and starting
execution of an interrupt handler.
Sources of Interrupts
• External interrupts – raised by external devices
• Software interrupts – raised by executed program
with special instruction (interrupt call)
• Diagnostic interrupts (exception handling) – raised to
handle an exceptional state of processing:
– traps
– software errors e.g..: division by 0, memory protection violation,
incorrect instruction; OS’s kernel removes the faulty process
– hardware errors e.g..: segmentation fault
Basics of OS’s operation
• The OS’s kernel is called by the use interrupts, in this
respect the kernel is a set of int. handlers and related procs.
• Hardware memory protection
• At least two CPU modes: (user mode, kernel mode)
• A set of privileged instructions is available only in the
kernel mode
• the I/O instructions are privileged
• a clock generates clock interrupts at constant
intervals of time, so that periodically the kernel regains
control
Interrupts in the layer cake
user software
program interrupt
external
interrupt
Operating System
machine code
diagnostic
interrupt
microarchitecture
Hardware memory protection example
• Executed program address
makes reference to
a specific location
in memory
• Memory chunks >= BASE
which are available
to the program are
described by two fault
registers: BASE and
LIMIT < +
LIMIT
memory is accessed
Scheduling by clock interrupts
• Kernel regains control by clock interrupts
• A clock interrupt (typically once per 10ms) runs a
kernel procedure which chooses a program to be
executed in turn
• In single-tasking systems user programs (or viruses)
sometimes modified the clock interrupt handler to
emulate ‘double-tasking’.