Chapter 1 Introduction. 2 Outline What is an operating system? History of operating systems...
-
Upload
roy-gardner -
Category
Documents
-
view
220 -
download
2
Transcript of Chapter 1 Introduction. 2 Outline What is an operating system? History of operating systems...
2
Outline
• What is an operating system?
• History of operating systems
• Categories of operating systems
• Computer hardware review
• Operating system concepts
• System calls
• Operating system structure
3
Computer As A Complex System
• Many resources– Hardware: processors, memory, disks, printers,
keyboard, display, network interfaces, …– Software: office tools, multimedia players, …
• Many tasks– Surfing web, handling emails, solving equations,
playing music, …
• Many users– Playing with computer should be easy
4
Read From Diskette …
• Basic commands: read and write– 13 parameters, packed into 9 bytes
• Controller chips– 23 status and error field
• Motor switch: on/off– Don’t leave motor on too long!
• Do you want to program the hardware directly?– A simpler interface is needed!
5
Why A Simple Interface Possible?
• Many tedious details can be handled by default– They are out of the user’s interest
• Only some key features are important– Examples: file name, length of the file, etc
• A simple interface– Present key features to programmer– Hide many tedious details– Meet requirements from many programs
6
OS As An Extended Machine
• Extended machine/virtual machine– Easier to program than the underlying hardware– Provide a variety of services (system calls)
• Trade-off– Higher efficiency in program development and
system management– Less efficiency in program execution
7
Programs Without Coordination
• Three programs want to output to a printer– A chaos if no coordination
• How to coordinate?– Buffer outputs on disk– Copy complete outputs to printer one by one
• Do you want to coordinate everything in a computer system?– A resource manager is needed!
8
OS As A Resource Manager
• Multiplexing (sharing) resources– In time
• Users/programs take turns using resources• CPU, printers, etc.
– In space• Users/programs get parts of resources• Main memory, disk, etc.
• Issues about a good manager– Fairness, efficiency, protection, …
9
What Is An Operating System?Provide user programs with a simpler interface
Manage resources
Banking system
Airline reservation
Web browser
Application programs
Compilers EditorsCommand interpreter System
programsOperating system
Machine language
HardwareMicroarchitecture
Physical devices
10
Outline
• What is an operating system?
• History of operating systems
• Categories of operating systems
• Computer hardware review
• Operating system concepts
• System calls
• Operating system structure
11
History of Operating Systems
• OS and architecture of computers– Computer evolves so does OS– To provide better service OS has impact on
computer design
• Keep evolving through years– Four generations so far
12
The First Generation Computer
• Vacuum tubes and plugboards– 1944-1955
• Applications: – Straightforward numerical calculations
• Scenario– Single group of people designed, built,
programmed, operated and maintained a machine
– All in absolute machine language• No operating system
– The people maintaining the computers are OS?!
13
The Second Generation OS
• Transistors and batch systems– 1955-1965
• Applications– Scientific and engineering calculation
IBM 1401 IBM 7094 IBM 1401
Cards from programmers
Read batch of jobs onto tape
Input tape
Do computing
Output tape
Print out
14
Ancestor of Today’s OS
• Scenario: batch systems– Fortran
• Operating system– Read a job from tape run the job write
output onto a second tape
– Load next job
• Examples: – FMS, IBSYS
15
The Third Generation OS
• Features: ICs and multiprogramming– 1965-1980
• Applications– Numerical calculations in science & engineering
• Word-oriented, large-scale scientific computers
– Massive commercial data processing• Character-oriented, commercial computers
– Can we solve both problems at a single stroke?
16
System/360 and OS/360
• One family
– A series of software-compatible machines
– Different only in price and performance
– Capable of both scientific & commercial apps
• Problems
– Dinosaurs: huge operating systems
– Millions of instructions, thousands of developers
17
Key Advances in 3rd Gen OS
• Multiprogramming– Run job 2 while job 1 waiting for I/O– Keep CPU busy
• Spooling– Read job from cards to disk asap– Load new jobs from disk whenever old job done
• Time sharing– CPU is allocated in turn
18
Milestones
• IBM OS/360• M.I.T. CTSS• M.I.T. MULTICS• Ken Thompson UNIX
– AT&T UNIX System V– UC Berkeley UNIX BSD– IEEE POSIX– Andrew S. Tanenbaum MINIX– Linus Torvalds Linux
19
The Fourth Generation OS
• Personal computers– 1980-now– An individual has her own computer
• Milestones– Kildall CP/M for Intel 8080, Z80– MS-DOS/BASIC for IBM PC– Engelbart GUI– MS Windows, Windows NT– UNIX X Windows– Network & distributed operating systems
20
Outline
• What is an operating system?
• History of operating systems
• Categories of operating systems
• Computer hardware review
• Operating system concepts
• System calls
• Operating system structure
21
Categories of Operating Systems
• Mainframe operating systems
• Server operating systems
• Multiprocessor operating systems
• Personal computer operating systems
• Real-time operating systems
• Embedded operating systems
• Smart card operating systems
22
Mainframe Operating Systems
• Why mainframe computers– Strong I/O capability, e.g., 1000 disks, TB space– High-end servers
• Features of OS– Batch– Transaction processing– Timesharing
• Example: IBM OS/390
23
Server Operating Systems
• Hardware platforms– Very large personal computers or workstations
• Services– Printing– File accessing– Web
• Examples– UNIX, Windows 2000, Linux
24
Multiprocessor Operating Systems
• Multiple CPUs within a single system– Parallel computers: loosely coupled– Multi-computers: tightly coupled– Multiprocessors: share memory
• Features of OS– Communications and connectivity– Variations of the server operating systems
25
Personal Computer OS
• Good interface to a single user– Word processing, spreadsheets, internet
access, …
• Examples– Windows 98, Windows 2000– Macintosh operating system– Linux
26
Real-time Operating Systems
• Having time as a key parameter– Industrial process control systems
• Hard/soft real-time systems– Hard real-time system: actions absolutely must
occur at a certain moment• Robot at an assembly line
– Soft real-time system: missing an occasional deadline is acceptable
• Digital audio or multimedia systems
27
Embedded Operating Systems
• Very small computers– Palmtop/PDA– Device controllers
• Features of OS– Kind of real-time systems– Restrictions in size, memory, power, …
• Example: PalmOS, Windows CE
28
Smart Card Operating Systems
• CPU chips on credit card-sized devices– Proprietary systems
• Features– Java oriented– Multiprogramming for Java applets– Resource management and protection
29
Outline
• What is an operating system?
• History of operating systems
• Categories of operating systems
• Computer hardware review
• Operating system concepts
• System calls
• Operating system structure
30
Components of a Computer
• System bus: connect all components
Bus
CPU MemoryVideo
controllerKeyboard controller
Floppy disk
controller
Hard disk controller
Monitor Keyboard
Floppy disk
driver
Hard disk
driver
31
CPU
• Registers– General registers– Program counter: pointer to next instruction– Stack pointer: to the top of current memory– PSW: condition code bits
• Basic model– Fetching instruction decoding executing
• Execution image: a snapshot of registers
32
• Pipeline: overlap instruction execution
• Superscalar: multiple execution units
Execute unit
Decode unit
Fetch unit
Pipeline and Superscalar
I1
I2
I3
Fetch unit
Decode unit
Fetch unit
Decode unit
Holding buffer
Execute unit
Execute unit
Execute unit
33
System Calls
• Two modes in CPU– Kernel mode: full capability– User mode: disallow I/O, memory protection
• System calls: get OS service for user program– Traps: OS gets control– TRAP instruction switches from user mode to
kernel mode and starts OS– When the work done, control is returned to user
program
34
Memory Hierarchy
Typical access time
Typical capacity
1 nsec Register <1 KB
2 nsec Cache 1 MB
10 nsec Main memory 64-512 MB
10 msec Magnetic disk 5-50 GB
100 sec Magnetic tape 20-100 GB
35
Nonvolatile RAM
• ROM– Programmed once, cannot be changed
afterward– Fast and inexpensive– Boot strap loader, fixed programs
• EEPROM and flash RAM– Rewritable
• CMOS– Volatile, one battery lasts for several years
36
Memory Management
• Hold multiple programs in main memory– Improve CPU utilization
• Problems– Protection
• Program A is not allowed to fetch data within program B
– Relocation• Each program starts from logical address 0• How to load and allocate them into main memory?
37
Base/limit Registers• Base register
– Point to the start of a program– Its content is added to every program
address• Limit register
– Record the size of program + data– Limit of addresses
• Virtual address physical address– Base = 4096, limit = 6114– Virtual addr = 2000 physical addr =
6096 < limit, legal!• MMU: memory management unit
User program and data
User program and data
Operating system
0
Base
Limit
0xFFFFFFF
38
Split Program and Data
• Why: multiple users may run a same program
• How: base/limit registers for program and data, respectively
• Overhead of switching: context switch
User-2 data
User program
User-1 data
Operating system
Base-2
Limit-2
Registers when
running program 1
Base-1
Limit-1
Base-2
Limit-2
Registers when
running program 2
Base-1
Limit-1
39
I/O Devices
• Controller: physically controls the devices– Devices are diverse and complicated
• Device driver: software talks to a controller– Depends on operating systems
• Installation of drivers– Relink kernel with new driver, reboot
– Register driver in system file, reboot
– Install on-the-fly, NO rebootdevice
controller
driver
Operating system
40
Busy Waiting I/OUser program Kernel Driver I/O device
Issue a system call
Call driver
Start I/O
Polling Do I/O
Put data
Return control to
caller
Continue
41
I/O by Interrupt• Driver programs controller by writing its device registers.
Controller starts device• Controller finishes reading/writing, and then signals the
interrupt controller• If interrupt controller can accept the interrupt, it informs
CPU• Interrupt controller puts the number of device on the bus,
CPU read it
CPU Interrupt controller Disk controller
Disk drive
12
34
42
Interrupt Processing
Current instruction
Next instruction
Interrupt handler
1. Interrupt
2. Dispatch to handler
3. Return
43
Direct Memory Access (DMA)User program Kernel I/O device & memory
Issue a system call
Set up DMA chip
SuspendedRun other
programsI/O directly
Issue interrupt when
finish
Set the program
status as “ready”
Ready to continue
44
Advanced Computer With Multiple Buses
IDE bus
SCSI bus
USB bus
Level 2 cache CPU
PCI bridge
Main memory
Cache bus Local bus Memory bus
PCI bus
Available PCI slotSCSI USB ISA
bridge IDE disk
Graphics adaptor
MonitorISA busMouse Keyboard
Modem Sound card PrinterAvailable ISA slot
45
Plug and Play
• Problems without plug and play– Each I/O card has a fixed interrupt level/address– When new card comes conflict level/address– Use switches/jumpers to select good
level/address more than an art
• How plug and play– System collects info/assign level/address for I/O
devices– BIOS does major work
46
Warm-up
• Operating system = extended (virtual) machine + resource manager
• Hardware evolving operating system evolving– 4 generations– Various hardware platform various OS
• Important components of a computer– CPU, bus, memory, I/O
47
Outline
• What is an operating system?
• History of operating systems
• Categories of operating systems
• Computer hardware review
• Operating system concepts
• System calls
• Operating system structure
48
Process
• A program in execution– Address space: a list of memory locations the
process can read/write– Registers, e.g., PC, SP, …
• Examples– Two processes running two programs: Word,
Excel– Two processes running the same program:
multiple web-browsers in a PC
49
Information About Processes
• Process table in operating systems– Registers, etc.
• Core image: suspended process address space
• Process information = Process table entry + core image
50
Process Management System Calls• Create a new (child) process
– Process tree
• Interprocess communication– Communication– Synchronization
• Request/release memory
• Alarm signal– E.g., remote communication
A
B C
D E F
51
Users and Processes
• User group: a group of users– GID
• Users are identified by UID– Superuser/system administrator
• One user can run many processes– Processes from one user share same UID– Processes are identified by PID
53
Deadlock in ComputerTime Process 1 Process 2
1 Get CD-recorder
2 Get tape drive
3 Wait for tape drive
4 Wait for CD recorder
Deadlock!
Process 1Process 2
54
Memory Management
• Sharing main memory among processes– Protection
• Handling virtual memory larger than physical memory– Reallocation: map memory space to main
memory and disk
55
Files and Directories
• Directory: hierarchy of filesRoot
Students
Robert Matty Leo
Faculty
Prof. Brwon Prof. Green Prof. White
Courses Papers Grants Committees
CS101 CS105Path /Faculty/Prof.Brown/Courses/CS105
57
Model I/O Devices As Files
• Block special files: a collection of randomly addressable blocks, e.g., disks
• Character special files: devices accept/output character stream, e.g., printers, modems
• Pipe: pseudofile connecting two processes
A B
PipeProcess Process
58
Outline
• What is an operating system?
• History of operating systems
• Categories of operating systems
• Computer hardware review
• Operating system concepts
• System calls
• Operating system structure
59
System Calls
• Interface between OS and user programs
• Similar underlying concepts– Details vary from OS to OS
• A procedure library for programming languages– Like making a special procedure call
60
System Call Read
• A call in C: count=read(fd, buffer, nbytes);– Count # of bytes really read– If failed, count -1– errno error number
61
Making System Call read()
Count # of bytes really read
If failed, count -1, errno error number
count=read(fd, buffer, nbytes);
62
POSIX System Calls: Process Management• Fork()
• Waitpid(pid, &statloc, options)
• Execve(name, argv, environp)
• Exit(status)
63
POSIX System Calls: File Management• Open(file, how, …)
• Close(fd)
• Read(fd, buffer, nbytes)
• Write(fd, buffer, nbytes)
• Lseek(fd, offset, whence)
• Stat(name, &buf)
64
POSIX System Calls: Directory and File System Management• Mkdir(name, mode)
• Rmdir(name)
• Link(name1, name2)
• Unlink(name)
• Mount(special, name, flag)
• Umount(special)
65
POSIX System Calls: Miscellaneous• Chdir(dirname)
• Chmod(name, mode)
• Kill(pid, signal)
• Time(&seconds)
66
Win32 API CallsWin32 UNIX Win32 UNIX
CreateProcess fork CreateDirectory mkdir
WaitForSigleObject waitpid RemoveDirectory rmdir
(none) execve (none) link
ExitProcess exit DeleteFile unlink
CreateFile open (none) mount
CloseHandle close (none) umount
ReadFile read SetCurrentDirectory chdir
WriteFile write (none) chmod
SetFilePointer lseek (none) kill
GetFileAttributesEx stat GetLocalTime time
67
Outline
• What is an operating system?
• History of operating systems
• Categories of operating systems
• Computer hardware review
• Operating system concepts
• System calls
• Operating system structure
68
Monolithic Systems
• No structure as a good structure– OS: a collection of procedures
• Three layers of procedures
Invoke requested service procedure
Carry out system calls
Help service procedures
Main procedures
Service procedures
Utility procedures
69
Relation Among Procedures
• A main program– Involve the requested service procedures
• A set of service procedures– Carry out the system calls
• A set of utility procedures– Help the service procedures
70
Layered SystemsTHE system
MULTICS
professor
students
System calls
Layer Function
5 The operator
4 User programs
3 Input/output management
2 Operator-process communication
1 Memory and drum management
0 Processor allocation and multiprogramming
71
Virtual Machines
• Virtual machine monitor (VM/370)
– Multiprogramming by multiple virtual machines
– Each virtual machine is exact copies of 370
• Operating systems run on virtual machines
– Two level traps
System calls hereI/O incrustations here CMS CMS CMS Trap here
Trap here VM/370
370 bare hardware
72
Exokernels
• Give each user a clone of actual computer, but with a subset of the resources
• Two levels– Exokernel: allocate/maintain resources to virtual
machines– OS: run on virtual machines
• Advantages– Save a layer of mapping– Separate multiprogramming from user OS code
with less overhead
73
Client-server Model
• Move code from kernel up into higher layers
– Kernel minimal microkernel
– Implement most of the OS in user processes
Client process
Client process
Process server
Terminal server
…File
serverMemory server
User mode
MicrokernelKernel mode
Client obtains service by sending messages to server processes
74
Advantages of Client-server Model
• Robust– A bug may cause crash within a module only
• Adaptable– Easy to implement in distributed systems
Machine 1
Client
kernel
Machine 2
File server
kernel
Machine 3
process server
kernel
Machine 4
Terminal server
kernel
NetworkMessage from client to server
75
Summary
• Operating systems = resource managers + extended machines
• Operating systems evolve as hardware evolving• Review of computers hardware for good
understanding of operating systems• Basic concepts of OS: processes, memory
management, I/O management, file system, security
• System calls as heart of operating systems• Structures of operating systems