Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Operating System Allen C.-H. Wu Department of Computer Science Tsing Hua University
Part I: OverviewCh. 1 Introduction • Operating system: is a program that acts as an intermediary between a user and computer hardware. The goals are to make the computer system convenient to use and run in an efficient manner. • Why, what and how? • DOS, Window, UNIX, Linux • Single-user, multi-user
User System and application programs Operating system Hardware User 1.1 What Is an Operating System • OS=government: resource allocation=> CPU, memory, IO, storage • OS: a control program controls the execution of user programs to prevent errors and improper use of the computer. • Convenience for the user and efficient operation of the computer system
1.2 Batch Systems • In early days (beyond PC era), computers were extremely expensive. Only few institutes can afford it. • The common IO devices include card readers, tape drives, and line printers. • To speed up processing, operators batched together jobs with similar needs and ran them through the computer as a group. • The OS is simple that needs to only automatically transfer control from one job to the next.
Batch Systems • Speed(CPU) >> speed(IO: card readers) => CPU is constantly idle. • After introduce disk technology, OS can keep all jobs on a disk instead of a serial card reader. OS can perform job scheduling (Ch. 6) to perform tasks more efficiently. • Multiprogramming: OS keeps several jobs in the memory simultaneously. Interleaving CPU and IO operations between different jobs to maximize the CPU utilization.
Batch Systems • Life examples: a lawyer handles multiple cases for many clients. • Multiprogramming is the first instance where OS must make decisions for the users: job scheduling and CPU scheduling.
1.3 Time-Sharing Systems • Time sharing or multitasking: the CPU executes multiple jobs by switching among them, but switches are so quick and so frequently that the users can interact with each program while it is running (the user thinks that he/she is the only user). • A time-sharing OS uses CPU scheduling and multiprogramming to provide each user with a small portion of a time-shared computer. • Process: a program is loaded into memory and executed.
Time-Sharing Systems • Need memory management and protection methods (Ch. 9) • Virtual memory (Ch. 10) • File systems (Ch. 11) • Disk management (Ch. 13) • CPU scheduling (Ch. 6) • Synchronization and communication (Ch. 7)
1.4 PC Systems • MS-DOS, Microsoft-Window, Linux, IBM OS/2, Macintosh OS • Mainframe (MULTICS:MIT) => minicomputers (DEC:VMS, Bell-Lab:UNIX) => microcomputers => network computers • Personal workstation: a large PC (SUN, HP, IBM: Windows NY, UNIX) • PCs are mainly single-user systems: no resource sharing is needed; due to the internet access, security and protection is needed
1.5 Parallel Systems • Multiprocessor systems: tightly coupled systems • Why? 1) improve throughput, 2) money saving due to resources sharing (peripherals, storage, and power), and 3) increase reliability (graceful degradation, fault tolerant) • Symmetric multiprocessing: each processor runs an identical OS, needs communication between processors • Asymmetric multiprocessing: one master control processor, master-slave
Parallel Systems • Back-ends • => microprocessors become inexpensive • => using additional microprocessors to off-load some OS functions (e.g., using a microprocessor system to control disk management) • a kind of master-salve multiprocessing
1.6 Real-Time Systems • There are rigid time requirements on the operation of a processor or control/data flow • Hard real-time systems: the critical tasks must be guaranteed to be completed on time • Soft real-time systems: a critical real-time task gets priority over other tasks
1.7 Distributed Systems • Internet and WWW • TCP/IP and PPP • Distributed systems: loosely coupled systems • Network OS: a PC running a network OS acts autonomously (Ch. 14) • Distributed OS: a less autonomous environment (Ch. 16)
Ch. 2 Computer-System Structures Disks Printers Tape drivers Disk controller Printer controller Tape-drive controller CPU System bus Memory controller Memory
2.1 Computer-System Operation • Bootstrap program • Modern OSs are interrupt driven • Interrupt vector: interrupted device address, interrupt request, and other info • System call (e.g., performing an I/O operation) • Trap
2.2 I/O Structure • SCSI (small computer-systems interface): can attach seven or more devices • Synchronous I/O: I/O requested => I/O started => I/O completed => returned control to user program • Asynchronous I/O: I/O requested => I/O started => returned control to user program without waiting the completion of the I/O operation • Device-status table: indicates the device’s type, address, and state (busy, idle, not functioning)
I/O Structure • DMA (Direct Memory Access) • Data transfer for high-speed I/O devices and main memory • Block transfer with one interrupt (without CPU intervention: 1 byte/word at a time) • Cycle-stealing • A back-end microprocessor?
2.3 Storage Structure • Main memory: RAM (SRAM and DRAM) • von Neumann architecture: instruction register • Memory-mapped I/O, programmed I/O (PIO) • Secondary memory • Magnetic disks, floppy disks • Magnetic tapes
2.4 Storage Hierarchy (FIG) • Bridging speed gap • registers=>cache=>main memory=>electronic disk=>magnetic disk=>optical disk=>magnetic tapes • Volatile storage: data lost when power is off • Nonvolatile storage: storage systems below electronic disk are nonvolatile • Cache: small size but fast (cache management: hit and miss) • Coherency and consistency
2.5 Hardware Protection • Resource sharing (multiprogramming) improves utilization but also increase problems • Many programming errors are detected by the hardware and reported to OS (e.g., memory fault) • Dual-mode operation: user mode and monitor mode (also called supervisor, system or privileged mode: privileged instructions): indicated by a mode bit. • Whenever a trap occurs, the hardware switches from user mode to monitor mode
Hardware Protection • I/O protection: all I/O instructions should be privileged instructions. The user can only perform I/O operation through the OS. • Memory protection: protect the OS from access by users program, protect user programs from each other: base and limit registers. • CPU protection: A timer to prevent a user program from getting stuck in an infinite loop.
CH. 3 OS Structure • Examining the services that an OS provides • Examining the interface between the OS and users • Disassembling the system into components and their interconnections • OS components: => Process management => Main-memory management => File management => I/O-system management => Secondary-storage management => Networking => Protection system => Command-interpreter
3.1 System ComponentsProcess Management • Process: a program in execution (e.g., a compiler, a word-processing program) • A process needs certain resources (e.g., CPU, memory, files and I/O devices) to complete its task. When the process terminates, the OS will reclaim any reusable resources. • OS processes and user processes: The execution of each process must be sequential. All the processes can potentially execute concurrently, by multiplexing the CPU among them.
Process Management The OS should perform the following tasks: • Creating and deleting processes • Suspending and resuming processes • Providing mechanisms for process synchronization • Providing mechanisms for process communication • Providing mechanisms for deadlock handling • => Ch. 4- Ch. 7
Main-Memory Management • Main memory is a repository of quickly accessible data shared by the CPU and I/O devices (Store data as well as program) • Using absolute address to access data in the main memory • Each memory-management scheme requires its own hardware support • The OS should responsible for the following tasks: => Tracking what parts memory are currently used and by whom => Deciding which processes should be loaded into memory => Allocating and deallocating memory as needed
File Management • Different I/O devices have different characteristics (e.g., access speed, capacity, access method) - physical properties • File: is a collection of related information defined by its creator. The OS provides a logical view of information storage (FILE) regardless its physical properties • Directories => files (organizer) => access right for multiple users
File Management The OS should be responsible for: • Creating and deleting files • Creating and deleting directories • Supporting primitives for manipulating files and directories • Mapping files onto secondary storage • Backing up files on nonvolatile storage • => Ch. 11
I/O-System Management • An OS should hide the peculiarities of specific hardware devices from the user • The I/O subsystem consists of: • A memory-management component including buffering, caching, and spooling • A general device-driver interface • Drivers for specific hardware devices
Secondary-Storage Management • Most modern computer systems use disks as the principle on-line storage medium, for both programs and data • Most programs stored on a disk and will be loaded into main memory whenever it is needed • The OS should responsible for: => Free-space management => Storage allocation => Disk scheduling => Ch. 13
Networking • Distributed system: a collection of independent processors that are connected through a communication network • FTP: file transfer protocol • WWW: NFS (network file system protocol) • http: • => Ch. 14- Ch. 17
Protection System • For a multi-user/multi-process system: processes executions need to be protected • Any mechanisms for controlling the access of programs, data, and resources • Authorized and unauthorized access and usage
Command-Interpreter System • OS (kernel) <=> command interpreter (shell) <=> user • Control statements • A mouse-based window OS: • Click an icon, depending on mouse point’s location, the OS can invoke a program, select a file or a directory (folder).
3.2 OS Services • Program execution • I/O operation • File-system manipulation • Communications • Error detection • Resource allocation • Accounting • Protection
3.3 System Calls • System calls: the interface between a process and the OS • Mainly in assembly-language instructions. • Allow to be invoked from a higher-level language program (C, C++ for UNIX: JAVA+C/C++) • EX. Copy one file to another: how to use system calls to perform this task? • Three common ways to pass parameters to the OS: register, block, stack (push/pop).
System Calls Five major categories: • Process control • File manipulation • Device manipulation • Information maintenance • Communications
Process Control • End, about: =>Halt the execution normally (end) or abnormally (abort) => Core dump file: debugger =>Error level and possible recovery • Load, execute => When to load/execute? Where to return the control after it’s done? • Create/terminate process => When? (wait time/event)
Process Control • Get/set process attributes => Core dump file for debugging => A time profile of a program • Wait for time, event, single event • Allocate and free memory • The MS-DOS: a single tasking system • Berkeley UNIX: a multitasking system (using fork to start a new process
File Management • Create/delete file • Open, close • Read, write, reposition (e.g., to the end of the file) • Get/set file attributes
Device Management • Request/release device • Read, write, reposition • Get/set device attributes • Logically attach and detach devices
Information Maintenance • Get/set time or date • Get/set system data (e.g., OS version, free memory space) • Get/set process, file, or device attributes (e.g., current users and processes)
Communications • Create, delete communication connection: message-passing and shared-memory model • Send, receive messages: host name (IP name), process name Daemons: source (client)<->connection<->the receiving daemon (server) • Transfer status information • Attach or detach remote devices
3.4 System Programs • OS: a collection of system programs include file management, status information, file modification, programming-language support, program loading and execution, and communications. • Os is supplied with system utilities or application programs (e.g., web browsers, compiler, word-processors) • Command interpreter: the most important system program => contains code to execute the command => UNIX: command -> to a file, load the file into memory and execute rm G => search the file rm => load the file => execute it with the parameter G
3.5 System Structure(Simple Structure) FIG3.6 • MS-DOS: application programs are able to directly access the basic I/O routine (8088 has no dual mode and no hardware protection) => errant programs may cause entire system crashes • UNIX: the kernel and the system programs. • System calls define the application programmer interface (API) to UNIX FIG3.7
Layered Approach • Layer 0 (the bottom one): the hardware, layer N (the top one): the user interface • The main advantage of the layer approach: modularity Pro: simplify the design and implementation Con: not easy to appropriately define the layers less efficient • Windows NT: a highly layer-oriented organization => lower performance compared to Windows 95 => Windows NT 4.0 => moving layers from user space to kernel space to improve the performance
Microkernels • Carnegie Mellon Univ (1980s): Mach • Idea: removing all nonessential components from the kernel, and implementing them as system and user-level programs. • Main function: microkernel provides a communication facility (message passing) between the client program and various services (running in user space) • Easy of extending the OS: new services are added to the user space, no change on the kernel
Microkernels • Easy to port, more security and reliability (most services are running as user, if a service fails, the rest of OS remains ok) • Digital UNIX • Apple MacOS Server OS • Windows NT: a hybrid structure FIG 3.10
Virtual Machines • VM: IBM • Each process is provided with a (virtual) copy of the underlying computer • Major difficulty: disk systems => minidisks Implementation: • Difficult to implement: switch between a virtual user and a virtual monitor mode • Less efficient in run time FIG 3.11
Virtual Machines Benefits: • The environment is complete protection of the various system resources (but no direct sharing of resources) • A perfect vehicle for OS research and development • No system-development time is needed: system programmer can work on his/her own virtual machine to develop their system • MS-DOS (Intel) <=> UNIX (SUN) • Apple Macintosh (68000) <=> Mac (old 68000) • Java
Java • Java: a technology rather than a programming language : SUN : late 1995 • Three essential components: => Programming-language specification => Application-programming interface (API) => Virtual-machine specification
Java Programming language • Object-oriented, architecture-neutral, distributed and multithreaded programming language • Applets: programs with limited resource access that run within a web browser • A secure language (running on distributed network) • Performing automate garbage collection