Unit - 1 Introduction to Operating Systems An operating system is a program that manages the computer hardware. It also provides a basis for application programs and acts as an intermediary between a user of a computer and the computer hardware. A computer system can be divided roughly into for components – the hardware, the operating system, the application programs and the users. The hardware consisting of CPU, memory and I/O devices provides the basic computing resources for the system. The application programs define the ways in which these resources are used to solve users computing problems. Fig: Abstract view of the components of a computer system The operating system controls and co-ordinates the use of hardware among the various application programs for the various users. User view of an Operating System: The user’s view of the computer varies according to the interface being used. While designing a PC for one user, the goal is to maximize the work that the user is performing. Here OS is designed mostly for ease of use. In another case the user sits at a terminal connected to a main frame or minicomputer. Other users can access the same computer through other terminals. OS here is designed to maximize resource utilization to assure that all available CPU time, memory and I/O are used efficiently. In other cases, users sit at workstations connected to networks of other workstations and servers. These users have dedicated resources but they also share resources such as networking and servers. Here OS is designed to compromise between individual usability and resource utilization. System view of an Operating System: From the computer’s point of view, OS can be viewed as resource allocator where in resources are – CPU time, memory space, file storage space, I/O devices etc. OS must decide how to allocate these resources to specific programs and users so that it can operate the computer system efficiently. OS is also a control program. A control program manages the execution of user programs to prevent errors and improper use of computer. It is concerned with the operation and control of I/O devices. Another service provided by the OS is of Resource manager. Resource management includes multiplexing resources in two ways - "in time" and "in space". (i)When a resource is time multiplexed different programs or different users gets their turn to use that resource. Ex: Printer. (ii)When a resource is space multiplexed instead of taking turns, the resource is shared among them, i.e. each one gets a part of the resource. Ex: Sharing main memory, hard disk etc. USER SERVICES PROVIDED BY AN OPERATING SYSTEM • Program creation - Editor and debugger utility programs • Program execution - Loading instructions, initializing I/O devices • Access to I/O devices - Making it a simple R/W command • Controlled access to files - Media technology, file format, controlling access • Error detection and response - internal and external hardware errors {memory error, device failure}, software errors {arithmetic overflow, access forbidden memory locations} OBJECTIVES OF AN OPERATING SYSTEM - An operating system makes a computer more convenient to use. - An operating system allows the computer system resources to be used in an efficient manner. - Should permit effective development, testing, and introduction of new system features and functions without interfering with service. Main frame systems These were the first computers used to tackle many commercial and scientific applications. They have evolved from simple batch systems to time-shared systems. Unit - 1 Batch systems These are the early computers that are physically enormous machines running from a console. The common input devices are card readers, tape drivers and some of the common output devices are Line printers, Tape drives, Card Punches. The user did not interact directly with the computer systems. Bring cards to 1401, Read cards onto input tape, Put input tape on 7094, perform the computation, writing results to output tape, Put output tape on 1401, which prints output. The operating system in these early computers was fairly simple. Its major task was to transfer control automatically from one job to the next. The operating system was always resident in memory. To speed up processing, operators batched together jobs with similar needs and ran them through the computer as a group. Thus, the programmers would leave their programs with the operator. The operator would sort programs into batches with similar requirements and, as the computer became available, would run each batch. The output from each job would be sent back to the appropriate programmer. The introduction of disk technology allowed the operating system to keep all jobs on a disk, rather than in a serial card reader. With direct access to several jobs, the operating system could perform job scheduling, to use resources and perform tasks efficiently. Multiprogrammed systems One of the most important aspects of OS is its ability to multi program. Multi programming increases CPU utilization by organizing jobs (code and data) so that the CPU always has one to execute. OS keeps several jobs in memory. This set of jobs can be a subset of jobs kept in the job pool which contains all jobs that enter the system. OS picks and begins to execute one of the jobs in memory. The job may have to wait for some task, such as I/O operation to complete. In a non multi programmed system, the CPU would sit idle. But here, the OS simply switches to and executes another job. When that job needs to wait, CPU is switched to another job and so on. As long as at least on job needs to execute, CPU is never idle. Multiprogramming is the first instance where the operating system must make decisions for the users. Multiprogrammed operating systems are therefore fairly sophisticated. All the jobs that enter the system are kept in the job pool. This pool consists of all processes residing on disk awaiting allocation of main memory. If several jobs are ready to be brought into memory, and if there is not enough room for all of them, then the system must choose among them. Making this decision is job scheduling. If several jobs are ready to run at the same time, the system must choose among them. Making this decision is CPU scheduling. Multi programmed systems provide an environment in which the various system resources are utilized effectively but they do not provide for user interaction with the computer system. Time- Sharing systems Unit - 1 Time-sharing or multi tasking is a logical extension of multi programming. In time sharing systems, CPU executes multiple jobs by switching among them but the switches occur so frequently that the users can interact with each program while it is running. Time-sharing requires an interactive computer system which provides direct communication between the user and the system. A time shared operating system allows many users to share the computer simultaneously. It uses CPU scheduling and multi programming to provide each user with a small portion of a time shared computer. A program loaded into memory and executing is called a process. Time sharing and multi programming require several jobs to be kept simultaneously in memory. Since main memory is too small to accommodate all jobs, the jobs are kept initially on the disk in the job pool. Time-sharing operating systems are even more complex than multiprogrammed operating systems. In Time sharing systems, to obtain a reasonable response time, jobs may have to be swapped in and out of main memory to the disk that now serves as a backing store for main memory. A common method for achieving this goal is virtual memory, which is a technique that allows the execution of a job that may not be completely in memory. The main advantage of the virtual-memory scheme is that programs can be larger than physical memory. Further, it abstracts main memory into a large, uniform array of storage, separating logical memory as viewed by the user from physical memory. This arrangement frees programmers from concern over memory-storage limitations. Desktop systems Once the personal computers PCs appeared in 1970’s, during the first decade, the CPUs in these PCs lacked the features of protection of OS from user programs. PC operating systems were neither multiuser nor multitasking. However as time passed, the goals of these operating systems shifted more towards maximizing user convenience and responsiveness. The PCs started running Microsoft Windows and Apple Macintosh. Linux, a UNIX-like operating system available for PCs, has also become popular recently. File protection was not a priority for these systems at first, but as these computers are now often tied into other computers over local-area networks or other Internet connections enabling other computers and users access the files on a PC, file protection again becomes a necessary feature of the operating system. The lack of such protection has made it easy for malicious programs to destroy data on systems such as MS-DOS and the Macintosh operating system. These programs may be self-replicating, and may spread rapidly via worm or virus mechanisms and disrupt entire companies or even worldwide networks. Security mechanisms capable of countering these attacks are to be implemented. Multiprocessor systems Systems that have more than one processor in close communication, sharing the computer bus, the clock, and sometimes memory and peripheral devices are called as multiprocessor systems (also called as parallel systems or tightly coupled systems). There are three main advantages with these multiprocessor systems. 1. Increased Throughput: If we increase number of processors, it takes less time to finish the task 2. Economy of scale: It saves more money because it shares the resources between the processors such as peripherals, mass storage and power supplies 3. Increased reliability: If functions can be distributed among several processors, then the failure of one processor will not halt the system, only slows it down The ability to continue providing service proportional to the level of surviving hardware is called graceful degradation. Systems designed for graceful degradation are also called fault tolerant. The most common multiple-processor systems now use symmetric multiprocessing (SMP), in which each processor runs an identical copy of the operating system, and these copies communicate with one another as needed. Here, all the processors are peers. Some systems use asymmetric multiprocessing (ASMP), in which each processor is assigned a specific task. A master processor controls the system; the other processors either look to the master for instructions or have predefined tasks. This scheme defines a master-slave relationship. The master processor schedules and allocates work to the slave processors. The difference between the multiprocessors is via the hardware or software. Unit - 1 Distributed systems Distributed systems depend on networking for their functionality. By being able to communicate, distributed systems are able to share computational tasks, and provide a rich set of features to users. Also called as Loosely coupled system – each processor has its own local memory; processors communicate with one another through various communications lines, such as high-speed buses or telephone lines. These systems have many advantages such as resource sharing, computation speedup (load sharing), reliability and communications. Distributed systems require networking infrastructure such as Local Area Networks (LAN) or Wide Area Networks (WAN). They may be clientserver or peer-to-peer systems. Client -Server Systems As PCs have become very powerful, faster and cheaper, the design interest has shifted from a centralized system to that of a client-server system. Centralized systems today act as server systems to satisfy requests generated by client systems. The general structure of a client-server system is depicted below: Server systems can be broadly categorized as compute servers and file servers. Compute-server systems provide an interface to which clients can send requests to perform an action, in response to which they execute the action and send back results to the client. File-server systems provide a file-system interface where clients can create, update, read, and delete files. Peer-to-Peer Systems The growth of computer networks -especially the Internet and World Wide Web (WWW) has had a profound influence on the recent development of operating systems. When PCs were introduced in the 1970s, they were designed for "personal" use and were generally considered standalone computers. With the beginning of widespread public use of the Internet in the 1980s for electronic mail, ftp, and gopher, many PCs became connected to computer networks. With the introduction of the Web in the mid-1990s, network connectivity became an essential component of a computer system. Virtually all modern PCs and workstations are capable of running a web browser for accessing hypertext documents on the Web. Operating systems (such as Windows, OS/2, Mac OS, and UNIX) now also include the system software (such as TCP/IP and PPP) that enables a computer to access the Internet via a local-area network or telephone connection. Several include the web browser itself, as well as electronic mail, remote login, and file-transfer clients and servers. Clustered systems: Like parallel systems, clustered systems gather together multiple CPUs to accomplish computational work. Clustered systems differ from parallel systems, however, in that they are composed of two or more individual systems coupled together. They are used to provide high availability. A layer of cluster software runs on the cluster nodes. Each node can monitor one or more of the others (over the LAN). If the monitored machine fails, the monitoring machine takes ownership of its storage and restarts the applications running on the failed machine. It has two types: Asymmetric Cluster: One machine is in hot – standby mode while the other is running the application. Hot – stand- by host does nothing but monitor the active server. If that server fails, the hot standby machine becomes the active server. Symmetric Cluster: Two or more hosts are running applications, and they are monitoring each other. More efficient as it uses all the available hardware Cluster technology is rapidly changing. Cluster directions include global clusters, in which the machines could be anywhere in the world. Clustered system use and features should expand greatly as storage –area-networks (SAN) become prevalent. Unit - 1 Real-time systems A real-time system is used when rigid time requirements have been placed on the operation of a processor or the flow of data; thus, it is often used as a control device in a dedicated application. A real-time system has well-defined, fixed time constraints. Processing must be done within the defined constraints, or the system will fail. Real-Time systems are of two types. A hard real-time system guarantees that critical tasks be completed on time. Due to the stringent time constraints, hard real-time systems conflict with the operation of time-sharing systems, and the two cannot be mixed. A less restrictive type of real-time system is a soft real-time system, where a critical real-time task gets priority over other tasks, and retains that priority until it completes. Though soft real-time system is an achievable goal, they have more limited utility than hard real-time systems and therefore risky to be used in industrial control and robotics. They are useful in several areas, including multimedia, virtual reality, and advanced scientific projectssuch as undersea exploration and planetary rovers. Hand held systems: Handheld systems includes personal Digital Assistants (PDAs) such as palm, pocket – pcs/ cellular telephones. The main challenge of this type system is limited size of the system. So, it holds small amount of storage space. One approach for displaying the content in webpage is web clipping, where only a small subset of a web page is delivered and displayed on the handheld device. Computer system: A common computer system consists of a CPU and a number of device controllers that are connected through a common bus that provides access to shared memory. Each device controller is in charge of a specific type of device as shown. The CPU and the device controllers can execute concurrently, competing for memory cycles. To ensure orderly access to the shared memory, a memory controller is provided whose function is to synchronize access to the memory. A bootstrap program is stored in read-only memory (ROM) within the computer hardware and it initializes all aspects of the system, from CPU registers to device controllers to memory contents. In order to load the operating system, the bootstrap program must locate and load into memory the operating-system kernel. The OS then starts executing the first process, such as “init”, and waits for some event to occur. The occurrence of an event is usually signaled by an interrupt from either the hardware or the software. Hardware may trigger an interrupt at any time by sending a signal to the CPU, usually by way of the system bus. Software may trigger an interrupt by executing a special operation called a system call (also called a monitor call). Events are almost always signaled by the occurrence of an interrupt or a trap. A trap (or an exception) is a software-generated interrupt caused either by an error (for example, division by zero or invalid memory access) or by a specific request from a user program that an operating-system service be performed. For each type of interrupt, separate segments of code in the operating system determine what action should be taken. An interrupt service routine is provided that is responsible for dealing with the interrupt. Interrupts are an important part of computer architecture. Each computer design has its own interrupt mechanism, but several functions are common. The interrupt must transfer control to the appropriate interrupt service routine. Interrupt vector contains the address of service routines. Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt. I/O Structure Unit - 1 A device controller maintains some local buffer storage and a set of special-purpose registers. The device controller is responsible for moving the data between the peripheral devices that it controls and its local buffer storage. The size of the local buffer within a device controller varies from one controller to another. I/O Interrupts Once the I/O is started, two kinds of I/O methods exist. In synchronous I/O, control returns to the user program only upon I/O completion. A special wait instruction idles CPU until next interrupt or some machines may have a wait loop: Loop: jmp Loop. No simultaneous I/O processing is present so, at most one outstanding I/O request at a time. Another possibility called asynchronous I/O returns control to the user program without waiting for the I/O to complete. The I/O then can continue while other system operations occur. A system call is needed to allow the user program to wait for I/O completion. The operating system uses a table containing an entry for each I/O device called the device-status table in which each entry indicates the device’s type, address and state as shown. Device-status table Since it is possible for other processes to issue requests to the same device, the operating system will also maintain a wait queue-a list of waiting requests-for each I/O device. An I/O device interrupts when it needs service. When an interrupt occurs, the operating system first determines which I/O device caused the interrupt. It then indexes into the I/O device table to determine the status of that device, and modifies the table entry to reflect the occurrence of the interrupt. For most devices, an interrupt signals completion of an I/O request. If there are additional requests waiting in the queue for this device, the operating system starts processing the next request. The main advantage of asynchronous I/0 is increased system efficiency. While I/0 is taking place, the system CPU can be used for processing or starting I/O’s to other devices. Because I/0 can be slow compared to processor speed, the system makes efficient use of its facilities. Unit - 1 DMA Structure Direct Memory Access is used for high speed I/O devices that are 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 one interrupt is generated per block, rather than one per byte (or word). Storage Structure Computer programs must be in main memory (also called random-access memory or RAM) to be executed. Main memory is implemented in a semiconductor technology called dynamic random-access memory (DRAM), which forms an array of memory words. A typical instruction -execution cycle, as executed on a system with a von Neumann architecture, will first fetch an instruction from memory and will store that instruction in the instruction register. The instruction is then decoded and may cause operands to be fetched from memory and stored in some internal register. After the instruction on the operands has been executed, the result may be stored back in memory. Since main memory is too small and it’s volatile, most computer systems provide secondary storage as an extension. The main idea is to store large quantities of data permanently. The most common secondary-storage device is a magnetic disk, which provides storage of both programs and data. Most programs (web browsers, compilers, word processors, spreadsheets, and so on) are stored on a disk until they are loaded into memory. Many programs then use the disk as both a source and a destination of the information for their processing. Hence, the proper management of disk storage is of central importance to a computer system. Main memory and the registers built into the processor itself are the only storage that the CPU can access directly. To allow more convenient access to I/O devices, many computer architectures provide memory-mapped I/O. In this case, ranges of memory addresses set aside, and are mapped to the device registers. Reads and writes to these memory addresses causes the data to be transferred to and from the device registers. A disk drive is attached to a computer by a set of wires called an I/0 bus. The data transfers on a bus are carried out by special electronic processors called controllers. The host controller is the controller at the computer end of the bus. A disk controller is built into each disk drive. To perform a disk I/0 operation, the computer places a command into the host controller, typically using memory mapped I/O ports. The host controller then sends the command via messages to the disk controller, and the disk controller operates the disk-drive hardware to carry out the command. Disk controllers usually have a built-in cache. Data transfer at the disk drive happens between the cache and the disk surface, and data transfer to the host, at fast electronic speeds, occurs between the cache and the host controller. Storage Hierarchy: The wide variety of storage systems in a computer system can be organized in a hierarchy according to speed and cost. The higher levels are expensive, but they are fast. As we move down the hierarchy, the cost per bit generally decreases, whereas the access time controller, typically using memory mapped I/O ports. The host controller then sends the command via messages to the disk controller, and the disk controller operates the diskdrive hardware to carry out the command. Disk controllers usually have a built-in cache. Data transfer at the disk drive happens between the cache and the disk surface, and data transfer to the host, at fast electronic speeds, occurs between the cache and the host controller. Storage Hierarchy: The wide variety of storage systems in a computer system can be organized in a hierarchy according to speed and cost. The higher levels are expensive, but they are fast. As we move down the hierarchy, the cost per bit generally decreases, whereas the access time generally increases. The top three levels of memory in above figure may be constructed using semiconductor memory. In the hierarchy shown above, the storage systems above the electronic disk are volatile, whereas those below are nonvolatile. An electronic disk can be designed to be either volatile or nonvolatile. Volatile storage loses its contents when the power to the device is removed. Unit - 1 Operating System Structures Such a large and a complex operating system can be created by partitioning it into smaller pieces and each piece should be a well-delineated portion of the system, with carefully defined inputs, outputs, and functions. Most common system components are Process Management, Main memory Management, I/O system Management, File Memory Management, Secondary storage Management, Networking Management, Protection Management and Command – Interpreter System Process Management A process is a program in execution. A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task. These resources are either given to the process when it is created, or allocated to it when it is running. Here program is a passive entity, such as the contents of a file stored on disk, whereas process is an active entity, with a program counter specifying the next instruction to execute. The execution of a process must be sequential. 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. Main Memory Management Main memory is a large array of words or bytes each with its own address. Main memory is a repository of quickly accessible data shared by the CPU and I/O devices. Many different memory management schemes are available and the effectiveness of the different algorithms depends on the particular situation. The operating system is responsible for the following activities in connection with memory management: Keeping track of which parts of memory are currently being used and by whom. Deciding which processes are to be loaded into memory when memory space becomes available. Allocating and de allocating memory space as needed. File Management File management is one of the most visible components of operating systems. Computers can store information on several different types of physical media each having its own characteristics and physical organization. A file is a collection of related information defined by its creator. It represents programs and data. The OS implements the abstract concept of a file by managing mass storage media, such as disks and tapes, and the devices that control them. The operating system is responsible for the following activities in connection with file management: Creating and deleting files Creating and deleting directories Supporting primitives for manipulating files and directories Mapping files onto secondary storage Backing up files on stable (nonvolatile) storage media. I/O –System Management One of the purposes of an operating system is to hide the peculiarities of specific hardware devices form the user. The I/O subsystem consists of A memory management component that includes buffering, caching and spooling. A general device – driver interface. Drivers for specific hardware devices Secondary storage management The main purpose of a computer system is to execute programs. These programs, with the data they access, must be in main memory, or primary storage, during execution. Because main memory is too small and volatile, the computer system must provide secondary storage to back up main memory. The operating system is responsible for the following activities in connection with disk management: Free – space management Storage allocation Unit - 1 Disk scheduling. Networking Distributed system is a collection of processors that do not share memory, peripheral devices, or a clock. Each processor has its own local memory and clock, and the processors communicate with one another through various communication lines, such as high – speed buses or networks. The processors in the system are connected through a communication network, which can be configured in a number of different ways. A distributed system collects physically separate, possibly heterogeneous systems into a single coherent system, providing the user with access to the various resources that the system maintains. Access to a shared resource allows computation speedup, increased functionality, increased data availability, and enhanced reliability. Operating systems usually generalize network access as a form of file access, with the details of networking being contained in the network interface's device driver. Protection System If a computer system has multiple users and allows the concurrent execution of multiple processes, then the various processes must be protected from one another’s activities. Protection is any mechanism for controlling the access of programs, processes, or users to the resources defined by a computer system. Protection can improve reliability by detecting latent errors at the interfaces between component subsystems. Early detection of interface errors can often prevent contamination of a healthy subsystem by another subsystem that is malfunctioning. Command-Interpreter System One of the most important systems programs for an operating system is the command interpreter, which is the interface between the user and the operating system. Some of the operating systems include the command interpreter in the kernel. When a new job is started in a batch system, or when a user logs on to a time – shared system, a program that reads and interprets control statements is executed automatically. This program is sometimes called the control – card interpreter or the command- line interpreter, and is often known as the shell. Its function is simple: To get the next command statement and execute it. The command statements themselves deal with process creation and management, I/O handling, secondary-storage management, main-memory management, file-system access, protection, and networking. Operating System services Operating system provides an environment for the execution of programs. It provides certain services to programs and to the users of those programs. Some of the common services provided by the operating systems are: Services that provide user-interfaces to OS - load program into memory and run it - since users cannot execute I/O operations directly - read, write, create, delete files - interprocess and intersystem - in hardware, I/O devices, user programs Services for providing efficient system operation - for simultaneously executing jobs - for account billing and usage statistics - ensure access to system resources is controlled System Calls System calls provide the interface between a running program and the operating system. They are generally available as assembly-language instructions. The languages defined to replace assembly language for systems programming allow system calls to be made directly (e.g., C, C++). Unit - 1 Three general methods are used to pass parameters between a running program and the operating system: , and the table address is passed as a parameter in a register -off the stack by operating system Different system calls are Process control end, abort load, execute create process, terminate process get process attributes, set process attributes wait for time wait event, signal event allocate and free memory File management create file, delete file open, close read, write, reposition get file attributes, set file attributes Device management request device, release device read, write, reposition get device attributes, set device attributes logically attach or detach devices Information maintenance get time or date, set time or date get system data, set system data get process, file, or device attributes set process, file, or device attributes Unit - 1 Communications There are two common models for communication 1. Message passing model 2. Shared memory model In message passing model, information is exchanged through an interprocess – communication facility provided by the OS. Before communication can take place, a condition must be opened. The name of the other communicator must be known be it another process on the same CPU / Process on another computer connected by a communications network. Message passing Shared Memory In shared memory, processes use map memory system calls to gain access to regions of memory owned other processes. They may then exchange information by reading and writing data in the shared area. Message passing is useful when smaller numbers of data need to be exchanged, because no conflicts need to be avoided. It is also easier to implement than is shared memory for inter-computer communication. Shared memory allows maximum speed and convenience of communication, as it can be done at memory speeds when within a computer. create, delete communication connection send, receive messages transfer status information attach or detach remote devices System Programs System programs provide a convenient environment for program development and execution. These can be divided into following categories: 1. File Management: These programs create, delete, copy, rename, print, dump, list and manipulate files and directories. 2. Status Information: It deals with the amount of memory or disk space, numbers of users, date, time or similar status information. 3. File Modification: Before modifying files, we should check whether the file is existing or not. If it is existing we can modify the files, if not error occurs. 4. Programming – Language Support: Compilers, assemblers and interpreters for common programming languages are often provided by the Operating System 5. Program loading and execution: Once the program is assembled or compiled, it must be loaded into memory to be executed. The system may provide loaders, linkage editors and overlay editors. 6. Communications: These programs provide the mechanism for creating virtual connections among processes, users, and different computer systems. They allow users to send messages to one another's screens, to browse web pages, to send electronic-mail messages, to log in remotely, or to transfer files from one machine to another. Unit - 1 Some programs such as web browsers, word processors and text formatters, spreadsheets, database systems, compilers, plotting and statistical-analysis packages, and games which come along with the OS and are used for common operations are called as system utilities or application programs. The most important system program for an operating system is the command interpreter, whose main function is to get and execute the next user-specified command.