Download Operating Systems [OS]

Document related concepts

Berkeley Software Distribution wikipedia , lookup

Acorn MOS wikipedia , lookup

Library (computing) wikipedia , lookup

Mobile operating system wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

DNIX wikipedia , lookup

OS 2200 wikipedia , lookup

Copland (operating system) wikipedia , lookup

Security-focused operating system wikipedia , lookup

Burroughs MCP wikipedia , lookup

RSTS/E wikipedia , lookup

Windows NT startup process wikipedia , lookup

Booting wikipedia , lookup

Distributed operating system wikipedia , lookup

Spring (operating system) wikipedia , lookup

Process management (computing) wikipedia , lookup

Paging wikipedia , lookup

VS/9 wikipedia , lookup

Unix security wikipedia , lookup

CP/M wikipedia , lookup

Transcript
Distributed Embedded
Systems Group – CCS
Operating Systems [OS]
Falko Dressler
n
1
Introduction
Operating Systems - Introduction
What is an Operating System?
n
A program that acts as an intermediary between a user of a computer and
the computer hardware
n
Operating system goals:
2
n
Execute user programs and make solving user problems easier
n
Make the computer system convenient to use
n
Use the computer hardware in an efficient manner
Operating Systems - Introduction
Popular Operating Systems
n
UNIX
n
MS-DOS
n
Windows
n
BSD
n
Linux
n
MAC OS
3
Operating Systems - Introduction
DEC PDP-7 (~1969)
• 18-bit processor
• US$ 72,000
• 8 kB for UNIX OS
• 16 kB for applications
History of UNIX
4
Operating Systems - Introduction
Other Operating Systems
n
TinyOS
n
Contiki
n
OSEK OS
n
Sloth
n
RTOS
n
QNX
5
Operating Systems - Introduction
Computer System Structure
n
Computer system can be divided into
four components:
n
Hardware – provides basic computing
resources
n
n
Operating system
n
n
Word processors, compilers, web browsers, database systems, video games
Users
n
6
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
n
n
CPU, memory, I/O devices
People, machines, other computers
Operating Systems - Introduction
Operating System Definition
n
n
OS is a resource allocator
n
Manages all resources
n
Decides between conflicting requests for efficient and fair resource use
OS is a control program
n
7
Controls execution of programs to prevent errors and improper use of the
computer
Operating Systems - Introduction
Computer-System Operation
n
I/O devices and the CPU can execute concurrently
n
Each device controller is in charge of a particular device type
n
Each device controller has a local buffer
n
CPU moves data from/to main memory to/from local buffers
n
I/O is from the device to local buffer of controller
n
Device controller informs CPU that it has finished its operation by causing
an interrupt
8
Operating Systems - Introduction
Common Functions of Interrupts
n
Interrupt transfers control to the interrupt service routine generally,
through the interrupt vector, which contains the addresses of all the
service routines
n
Interrupt architecture must save the address of the interrupted instruction
n
A trap or exception is a software-generated interrupt caused either by an
error or a user request
n
An operating system is interrupt driven
9
Operating Systems - Introduction
Interrupt Handling
n
The operating system preserves the state of the CPU by storing registers
and the program counter
n
Determines which type of interrupt has occurred:
n
n
polling
n
vectored interrupt system
Separate segments of code determine what action should be taken for
each type of interrupt
10 Operating Systems - Introduction
I/O Semantics
n
n
Synchronous I/O or blocking I/O
n
After the I/O request is submitted with a system call, control returns to user
program only upon I/O completion
n
At most one I/O request is outstanding at a time, no simultaneous I/O
processing
Asynchronous I/O or non-blocking I/O
n
After I/O request is submitted, control returns to user program without waiting
for I/O completion
n
Polling
n
Signal
n
Callback function
11 Operating Systems - Introduction
How a Modern Computer Works
A von Neumann architecture
12 Operating Systems - Introduction
Computer-System Architecture
n
Most systems use a single general-purpose processor
n
n
Most systems have special-purpose processors as well
Multiprocessors systems growing in use and importance
n
Also known as parallel systems, tightly-coupled systems
n
Advantages include:
n
n
Increased throughput
n
Economy of scale
n
Increased reliability – graceful degradation or fault tolerance
Two types:
n
Asymmetric Multiprocessing – each processor is assigned a specific
task
n
Symmetric Multiprocessing – each processor performs all tasks
13 Operating Systems - Introduction
Clustered Systems
n
Like multiprocessor systems, but multiple systems working together
n
Usually sharing storage via a storage-area network (SAN)
n
Provides a high-availability service which survives failures
n
n
Asymmetric clustering has one machine in hot-standby mode
n
Symmetric clustering has multiple nodes running applications,
monitoring each other
Some clusters are for high-performance computing (HPC)
n
n
Applications must be
written to use parallelization
computer
interconnect
computer
Some have distributed lock
manager (DLM) to avoid
conflicting operations
storage area
network
14 Operating Systems - Introduction
interconnect
computer
Multiple Programs
n
Multiprogramming (Batch system) needed for efficiency
n
Single user cannot keep CPU and I/O devices busy at all times
n
Multiprogramming organizes jobs (code and data) so CPU always has one to
execute
n
A subset of total jobs in system is kept in memory
n
One job selected and run via job scheduling
n
When it has to wait (for I/O for example), OS switches to another job
15 Operating Systems - Introduction
Multiple Programs
n
Timesharing (multitasking) is logical extension in which CPU switches
jobs so frequently that users can interact with each job while it is running,
creating interactive computing
n
Response time should be < 1 second
n
Each user has at least one program executing in memory [process
n
If several jobs ready to run at the same time [ CPU scheduling
n
If processes don’t fit in memory, swapping moves them in and out to run
n
Virtual memory allows execution of processes not completely in memory
16 Operating Systems - Introduction
Multiple Programs
n
Interrupt driven (hardware and software)
n
Hardware interrupt by one of the devices
n
Software interrupt (exception or trap):
n
Software error (e.g., division by zero)
n
Request for operating system service
n
Other process problems include infinite loop, processes modifying each
other or the operating system
17 Operating Systems - Introduction
Operating-System Operations (cont.)
n
n
Dual-mode operation allows OS to protect itself and other system
components
n
User mode and kernel mode
n
Mode bit provided by hardware
n
Provides ability to distinguish when system is running user code or
kernel code
n
Some instructions designated as privileged, only executable in kernel
mode
n
System call changes mode to kernel, return from call resets it to user
Increasingly CPUs support multi-mode operations
n
I.e., virtual machine manager (VMM) mode for guest VMs
18 Operating Systems - Introduction
Transition from User to Kernel Mode
n
Timer to prevent infinite loop / process hogging resources
n
Timer is set to interrupt the computer after some time period
n
Keep a counter that is decremented by the physical clock.
n
Operating system set the counter (privileged instruction)
n
When counter zero generate an interrupt
n
Set up before scheduling process to regain control or terminate program that
exceeds allotted time
19 Operating Systems - Introduction
Process Management
n
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.
n
Process needs resources to accomplish its task
n
CPU, memory, I/O, files
n
Initialization data
n
Process termination requires reclaim of any reusable resources
n
Single-threaded process has one program counter specifying location of
next instruction to execute
n
Process executes instructions sequentially, one at a time, until completion
n
Multi-threaded process has one program counter per thread
n
Typically system has many processes, some user, some operating
system running concurrently on one or more CPUs
n
Concurrency by multiplexing the CPUs among the processes / threads
20 Operating Systems - Introduction
Process Management Activities
The operating system is responsible for the following activities in connection
with process management:
n
Creating and deleting both user and system processes
n
Suspending and resuming processes
n
Providing mechanisms for process synchronization
n
Providing mechanisms for process communication
n
Providing mechanisms for deadlock handling
21 Operating Systems - Introduction
Memory Management
n
To execute a program all (or part) of the instructions must be in memory
n
All (or part) of the data that is needed by the program must be in memory.
n
Memory management determines what is in memory and when
n
n
Optimizing CPU utilization and computer response to users
Memory management activities
n
Keeping track of which parts of memory are currently being used and by
whom
n
Deciding which processes (or parts thereof) and data to move into and out of
memory
n
Allocating and deallocating memory space as needed
22 Operating Systems - Introduction
Storage Management
n
OS provides uniform, logical view of information storage
n
Abstracts physical properties to logical storage unit - a file
n
Each medium is controlled by device (i.e., disk drive, tape drive)
n
n
Varying properties include access speed, capacity, data-transfer rate, access
method (sequential or random)
File-System management
n
Files usually organized into directories
n
Access control on most systems to determine who can access what
n
OS activities include
n
Creating and deleting files and directories
n
Primitives to manipulate files and directories
n
Mapping files onto secondary storage
n
Backup files onto stable (non-volatile) storage media
23 Operating Systems - Introduction
Caching
n
Important principle, performed at many levels in a computer (in hardware,
operating system, software)
n
Information in use is copied from slower to faster storage temporarily
n
Faster storage (cache) checked first to determine if information is there
n
n
If it is, information used directly from the cache (fast)
n
If not, data is copied to cache and used there
Cache smaller than storage being cached
n
Cache management important design problem
n
Cache size and replacement policy
24 Operating Systems - Introduction
Protection and Security
n
Protection – any mechanism for controlling access of processes or users
to resources defined by the OS
n
Security – defense of the system against internal and external attacks
n
n
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
n
User identities (user IDs, security IDs) include name and associated number,
one per user
n
User ID then associated with all files, processes of that user to determine
access control
n
Group identifier (group ID) allows set of users to be defined and controls
managed, then also associated with each process, file
n
Privilege escalation allows user to change to effective ID with more rights
25 Operating Systems - Introduction
OS Organization: The Big Picture
n
System services
n
System calls
n
System programs
26 Operating Systems - Introduction
System Objectives
n
n
User goals and system goals
n
User goals – operating system should be convenient to use, easy to learn,
reliable, safe, and fast
n
System goals – operating system should be easy to design, implement, and
maintain, as well as flexible, reliable, error-free, and efficient
Important principle to separate
n
Policy: What will be done? How to reach the goal?
n
Mechanism: How to do it?
n
Mechanisms determine how to do something, policies decide what will be
done.
n
The separation of policy from mechanism allows maximum flexibility if
policy decisions are to be changed later
27 Operating Systems - Introduction
Operating System Services
n
Operating systems provide an environment for execution of programs and
services to programs and users
n
One set of operating-system services provides functions that are helpful
to the user:
n
User interface – Almost all operating systems have a user interface (UI)
n
Command-Line (CLI), Graphics User Interface (GUI), Batch
n
Program execution – The system must be able to load a program into
memory and to run that program, end execution, either normally or
abnormally (indicating error)
n
I/O operations – A running program may require I/O, which may involve a file
or an I/O device
28 Operating Systems - Introduction
Operating System Services (Cont.)
n
One set of operating-system services provides functions that are helpful
to the user (Cont.):
n
File-system manipulation – The file system is of particular interest;
programs need to read and write files and directories, create and delete
them, list file Information, manage
n
Communications – Processes may exchange information, on the same
computer or between computers over a network
n
n
Communications may be via shared memory or through message
passing (packets moved by the OS)
Error detection – OS needs to be constantly aware of possible errors
n
May occur in CPU and memory, in I/O devices, in user program
n
For each type of error, OS should take the appropriate action to ensure
correct and consistent computing
n
Debugging facilities can greatly enhance the user’s and programmer’s
abilities to efficiently use the system
29 Operating Systems - Introduction
Operating System Services (Cont.)
n
Another set of OS functions ensures the efficient operation of the system
itself via resource sharing
n
Resource allocation – When multiple users or multiple jobs rung
concurrently, resources must be allocated to each of them
n
Many types - CPU cycles, main memory, file storage, I/O devices
n
Accounting – To keep track of which users use how much and what kinds of
computer resources
n
Protection and security – The owners of information stored in a multiuser or
networked computer system may want to control use of that information,
concurrent processes should not interfere with each other
n
Protection involves ensuring that all access to system resources is
controlled
n
Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access attempts
30 Operating Systems - Introduction
System Calls
n
Programming interface to the services provided by the OS
n
Typically written in a high-level language (C or C++)
n
Mostly accessed by programs via a high-level Application
Programming Interface (API) rather than direct system call use
n
Three most common APIs are Win32 API for Windows, POSIX API for
POSIX-based systems (including virtually all versions of UNIX, Linux, and
Mac OS X), and Java API for the Java virtual machine (JVM)
31 Operating Systems - Introduction
Example of System Calls
n
System call sequence to copy the contents of one file to another file
32 Operating Systems - Introduction
Example of Standard API
33 Operating Systems - Introduction
System Call Implementation
n
Typically, a number associated with each system call
n
System-call interface maintains a table indexed according to these numbers
n
The system call interface invokes the intended system call in OS kernel
and returns status of the system call and any return values
n
The caller need know nothing about how the system call is implemented
n
Just needs to obey API and understand what OS will do as a result call
n
Most details of OS interface hidden from programmer by API
n
Managed by run-time support library (set of functions built into libraries
included with compiler)
34 Operating Systems - Introduction
API – System Call – OS Relationship
35 Operating Systems - Introduction
System Call Parameter Passing
n
Often, more information is required than simply identity of desired system
call
n
n
Exact type and amount of information vary according to OS and call
Three general methods used to pass parameters to the OS
n
Simplest: pass the parameters in registers
n
n
In some cases, may be more parameters than registers
Parameters stored in a block, or table, in memory, and address of block
passed as a parameter in a register
n
This approach is taken by Linux and Solaris
n
Parameters placed, or pushed, onto the stack by the program and popped
off the stack by the operating system
n
Block and stack methods do not limit the number or length of parameters
being passed
36 Operating Systems - Introduction
Parameter Passing via Table
37 Operating Systems - Introduction
Types of System Calls
n
Process control
n
create process, terminate process
n
end, abort
n
load, execute
n
get process attributes, set process attributes
n
wait for time
n
wait event, signal event
n
allocate and free memory
n
Dump memory if error
n
Debugger for determining bugs, single step execution
n
Locks for managing access to shared data between processes
38 Operating Systems - Introduction
Types of System Calls
n
n
File management
n
create file, delete file
n
open, close file
n
read, write, reposition
n
get and set file attributes
Device management
n
request device, release device
n
read, write, reposition
n
get device attributes, set device attributes
n
logically attach or detach devices
39 Operating Systems - Introduction
Types of System Calls (Cont.)
n
n
Information maintenance
n
get time or date, set time or date
n
get system data, set system data
n
get and set process, file, or device attributes
Communications
n
create, delete communication connection
n
send, receive messages if message passing model to host name or process
name
n
From client to server
n
Shared-memory model create and gain access to memory regions
n
transfer status information
n
attach and detach remote devices
40 Operating Systems - Introduction
Types of System Calls (Cont.)
n
Protection
n
Control access to resources
n
Get and set permissions
n
Allow and deny user access
41 Operating Systems - Introduction
Examples of Windows and Unix System Calls
42 Operating Systems - Introduction
Standard C Library Example
n
C program invoking printf() library call, which calls write() system call
43 Operating Systems - Introduction
Tasks in Memory: Example MS-DOS
n
Single-tasking
n
Shell invoked when system booted
n
Simple method to run program
n
No process created
n
Single memory space
n
Loads program into memory,
overwriting all but the kernel
n
Program exit -> shell reloaded
At system startup
44 Operating Systems - Introduction
running a program
Tasks in Memory: Example FreeBSD
n
UNIX variant
n
Multitasking
n
User login -> invoke user’s choice of shell
n
Shell executes fork() system call to create
process
n
n
Executes exec() to load program into process
n
Shell waits for process to terminate or
continues with user commands
Process exits with:
n
code = 0 – no error
n
code > 0 – error code
45 Operating Systems - Introduction
Implementation
n
n
n
Much variation
n
Early OSes in assembly language
n
Then system programming languages like Algol, PL/1
n
Now C, C++
Actually usually a mix of languages
n
Lowest levels in assembly
n
Main body in C
n
Systems programs in C, C++, scripting languages like Perl, Python, shell
scripts
More high-level language easier to port to other hardware
n
n
But slower
Emulation can allow an OS to run on non-native hardware
46 Operating Systems - Introduction
Operating System Structure
n
General-purpose OS is very large program
n
Various ways to structure ones
n
Simple structure – MS-DOS
n
More complex – UNIX
n
Layered – an abstraction
n
Microkernel – Mach
47 Operating Systems - Introduction
Traditional UNIX System Structure
Beyond simple but not fully layered
48 Operating Systems - Introduction
Microkernel System Structure
n
Moves as much from the kernel into user space
n
Mach example of microkernel
n
Mac OS X kernel (Darwin) partly based on Mach
n
Communication takes place between user modules using message
passing
n
Benefits:
n
n
Easier to extend a microkernel
n
Easier to port the operating system to new architectures
n
More reliable (less code is running in kernel mode)
n
More secure
Detriments:
n
Performance overhead of user space to kernel space communication
49 Operating Systems - Introduction
Microkernel System Structure
Application
Program
File
System
messages
Interprocess
Communication
user
mode
messages
memory
managment
microkernel
hardware
50 Operating Systems - Introduction
Device
Driver
CPU
scheduling
kernel
mode
System Boot
n
When power initialized on system, execution starts at a fixed memory
location
n
n
Firmware ROM used to hold initial boot code
Operating system must be made available to hardware so hardware can
start it
n
Small piece of code – bootstrap loader, stored in ROM or EEPROM locates
the kernel, loads it into memory, and starts it
n
Sometimes two-step process where boot block at fixed location loaded by
ROM code, which loads bootstrap loader from disk
n
Common bootstrap loader, GRUB, allows selection of kernel from multiple
disks, versions, kernel options
n
Kernel loads and system is then running
51 Operating Systems - Introduction
System Boot
System start
Jump via RESET vector or
to a fixed address
Start BIOS, firmware, or OS
in ROM
Copy data segments,
initialize BSS
Jump via RESET vector or
to a fixed address
Failure
Initialize (and test) hardware
Failure
System stopped
OS loaded from ROM
BIOS
Search for bootable media,
load and start OS
OS loaded
52 Operating Systems - Introduction
OS started
Implementing
a FSSystem
on Disk
Boot
Loader on File
n
n
n
Possible
layoutper
perpartition
partition
Possible
FSFS
layout
Sector
of disk
= MBR
Sector
0 of0 disk
= MBR
Bootinfo
info(if(ifPC
PCisisbooting,
booting, BIOS
BIOS reads
n Boot
readsand
andexecutes
executesMBR)
MBR)
Diskpartition
partitioninfo
info
n Disk
Sector
of partition
volumeboot
bootrecord
record
Sector
0 of0 partition
is is
volume
File-System Organization ····················································································· Virtual File Systems
53 Operating
- Introduction
ImplementingSystems
File Systems
Implementing Files · Implementing Directories · UNIX File System Structure · Logical and Physical Filesystem
Boot Process – PC with Boot Sector
n
PC BIOS loads first block (512 Byte) from the boot medium to address
0x7c00
n
Blind jump to this address
n
FAT32 boot record
Offset
Description
0x0000
jmp boot; nop
0x0003
OEM name
0x000b
Bytes per sector
0x000d
Sectors per cluster
…
0x005a
boot: executable code
0x01fe
boot record signature (0x55aa)
54 Operating Systems - Introduction
Boot Manager
n
Task: load actual OS
n
Examples:
n
n
n
GRUB (Grand Unified Boot Loader)
n
LILO (Linux Loader)
n
U-Boot (used on embedded devices)
Boot loader has size constraints (512 bytes)
n
à Reduced functionality
n
à Use multiple stages
Boot loader executes boot manager
n
n
Drivers for
n
Network boot
n
File system
Graphical interface
55 Operating Systems - Introduction
BIOS Successor: UEFI
BIOS
UEFI
56 Operating Systems - Introduction
UEFI
n
Unified Extensible Firmware Interface
n
Goal: Create a successor to BIOS
n
n
Created for 32 and 64 bit architectures
n
n
No restrictions on running in 16bit 8086 mode with 20bit addressing
Including Macs, which also have BIOS support for Windows
Preserved from BIOS:
n
Power management (Advanced Configuration & Power Interface, ACPI)
n
System management components from the BIOS
57 Operating Systems - Introduction
UEFI
n
Support for larger disks
n
BIOS only supported 4 partitions per disk, each up to 2.2 TB per partition
n
UEFI supports max partition size of 9.4 ZB (9.4×10e21 bytes)
n
Pre-boot execution environment with direct access to all memory
n
Device drivers, including the ability to interpret architecture-independent
EFI Byte Code
n
Boot manager: lets you select and load an OS
n
n
No need for a dedicated boot loader (but they may be present anyway)
n
Stick your files in the EFI boot partition and EFI can load them
Extensible: extensions can be loaded into non-volatile memory
58 Operating Systems - Introduction
UEFI Booting
n
No need for MBR code (ignore block 0)
n
Read GUID Partition Table (GPT)
n
n
UEFI understands Microsoft FAT file systems
n
n
n
Describes layout of the partition table on a disk (blocks 1-33)
Apple’s UEFI knows HFS+ in addition
Read programs stored as files in the EFI System Partition:
n
Windows Boot Manager (BOOTMGR) is in the EFI partition
n
NT (IA-64): IA64ldr
n
Linux: elilo.efi (ELILO = EFI Linux Boot Loader)
n
OS X: boot.efi
Secure Boot (boot/execute only correctly singed binaries)
59 Operating Systems - Introduction
Summary (What do I need to know)
n
n
n
Conceptual organization of operating systems
n
Macro vs micro kernel
n
Process to memory mapping
User and kernel mode
n
System call interface
n
Data transfer
Boot process
n
MBR, boot sector
n
Boot loader
n
UEFI
60 Operating Systems - Introduction