Operating Systems 1 Unit- I Computer System and Operating System Overview Overview of computer operating systems: An operating system is a set of software programs that manages the hardware of a computer. It also exploits the hardware resources of one or more processors to provide a set of services to system hardware. An amazing aspect of OS is how varied they are in accomplishing these tasks. Mainframe operating systems are designed primarily to optimize the utilization of hardware resources. Personal Computer (PC) OS supports a wide range between complex games and business applications. What an OS do? A computer system can be divided roughly into four components: 1) The Hardware: The CPU, the memory, and I/O devices provide the basic computing resources for the system. 2) The Application Programs: The application programs such as word processors, spreadsheets, compilers, and web browsers define the ways in which these resources are used to solve user’s computing problems. 3) The Operating System: It controls and coordinates the use of the use of hardware among the various application programs for the various users. 4) The Users: The users are the ultimate end users of the hardware, operating system, and the application programs. User 1 Compilers User 2 Assembler User 3 User n …….. Text Editors ……….. Database System System and Application Programs Operating System Computer Hardware Fig 1: Abstract View of the components of a computer system Operating Systems 2 For example: An OS is similar to a government Like a government, it performs no useful by itself. It simply provides an environment within which other programs can do useful work. User Application Operating System Hardware Fig 2: Hierarchy of computer system What does a modern operating system do? 1) Provides Abstractions: Hardware has low-level physical resources with complicated, idiosyncratic (individual, peculiar) interfaces. OS provides abstracts that present clean interfaces. Goal: make computer easier to use. E.g.: Processes, unbounded memory, files, synchronization and communication mechanisms. 2) Provides Standard Interface: Goal: portability. E.g.: UNIX runs on many very different computer systems. To a first approximation can port many programs across systems with little effort. 3) Mediates Resource Usage: Goal: allow multiple users to share resources fairly, efficiently, safely, and securely. E.g.: Multiple processes share one processor (preemptable resources). Multiple programs share one physical memory (preemptable resources). Multiple users and file share one disk (non- preemptable resources). Multiple programs share a given amount of disk and network bandwidth (preemptable resources). 4) Consumes Resources: Goal: Solaris takes up about 8M bytes physical memory (or about $400). Operating Systems 3 The major problem facing computer science today is how to build large, reliable software systems. Operating systems are one of very few examples of existing large software systems, and by studying OS we may learn lessons applicable to the construction of larger systems. Operating System Overview An operating system or OS is a software program that enables the computer hardware to communicate and operate with the computer software. Without a computer operating system a computer would be useless. OS Types: As computers have progressed and developed so have the types of OS. 1) GUI (Graphical User Interface): A GUI operating system contains graphics and icons and is commonly navigated by using a mouse. E.g.: Widows XP, Windows CE, Solaris etc., 2) Multi-user: A multi-user operating system allows for multiple users to use the same computer at the same time and/or different times. E.g.: Linux, UNIX etc., 3) Multiprocessing: An OS capable of supporting and utilizing more than one computer processor. E.g.: Linux, UNIX, Windows 2000 etc., 4) Multitasking: An OS that is capable of allowing multiple software processes to run at the same time. E.g.: UNIX, Windows 2000 etc., 5) Multithreading: Operating systems that allow different parts of a software program to run concurrently. E.g.: Linux, UNIX, Windows 2000 etc., Computer System Overview Basic Elements: A computer consists of processor, memory and I/O components, with one or more modules of each type. These components are interconnected in some fashion to achieve the main function of a computer, which is to execute programs. There are 4 main structural elements. 1) Processor: It controls the operation of the computer and performs its data processing functions. When there is only one processor, it is often referred to as the CPU. 2) Main Memory: It is used store the data and programs. This memory is typically volatile; it is referred to as primary memory or real memory. 3) I/O Modules: These are used to move data between the computer and it external environment. The external environment consists of a variety of devices, including secondary memory devices, communication equipment, and terminals. Operating Systems 4 4) System Bus: It is used to provide the communication among processors, main memory, and I/O modules. The following figure depicts these top-level components. One of the processor’s functions is to exchange data with memory. For this purpose, it typically makes use of two internal (to the processor) registers: A. Memory Address Register (MAR): which specifies the address in memory for the next read or write. B. Memory Buffer Register (MBR): This contains the data to be written into memory or receives the data read from memory. Similarly I/O Address register (I/OAR) specifies a particular I/O device. I/O Buffer Register (I/OBR) is used for the exchange of data between an I/O module and the processor. CPU PC MAR IR MBR . . . Instruction I/OAR 0 1 2 . . Instruction Instruction Execution unit I/OBR . . . Data Data . . . I/O Module . . . Buffers n-2 n-1 PC=Program counter IR=Instruction register MAR=Memory Address Register MBR=Memory Buffer Register I/OAR=Input/Output Address Register I/O BR=Input/Output Buffer Register Fig 3: Computer Components: Top-Level View Operating Systems 5 A memory module consists of a set of locations, defined by sequentially numbered addresses. Each location contains a bit pattern that can be interpreted as either an instruction or data. An I/O module transfers data from external devices to main memory and processor and vice versa. It contains internal buffers for temporarily storing data until they can be sent on. Processor Registers: A processor includes a set of registers that provide a type of memory that is faster and smaller than main memory. There are two types of registers, they are: 1. User-Visible Registers 2. Control and Status Registers 1) User-Visible Registers: These are used to enable the machine or assembly language programs to minimize main memory references by optimizing register use. Types of registers that are typically available are data, address, and condition code registers. Data Registers: These can be assigned to a variety if functions by the programmer. These registers contain main memory addresses of data and instructions, or they contain a portion of the address that is used in the calculation of the complete or effective address. E.g.: a) Index Registers: Indexed addressing is a common mode of addressing that involves adding an index to a base value to get the effective address. b) Segment Pointer: With segmented addressing, memory is divided into segments, which are variable length blocks of words. c) Stack Pointer: If there is user-visible stack addressing, then there is a dedicated registers that points to the top of the stack. 2) Control and Status Registers: A variety of processor registers are employed to control the operations of the processor. On most machines, most of these are not visible to the users. In addition to the MAR, MBR, I/OAR and I/OBR registers, the following are essential to instruction execution: a) Program Counter: PC contains the address of the next instruction to be fetched. b) Instruction Register: IR contains the instructions most recently fetched. Instruction Execution: A program to be executed by a processor consists of a set of instructions stored in memory. In its simplest form the instruction processing consists of two steps: i. The processor reads (fetches) instruction from memory one at a time and executes each instruction. ii. Program execution consists of repeating the process of instruction fetch and instruction execution. The processing required for a single instruction is called an instruction cycle. Instruction cycle includes two steps: 1) Fetch Stage, 2) Execute Stage. Operating Systems 6 Instruction Fetch and Execute: Start Fetch Next Instruction Execute Instruction Fetch Stage Execute Stage Halt Fig 4: Basic Instruction Cycle Interrupts: An interrupt is a signal which transfers control to the interrupt service routine generally, through the interrupt vector, which contains the addresses of all the service routines. Interrupt architecture must save the address of the interrupt instruction. It is a signal to the processor to suspend the current executing program and run a specified routine. Whenever the execution of routine is completed, the processor switches to its original program. Basically, interrupts are of four types. They are: 1. Program Interrupts: These types of interrupts are generated by illegal instructions in the program such as division by zero, arithmetic overflow and reference outside a user’s allowed memory space. Whenever the program interrupts happened the OS sends signal to the processor to suspend the current job. 2. Timer Interrupts: These types of interrupts are generated by clock within the processor. Whenever the time slot of the processor expired, the operating system sends the interrupt signal to the processor to suspend the current job. 3. I/O Interrupts: These types of interrupts are generated by I/O controller. For example, if the CPU issues read command to the I/O module, the I/O module is ready at that time, and then the I/O module sends an interrupt signal to the CPU about the status. 4. Hardware Interrupts: These types of interrupts are generated by hardware components, if any hardware component fails due to the technical problem, then they generates an interrupt. For example, memory failure, power failure to a particular hardware device. The interrupt signal is detected by the interrupt handler, if there are no other interrupts are pending, the interrupt controller processes the interrupt immediately. If another one is in progress, the interrupt suspends temporarily. Operating Systems 7 Interrupts and Instruction Cycle: Interrupts are provided primarily as a way to improve processor utilization. Whenever an interrupt occurs, the processor will respond after the execution of an instruction currently it is executing. And the processor does not fetch the subsequent instruction rather than it executes the interrupt controller. The CPU responds to interrupts by saving the current value of the program counter and resetting the program counter to a new address of the interrupt handler. This allows the CPU to return to executing at the point the interrupt occurred, after it has executed a procedure for handling the interrupt. The address the CPU jumps to is determined by the hardware architecture. On some machines, a unique address is associated with each interrupt. More commonly, the architecture defines an address in memory to be location of an interrupt vector. Each interrupt is associated with an index into that vector. The branch address is determined by the contents of the memory location in the vector pointed to by the interrupt’s index. Other status information is stored in a special register called Program Status Word (PSW) register. With interrupts, the processor can be engaged in executing other instructions while an I/O operation is in progress. For the user program, an interrupt suspends the normal sequence of execution. When the interrupt processing is completed, execution resumes. See the following fig 5. User Program Interrupt Handler 1 2 i . . . . . . i+1 . . . . M Fig 1.6: Transfer of control via Interrupts To accommodate interrupts, an interrupt stage is added to the instruction cycle. In the interrupt stage, the processor checks to see if any interrupt have occurred, indicated by the presence of an interrupt signal. If no interrupts are pending, the processor suspends execution of current program and executes an interrupt-handler routine. The interrupthandler routine is generally part of the operating system. Typically, this routine determines the nature of the interrupt and performs whatever actions are needed. The following fig 6 shows the instruction cycle with interrupts. Operating Systems 8 Interrupts Disabled Start Fetch Next Instruction Execute Instruction Interrupts Enabled Check for interrupt; initiate interrupt handler Halt Fig 6: Instruction Cycle with Interrupts Interrupt processing: The occurrence of an interrupt triggers a number of events, both is the processor hardware and in software. The following fig 7 shows a typical sequence. The following is the sequence of events when an I/O operation is completed by the I/O device. Operating Systems 9