edited os.pdf
Document Details
Uploaded by RazorSharpTropicalRainforest
Polytechnic University of the Philippines
Tags
Full Transcript
Republic of the Philippines POLYTECHNIC UNIVERSITY OF THE PHILIPPINES QUEZON CITY BRANCH Don Fabian St. Commonwealth, Quezon City Operating Systems Instructional Material Compiled by: Asst. Prof. Alma C. Fernandez email: [email protected]...
Republic of the Philippines POLYTECHNIC UNIVERSITY OF THE PHILIPPINES QUEZON CITY BRANCH Don Fabian St. Commonwealth, Quezon City Operating Systems Instructional Material Compiled by: Asst. Prof. Alma C. Fernandez email: [email protected] cp# 09174458146 Lesson 1: Operating Systems Concepts An operating system is a program that manages a computer’s hardware. It also provides a basis for application programs and acts as an intermediary between the computer user and the computer hardware. An amazing aspect of operating systems is how they vary in accomplishing these tasks. Mainframe operating systems are designed primarily to optimize utilization of hardware. Personal computer (PC) operating systems support complex games, business applications, and everything in between. Operating systems for mobile computers provide an environment in which a user can easily interface with the computer to execute programs. Thus, some operating systems are designed to be convenient, others to be efficient, and others to be some combination of the two [Abraham et. al]. Lesson Objectives To Summarize the objectives and functions of modern operating systems To Determine the functions of a contemporary operating system with respect to convenience, efficiency, and the ability to evolve. To Compare and contrast networked, client-server, distributed operating systems and single user operating systems. 1.1 What is an Operating System An operating system (OS) is a collection of software that manages computer hardware resources and provides common services for computer programs. The operating system is a vital component of the system software in a computer system. Operating systems can be viewed from two viewpoints: a.) In the resource-manager view, the operating system’s job is to manage the different parts of the system efficiently. b.) In the extended-machine view, the job of the system is to provide the users with abstractions that are more convenient to use than the actual machine. These include processes, address spaces, and files. An operating system is a program that acts as an interface between the user and the computer hardware and controls the execution of all kinds of programs. Page | 1 Fig 1.1 1.2 Functions of Operating Systems Following are some of important functions of an Operating System. a. Memory Management Memory management refers to management of Primary Memory or Main Memory. Main memory is a large array of words or bytes where each word or byte has its own address. Main memory provides a fast storage that can be accessed directly by the CPU. For a program to be executed, it must in the main memory. An Operating System does the following activities for memory management Keeps tracks of primary memory, i.e., what part of it are in use by whom, what part are not in use. In multiprogramming, the OS decides which process will get memory when and how much. Allocates the memory when a process requests it to do so. De-allocates the memory when a process no longer needs it or has been terminated. b. Processor Management In multiprogramming environment, the OS decides which process gets the processor when and for how much time. This function is called process scheduling. An Operating System does the following activities for processor management − Keeps tracks of processor and status of process. The program responsible for this task is known as traffic controller. Page | 2 Allocates the processor (CPU) to a process. De-allocates processor when a process is no longer required. c. Device Management An Operating System manages device communication via their respective drivers. It does the following activities for device management − Keeps tracks of all devices. Program responsible for this task is known as the I/O controller. Decides which process gets the device when and for how much time. Allocates the device in the efficient way. De-allocates devices. d. File Management A file system is normally organized into directories for easy navigation and usage. These directories may contain files and other directions. An Operating System does the following activities for file management − Keeps track of information, location, uses, status etc. The collective facilities are often known as file system. Decides who gets the resources. Allocates the resources. De-allocates the resources. Other Functions of Operating Systems a. Security − By means of password and similar other techniques, it prevents unauthorized access to programs and data. b. Control over system performance − Recording delays between request for a service and response from the system. c. Job accounting − Keeping track of time and resources used by various jobs and users. d. Error detecting aids − Production of dumps, traces, error messages, and other debugging and error detecting aids. e. Coordination between other software and users − Coordination and assignment of compilers, interpreters, assemblers and other software to the various users of the computer systems. 1.3 Goals of the Operating System Primary Goal: The primary goal of an Operating System is to provide a user-friendly and convenient environment. We know that it is not compulsory to use the Operating System, but things become harder when the user has to perform all the process scheduling and converting the user code into machine code is also very difficult. So, we make the use of an Operating System to act as an intermediate between us and the Page | 3 hardware. All you need to do is give commands to the Operating System and the Operating System will do the rest for you. So, the Operating System should be convenient to use. Secondary Goal: The secondary goal of an Operating System is efficiency. The Operating System should perform all the management of resources in such a way that the resources are fully utilized, and no resource should be held idle if some request to that resource is there at that instant of time. 1.4 Types of Operating System 1.4.1 Batch operating system The users of a batch operating system do not interact with the computer directly. Each user prepares his job on an off-line device like punch cards and submits it to the computer operator. To speed up processing, jobs with similar needs are batched together and run as a group. The programmers leave their programs with the operator and the operator then sorts the programs with similar requirements into batches. The problems with Batch Systems are as follows − Lack of interaction between the user and the job. CPU is often idle, because the speed of the mechanical I/O devices is slower than the CPU. Difficult to provide the desired priority. 1.4.2 Time-sharing operating systems Time-sharing is a technique which enables many people, located at various terminals, to use a particular computer system at the same time. Time-sharing or multitasking is a logical extension of multiprogramming. Processor's time which is shared among multiple users simultaneously is termed as time-sharing. The main difference between Multiprogrammed Batch Systems and Time- Sharing Systems is that in case of Multiprogrammed batch systems, the objective is to maximize processor use, whereas in Time-Sharing Systems, the objective is to minimize response time. Multiple jobs are executed by the CPU by switching between them, but the switches occur so frequently. Thus, the user can receive an immediate response. For example, in a transaction processing, the processor executes each user program in a short burst or quantum of computation. That is, if n users are present, then each user can get a time quantum. When the user submits the command, the response time is in few seconds at most. The operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of a time. Computer systems that were designed primarily as batch systems have been modified to time-sharing systems. Advantages of Timesharing operating systems are as follows − Page | 4 Provides the advantage of quick response. Avoids duplication of software. Reduces CPU idle time. Disadvantages of Time-sharing operating systems are as follows − Problem of reliability. Question of security and integrity of user programs and data. Problem of data communication. 1.4.3 Distributed operating System Distributed systems use multiple central processors to serve multiple real-time applications and multiple users. Data processing jobs are distributed among the processors accordingly. The processors communicate with one another through various communication lines (such as high-speed buses or telephone lines). These are referred as loosely coupled systems or distributed systems. Processors in a distributed system may vary in size and function. These processors are referred as sites, nodes, computers, and so on. The advantages of distributed systems are as follows − With resource sharing facility, a user at one site may be able to use the resources available at another. Speedup the exchange of data with one another via electronic mail. If one site fails in a distributed system, the remaining sites can potentially continue operating. Better service to the customers. Reduction of the load on the host computer. Reduction of delays in data processing. 1.4.4 Network operating System A Network Operating System runs on a server and provides the server the capability to manage data, users, groups, security, applications, and other networking functions. The primary purpose of the network operating system is to allow shared file and printer access among multiple computers in a network, typically a local area network (LAN), a private network or to other networks. Examples of network operating systems include Microsoft Windows Server 2003, Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD. The advantages of network operating systems are as follows − Centralized servers are highly stable. Page | 5 Security is server managed. Upgrades to new technologies and hardware can be easily integrated into the system. Remote access to servers is possible from different locations and types of systems. The disadvantages of network operating systems are as follows − High cost of buying and running a server. Dependency on a central location for most operations. Regular maintenance and updates are required. 1.4.5 Real Time operating System A real-time system is defined as a data processing system in which the time interval required to process and respond to inputs is so small that it controls the environment. The time taken by the system to respond to an input and display of required updated information is termed as the response time. So, in this method, the response time is very less as compared to online processing. Real-time systems are used when there are rigid time requirements on the operation of a processor, or the flow of data and real-time systems can be used as a control device in a dedicated application. A real-time operating system must have well- defined, fixed time constraints, otherwise the system will fail. For example, Scientific experiments, medical imaging systems, industrial control systems, weapon systems, robots, air traffic control systems, etc. Two types of real-time operating systems. a. Hard real-time Systems Hard real-time systems guarantee that critical tasks complete on time. In hard real- time systems, secondary storage is limited or missing, and the data is stored in ROM. In these systems, virtual memory is almost never found. b. Soft real-time systems Soft real-time systems are less restrictive. A critical real-time task gets priority over other tasks and retains the priority until it completes. Soft real-time systems have limited utility than hard real-time systems. For example, multimedia, virtual reality, Advanced Scientific Projects like undersea exploration and planetary rovers, etc. Page | 6 1.5 History of Operating Systems 1.5.1 The First Generation (1945 - 1955): Vacuum Tubes and Plugboards Digital computers were not constructed until the second world war. Calculating engines with mechanical relays were built at that time. However, the mechanical relays were very slow and were later replaced with vacuum tubes. These machines were enormous but were still very slow. The ENIAC (Electronic Numerical Integrator and Computer) was built by William Mauchley and his graduate student J. Presper Eckert. ENIAC is the first Electronic General-Purpose computer. These early computers were designed, built and maintained by a single group of people. Programming languages were unknown and there were no operating systems so all the programming was done in machine language. All the problems were simple numerical calculations. By the 1950’s punch cards were introduced and this improved the computer system. Instead of using plugboards, programs were written on cards and read into the system. 1.5.2 The Second Generation (1955 - 1965): Transistors and Batch Systems 1.5.3 The Third Generation (1965–1980): ICs and Multiprogramming 1.5.4 The Fourth Generation (1980–Present): Personal Computers Personal Computers were easy to create with the development of large- scale integrated circuits. These were chips containing thousands of transistors on a square centimeter of silicon. Because of these, microcomputers were much cheaper than minicomputers and that made it possible for a single individual to own one of them. The advent of personal computers also led to the growth of networks. This created network operating systems and distributed operating systems. The users were aware of a network while using a network operating system and could log in to remote machines and copy files from one machine to another. In 1971 Richard Matthew Stallman (RMS) joined MIT. At that time, all the programmers used to share their code freely. In 1980, software companies refused to share the code (copyright). In 1985, in response, Stallman, founded the Free Software Founda- tion (FSF) and published the GNU manifesto. Outlined his motivation for creating a free OS (GNU), which would be compatible with Unix. 1.5.5 The Fifth Generation (1990–Present): Mobile Computers Page | 7 The period of fifth generation is 1980-till date. In the fifth generation, VLSI technology became ULSI (Ultra Large Scale Integration) technology, resulting in the production of microprocessor chips having ten million electronic components. This generation is based on parallel processing hardware and AI (Artificial Intelligence) software. AI is an emerging branch in computer science, which interprets the means and method of making computers think like human beings. All the high-level languages like C and C++, Java,.Net etc., are used in this generation. AI includes − Robotics Neural Networks Game Playing Development of expert systems to make decisions in real-life situations Natural language understanding and generation The main features of fifth generation are − ULSI technology Development of true artificial intelligence Development of Natural language processing Advancement in Parallel Processing Advancement in Superconductor technology More user-friendly interfaces with multimedia features Availability of very powerful and compact computers at cheaper rates Some computer types of this generation are − Desktop Laptop NoteBook UltraBook ChromeBook Page | 8 Lesson 2: Computer System Structures A modern computer consists of one or more processors, some main memory, disks, printers, a keyboard, a mouse, a display, network interfaces, and various other input/output devices. All in all, a complex system. If every application programmer had to understand how all these things work in detail, no code would ever get written. Furthermore, managing all these components and using them optimally is an exceedingly challenging job. For this reason, computers are equipped with a layer of software called the operating system, whose job is to provide user programs with a better, simpler, cleaner, model of the computer and to handle managing all the resources just mentioned. Lesson Objectives Distinguish potential threats to operating systems and the security features designed to guard against them. Explain the concept of logical layer. Summarize the benefits of building abstract layers in hierarchical functions. Describe how computing resources are used to application software and manage by system software. Discuss the advantages and disadvantages of using interrupt processing. Explain the use of device list and driver I/O queues. 2.1 The Computer System A computer system can be divided roughly into four components: the hardware, the operating system, the application programs, and the users (Figure 2.1). Figure 2.1 Abstract view of the components of a computer system Page | 13 Four Components: 1. Hardware – provides basic computing resources e.g. CPU, memory, I/O devices 2. Operating system - Controls and coordinates use of hardware among various applications and users 3. Application programs – define the ways in which the system resources are used to solve the computing problems of the users. e. g. Word processors, compilers, web browsers, database systems etc… 4. Users e.g. People, machines, other computers We can also view a computer system as consisting of hardware, software, and data. The operating system provides the means for proper use of these resources in the operation of the computer system. An operating system is similar to a government. Like a government, it performs no useful function by itself. It simply provides an environment within which other programs can do useful work. Basic Elements of a Computer At a top level, 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 the computer, which is to execute programs. Thus, there are four main structural elements: 1. Processor: 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 central processing unit (CPU). 2. Main memory: Stores data and programs. This memory is typically volatile; that is, when the computer is shut down, the contents of the memory are lost. In contrast, the contents of disk memory are retained even when the computer system is shut down. Main memory is also referred to as real memory or primary memory 3. I/O modules: Move data between the computer and its external environment. The external environment consists of a variety of devices, including secondary memory devices (e.g., disks), communications equipment, and terminals. 4. System bus: Provides for communication among processors, main memory, and I/O modules. 2.2 Computer Startup (Bootup) Bootstrap program is loaded at power-up or reboot Typically stored in ROM or EPROM, generally known as firmware Initializes all aspects of system Page | 14 Loads operating system kernel and starts execution Very briefly, the boot process is as follows. Every PC contains a parentboard (formerly called a motherboard before political correctness hit the computer industry). On the parentboard is a program called the system BIOS (Basic Input Output System). The BIOS contains low-level I/O software, including procedures to read the keyboard, write to the screen, and do disk I/O, among other things. Nowadays, it is held in a flash RAM, which is nonvolatile but which can be updated by the operating system when bugs are found in the BIOS. When the computer is booted, the BIOS is started. It first checks to see how much RAM is installed and whether the keyboard and other basic devices are installed and responding correctly. It starts out by scanning the PCIe and PCI buses to detect all the devices attached to them. If the devices present are different from when the system was last booted, the new devices are configured. The BIOS then determines the boot device by trying a list of devices stored in the CMOS memory. The user can change this list by entering a BIOS configuration program just after booting. Typically, an attempt is made to boot from a CD-ROM (or sometimes USB) drive, if one is present. If that fails, the system boots from the hard disk. The first sector from the boot device is read into memory and executed. This sector contains a program that normally examines the partition table at the end of the boot sector to determine which partition is active. Then a secondary boot loader is read in from that partition. This loader reads in the operating system from the active partition and starts it. The operating system then queries the BIOS to get the configuration information. For each device, it checks to see if it has the device driver. If not, it asks the user to insert a CD-ROM containing the driver (supplied by the device’s manufacturer) or to download it from the Internet. Once it has all the device drivers, the operating system loads them into the kernel. Then it initializes its tables, creates whatever background processes are needed, and starts up a login program or GUI. 2.3 Traps and Interrupts Interrupt There are 2 kinds of interrupts; 1. Synchronous interrupts often called exceptions. [Generated by the CPU] 2. Asynchronous interrupts often called interrupts. [Generated by other Hardware devices] -External interrupt: issued by peripheral devices. -Trap: It is also called exception handling such as ‘divide by zero’, ‘segmentation faults’, ‘page faults’ and ‘system calls’. (trap is called also ‘software interrupt) -Interrupts and Traps are all handled in the same way at Linux. Classes of Interrupts Page | 15 2. Program - Generated by some condition that occurs as a result of an instruction execution, such as arithmetic overflow, division by zero, attempt to execute an illegal machine instruction, and reference outside a user's allowed memory space. 3. Timer - Generated by a timer within the processor. This allows the operating system to perform certain functions on a regular basis. 4. I/O - Generated by an I/O controller, to signal normal completion of an operation or to signal a variety of error conditions. 5. Hardware – Generated by a failure, such as power failure or memory parity error. 2.4 I/O Structure The controlling of various devices that are connected to the computer is a key concern of operating-system designers. This is because I/O devices vary so widely in their functionality and speed (for example a mouse, a hard disk and a CD-ROM), varied methods are required for controlling them. These methods form the I/O sub-system of the kernel of OS that separates the rest of the kernel from the complications of managing I/O devices. I/O Hardware Computers operate many huge kinds of devices. The general categories of storage devices are like disks, tapes, transmission devices (like network interface cards, modems) and human interface devices (like screen, keyboard, etc.). A device communicates with the operating system of a computer by transferring signals over cable or even through the air. The peripheral devices communicate with the machine through a connection point also called ports— (one example is a serial port). When devices use a set of wires or cables, that connecting cables are called a "bus." A bus is a collection of wires and a firmly defined protocol which specifies a set of messages that can be sent on the wires. Operating System Using I/O Port An I/O port usually consists of four different registers. These are (1) status, (2) control, (3) data-in, and (4) data-out registers. The data-in register is read by the host for getting input. The data-out register is written by the host for sending output. Page | 16 The status register holds bits which can be read by the host. The control register is written by the host for starting a command or for changing the mode of any device. The data registers are usually 1 to 4 bytes in size. Some of the controllers have FIFO chips which hold several bytes of input or output data for expanding the capacity of the controller beyond the size of the data register. 2.5 Storage Structure The computer storage devices include Primary and Secondary Storage devices. These are explained in detail as follows Primary Storage Devices - also known as the main memory and is the memory directly accessible by the CPU. Some primary storage devices are a. ROM or Read Only Memory - This memory cannot be changed, it can only be read as required. Since ROM is unchangeable memory, it is used by data and programs that are frequently required and seldom changed, like the system boot program. b. RAM or Random Access Memory. - It is volatile i.e. the data in RAM is lost when the power is switched off. RAM is the major form of primary memory as it is quite fast. However, it is also quite expensive. c. Cache – Is used to store data and instructions that are frequently required by the CPU so it doesn't have to search them in the main memory. This is a small memory that is also very fast. Secondary Storage Devices or external storage is not directly accessible by the CPU. The data from secondary storage needs to be brought into the primary storage before the CPU can use it. Secondary storage contains a large amount of data permanently. The different types of secondary storage devices are: a. Hard disks - The most famously used secondary storage devices. They are round, flat pieces of metal covered with magnetic oxide. They are available in many sizes ranging from 1 to 14-inch diameter. b. Floppy Disks - They are flexible plastic discs which can bend, coated with magnetic oxide and are covered with a plastic cover to provide protection. Floppy disks are also known as floppies and diskettes. Page | 17 c. Memory Card - This has similar functionality to a flash drive but is in a card shape. It can easily plug into a port and removed after its work is done. A memory card is available in various sizes such as 8GB, 16GB, 64GB, etc. d. Flash Drive - This is also known as a pen drive. It helps in easy transportation of data from one system to another. A pen drive is quite compact and comes with various features and designs. e. CD-ROM - This is short for compact disk - read only memory. A CD is a shiny metal disk of silver colour. It is already pre-recorded and the data on it cannot be altered. It usually has a storage capacity of 700 MB. Computer Storage Notations There are several storage notations. These are given in detail as follows: A bit is the smallest unit of memory storage. It can contain either 0 or 1. All other storage in a computer is based on collections of bits. A byte is 8 bits, and on most computers it is the smallest convenient chunk of storage. For example, most computers don’t have an instruction to move a bit but do have one to move a byte. A word, which is a given computer architecture’s native unit of data. A word is made up of one or more bytes. For example, a computer that has 64-bit registers and 64-bit memory addressing typically has 64-bit (8-byte) words. A computer executes many operations in its native word size rather than a byte at a time. Computer storage, along with most computer throughput, is generally measured and manipulated in bytes and collections of bytes. A kilobyte, or KB, is 1,024 bytes a megabyte, or MB, is 1,0242 bytes a gigabyte, or GB, is 1,0243 bytes a terabyte, or TB, is 1,0244 bytes a petabyte, or PB, is 1,0245 bytes Computer manufacturers often round off these numbers and say that a megabyte is 1 million bytes and a gigabyte is 1 billion bytes. Networking measurements are an exception to this general rule; they are given in bits (because networks move data a bit at a time). 2.6 Hardware Protection When executing in monitor mode, the operating system has unrestricted access to both monitor and user’s memory. The load instructions for the base and limit registers are privileged instructions. Page | 18 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. Four types of Hardware Protections 1. Dual-Mode Operation Sharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly. Provide hardware support to differentiate between at least two modes of operations. a. User mode – execution done on behalf of a user. b. Monitor mode (also kernel mode or system mode) – execution done on behalf of operating system. Mode bit added to computer hardware to indicate the current mode: monitor (0) or user (1). When an interrupt or fault occurs hardware switches to monitor mode. Privileged instructions can be issued only in monitor mode. 2. I/O Protection All I/O instructions are privileged instructions. Must ensure that a user program could never gain control of the computer in monitor mode (I.e., a user program that, as part of its execution, stores a new address in the interrupt vector). 3. Memory Protection Must provide memory protection at least for the interrupt vector and the interrupt service routines. In order to have memory protection, add two registers that determine the range of legal addresses a program may access: c. Base register – holds the smallest legal physical memory address. d. Limit register – contains the size of the range Memory outside the defined range is protected. 4. CPU Protection a..Timer – interrupts computer after specified period to ensure operating system maintains control. b. Timer is decremented every clock tick. c. When timer reaches the value 0, an interrupt occurs. Timer commonly used to implement time sharing. Time also used to compute the current time. Load-timer is a privileged instruction. Page | 19