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: o Execute user programs and make solving user problems easier. o Make the computer system convenient to use. Use the computer hardware in an efficient manner. Computer System Structure 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 Four Components of a Computer System
Operating System Definition OS is a resource allocator 1. Manages all resources 2. Decides between conflicting requests for efficient and fair resource use OS is a control program 1. Controls execution of programs to prevent errors and improper use of the computer No universally accepted definition “Everything a vendor ships when you order an operating system” is good approximation But varies wildly
“The one program running at all times on the computer” is the kernel. Everything else is either a system program (ships with the operating system) or an application program
Computer Startup bootstrap program is loaded at power-up or reboot Typically stored in ROM or EEPROM, generally known as firmware 1. Initializates all aspects of system 2. Loads operating system kernel and starts execution Computer System Organization Computer-system operation : One or more CPUs, device controllers connect through common bus providing access to shared memory Concurrent execution of CPUs and devices competing for memory cycles To ensure orderly access to the shared memory, memory controller-> whose function is to synchronize access to memory
For a computer to start running – when it is powered up or rebooted, it requires an initial program. Initial program or BOOTSTRAP is stored in ROM and kept in H/W. It initializes the CPU, I/O devices, Memory. The BOOTSTRAP must locate and load O.S kernel into memory. O.S selects the first program i.e. INIT and waits for event to occur. For the event to occur is usually signaled by an interrupt i.e. H/W or Software. H/W may trigger an interrupt at any time by sending request to CPU through system Bus. S/W may trigger an interrupt by executing special operation called System Call. If there no process to execute, no I/O devices and no users to respond, O.S will sit waiting for something to happen. Events are usually signaled by occurrence of an interrupt or a TRAP. TRAP is software generated interrupt caused by an error. For each type of interrupt, separate segments of code in the O.S determine what action should be taken. An interrupt Service Routine is provided that is responsible for dealing with the interrupt.
Interrupt Hardware & Interrupt processing The function of the interrupt H/W of a computer system is to draw the supervisor’s attention to the occurrence of the interrupt & provide sufficient information for processing the interrupt. This involves diverting the CPU from the present executing job to Interrupt Process Routine. Interrupt H/W achieves this by changing contents of PSW (Process Status Word). The new contents of PSW tell the execution of interrupt service routine. Interrupt H/W also saves the old contents of PSW in the memory. Old contents are useful for determining the cause of the Interrupt & the state of the interrupt program. Interrupt H/W (PSW) IM P
IC
MPI
PC
IM : Interrupt Mask P : Privileged mode IC : Interrupt code MPI : Memory protection information PC: Program counter. MPI :Contains LBR & UBR registers P: Indicates whether CPU is in privileged mode. ( Single Bit ) IM: field may contain integer M, interrupts with priority >= M are permitted to occur are said to be ENABLED. Others a re MASKED. (They remain pending until they are permitted to occur. PC: determines behavior of CPU. IC; Contains an integer, records the nature and cause of last interrupt. Two areas of memory called Interrupt Vectors. They have saved information of PSW. Each area consists of set of units. No of units = No of interrupts. Each unit in interrupt vectors area is an interrupt vector, controls process of interrupt. It contains. 1) Address of an O.S routine to process to interrupt. 2) Interrupt mask to tell whether to permit other interrupts or no 3) Whether CPU should be in Privileged mode while processing. For simplicity interrupt vector has same format as a PSW. STEPS are !) When an interrupt occurs, cause of the interrupt is identified by the interrupt H/W & code describing the cause is stored in the interrupt code field of PSW. EX: “IO Completion” interrupt the code could be the address of the IO device causing the interrupts. 2) The PSW is copied into the saved PSW information area 3) The interrupt vector corresponding to the interrupt is accessed. Information from Interrupt vector is loaded into fields of PSW. CPU depends on new contents of PSW: 1. Privileged mode. 2. Interrupt mask. 3. PC. Since interrupt vector contains address of O.S routine the interrupt action effectively transfers control to the appropriate routine in the MP supervisor Only the interrupt enabled in the new interrupt mask can occur now, others are pending until the first job is completed. Interrupt action must put CPU in privileged mode.
System Call Is a method by which program makes a request to the O.S
They are implemented using interrupt H/W of a system a new kind of interrupt called S/W interrupt Special Instruction < SI _ Instrn> A S/W interrupt occurs when this instruction is executed. is put into the IC field of PSW. The integer processing routine analyzes the IC field to determine the nature of the request made by the program.
I/O Structure A General Purpose computer system consists of a 1). CPU 2). Device Drivers 3) connected through common bus. SCSI (Small Computer Systems interface) controller can have seven or more devices attached to it. A device controller maintains some 1. local buffer storage 2. set of special purpose registers.
Peripheral devices
Device controllers
Local buffer Storage
I/O Interrupts To start an I/O operation, CPU loads the appropriate registers in device controller. Device controller examines the contents of the register to determine what action to take. EX: READ REQUEST, IT WILL TRANSFER DATA FROM THE DEVICE TO ITS LOCAL BUFFER, ONCE TRANSFER IS COMPLETE, DEVICE CONTROLLER INFORMS CPU .This is done by triggering an interrupt. Synchronous I/O : I/O is started, then at I/O completion control is returned to the user process. Asynchronous I/O: returns control to the user without waiting for I/O to complete. Waiting for I/O 2 types :1. Special WAIT instruction that idles CPU until next interrupt. 2. WAIT LOOP Loop : jmp Loop. This loop continues until an interrupt occurs transferring control to another part of O.S.Devices then set flag in one of the registers and expect O.S to notice that flag. 1. A better alternative is to start the I/O operation & then to continue processing other O.S or user program code. A system Call is then needed to allow user program to wait for I/O completion. 2. If no user program are ready to run & O.S has no other work to do, still require the WAIT and keep track of I/O request. Two I/O Methods Synchronous
Asynchronous
Device-Status Table
Each table indicates the device, address, status O.S will also maintain a WAIT queue – list of waiting request – for each I/O device. When an interrupt occurs, the O.S first determines which I/O device caused the interrupt .Then indexes into I/O device table -> status. If there are additional request waiting in the queue process the next request. Control is returned from I/O interrupt. If process was waiting then control is transferred there. otherwise return to whatever we were doing before the I/O interrupt for : execution of the user program
Storage Structure Main memory (RAM) : Large storage area . DRAM – array of memory words. Each word has its own address. Von Neumann concept 1. Fetch instruction from memory. 2. Store in instruction register
3. Instruction is decoded 4. Operands may be fetched from memory & stored in some register. 5. After the instruction is executed result may be stored back in the memory Main memory is volatile storage device. Secondary storage : able to hold large quantities permanently. EX : magnetic disk 1. Any instruction in execution & any data being used by the instruction , must be in one of the storage devices. If data are not in memory they must be moved. 2. Many computers architecture provide memory mapped I/O. Ranges of memory address are set aside, and are mapped to device registers. Ex : Video Controller Location
Screen
Location
Mapped Memory
3. To send out a long string of bytes through a serial port, CPU writes one data byte to data register, set a bit on control register. 4. Device takes the data byte, cleans the bit in control register , ready for next byte. 5. CPU uses POLLING to watch control bit, to see device is ready and is called PROGRAMMED I/O 6. If CPU does not poll, but receives an interrupt when device is ready for next byte, data transfer is INTERRUPT DRIVEN Caching Caching is a n important principle of computer system. Information is normally kept in some storage System( Main memory). As it is used it is copied into a faster storage system – the cache – on temporary basis. When we need information we first see whether it is cache, if it is, we use information directly from cache. If it is not we use information from main storage device , putting a copy in cache. Registers provide high speed for cache. Most system have instruction cache to hold next instruction expected to be executed , which increases CPU speed and no need to wait. EX : RAM: used for high speed storage magnetic disks: bulk of secondary storage on this magnetic disk contents backed into magnetic tapes. To protect against data loss. Transfer of data from cache to CPU & registers is usually H/W function. Transfer of data from disk to memory is controlled by O.S Performance of Various Levels of Storage Movement between levels of storage hierarchy can be explicit or implicit
Micro kernels AS the UNIX O.S expanded, the Kernel became large & difficult to manage. Researches developed an O.S called MACH that modularizes the kernel using MICRO KERNEL approach. O>S removes all non essential components from the kernel. And implementing them as a system, user level programs. The result is a smaller kernel. They provide minimal process & memory management +communication facility.
Client Program
Micro Kernel
Various services
Easy to extend O.S. All new services are added to user space & no need of modification of the kernel. When kernel has to be modified changes are fewer. It provides more security & reliability since most services are running as user. If a service fails, rest of O.S remains untouched.
Virtual Machines Initially O.S were batch systems. But the users wanted time sharing. Therefore IBM decided for writing time sharing. The official IBM time sharing system TSS/360, was delivered late. It was to big and slow, so some sites converted over it. But later IBM selected one product. This system originally CP/CMS & now VM/370. A time sharing system provides 1. Multiprogramming 2. Extended machine with more convenience interface than bare H/W. 3. Heart of the system VIRTUAL MACHINE MONITOR VIRTUAL MACHINE MONITOR runs on bare H/W, does multiprogramming & provides several virtual machines to the next layer up. These machines are not extended machines. They are exact copies of H/W including 1. Kernel user mode 2. I/O 3. Interrupts Each machine can run any O.S that will run directly on H/W. Ex: Batch process -> O.S/360 Single user
CMS ( Conversational monitor system) -> time sharing Several machine have used microkernel approach. TRU 64 UNIX provides a UNIX interface to the user, implemented with MACK KERNEL. APPLE Macos X server O.S is based on MACH kernel QNX is real time O.S based on microkernel.1. Provides service for message passing & Process shecudiling 2. handles low level H/W interrupts. 3. all other services run outside the kernel in user mode Windows NT uses Hybrid structure. 1. runs various application like win32, POSIX. 2. It provides server that runs in user space for each application. 3. Kernel coordinates message passing between client application& application services.
Direct Memory Access Structure Used for high-speed I/O devices able to transmit information at close to memory speeds. Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention. Only on interrupt is generated per block, rather than the one interrupt per byte. Migration of Integer A from Disk to Register Multitasking environments must be careful to use most recent value, not matter where it is stored in the storage hierarchy
Multiprocessor environment must provide cache coherency in hardware such that all CPUs have the most recent value in their cache Distributed environment situation even more complex l Several copies of a datum can exist
Storage-Device Hierarchy
Operating System Structure Multiprogramming needed for efficiency 1. Single user cannot keep CPU and I/O devices busy at all times 2. Multiprogramming organizes jobs (code and data) so CPU always has one to execute 3. A subset of total jobs in system is kept in memory 4. One job selected and run via job scheduling 5. When it has to wait (for I/O for example), OS switches to another job 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 1. Response time should be < 1 second 2. Each user has at least one program executing in memory process 3. If several jobs ready to run at the same time CPU scheduling 4. If processes don’t fit in memory, swapping moves them in and out to run 5. Virtual memory allows execution of processes not completely in memory Memory Layout for Multiprogrammed System
Operating-System Operations Interrupt driven by hardware Software error or request creates exception or trap 1. Division by zero, request for operating system service Other process problems include infinite loop, processes modifying each other or the operating system Dual-mode operation allows OS to protect itself and other system components 1. User mode and kernel mode 2. Mode bit provided by hardware Provides ability to distinguish when system is running user code or kernel code Some instructions designated as privileged, only executable in kernel mode System call changes mode to kernel, return from call resets it to user Transition from User to Kernel Mode Timer to prevent infinite loop / process hogging resources 1. Set interrupt after specific period 2. Operating system decrements counter 3. When counter zero generate an interrupt 4. Set up before scheduling process to regain control or terminate program that exceeds allotted time
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 1. CPU, memory, I/O, files 2. Initialization data Process termination requires reclaim of any reusable resources Single-threaded process has one program counter specifying location of next instruction to execute 1. 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 1. Concurrency by multiplexing the CPUs among the processes / threads
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 All data in memory before and after processing All instructions in memory in order to execute Memory management determines what is in memory when 1. Optimizing CPU utilization and computer response to users Memory management activities 1. Keeping track of which parts of memory are currently being used and by whom 2. Deciding which processes (or parts thereof) and data to move into and out of memory 3. Allocating and de-allocating memory space as needed Storage Management OS provides uniform, logical view of information storage 1. Abstracts physical properties to logical storage unit - file 2. 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 1. Files usually organized into directories 2. Access control on most systems to determine who can access what 3. OS activities include Creating and deleting files and directories Primitives to manipulate files and dirs Mapping files onto secondary storage Backup files onto stable (non-volatile) storage media
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 1. Free-space management 2. Storage allocation 3. Disk scheduling Some storage need not be fast 1. Tertiary storage includes optical storage, magnetic tape 2. Still must be managed 3. Varies between WORM (write-once, read-many-times) and RW (readwrite) I/O Subsystem One purpose of OS is to hide peculiarities of hardware devices from the user I/O subsystem responsible for 1. 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) 2. General device-driver interface 3. Drivers for specific hardware devices 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 1. 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 1. User identities (user IDs, security IDs) include name and associated number, one per user 2. User ID then associated with all files, processes of that user to determine access control 3. Group identifier (group ID) allows set of users to be defined and controls managed, then also associated with each process, file 4. Privilege escalation allows user to change to effective ID with more rights Computing Environments Traditional computer 1. Blurring over time 2. Office environment PCs connected to a network, terminals attached to mainframe or minicomputers providing batch and timesharing Now portals allowing networked and remote systems access to same resources 3. Home networks
Used to be single system, then modems Now fire walled, networked Client-Server Computing 1. Dumb terminals supplanted by smart PCs 2. Many systems now servers, responding to requests generated by clients Compute-server provides an interface to client to request services (i.e. database) File-server provides interface for clients to store and retrieve files
Peer-to-Peer Computing Another model of distributed system P2P does not distinguish clients and servers 1. Instead all nodes are considered peers 2. May each act as client, server or both 3. 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 4. Examples include Napster and Gnutella Web-Based Computing Web has become ubiquitous PCs most prevalent devices More devices becoming networked to allow web access New category of devices to manage web traffic among similar servers: load balancers Use of operating systems like Windows 95, client-side, have evolved into Linux and Windows XP, which can be clients and servers