Document Details

UseableArtePovera

Uploaded by UseableArtePovera

DDU, School of Computing

Andualem T.

Tags

operating systems computer science kernel mode computer hardware

Summary

This document introduces operating systems, explaining concepts like kernel mode and user mode. It discusses the role of operating systems as an interface between users and hardware, and outlines the goals of an operating system. The document also touches upon different operating system types.

Full Transcript

Chapter One Introduction to Operating Systems 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 is a complex system. If every applica...

Chapter One Introduction to Operating Systems 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 is 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. The placement of operating system is between the user of a computer and computer hardware. Most computers have two modes of operation: kernel mode & user mode Kernel Mode: The operating system is the most fundamental piece of software and runs in kernel mode (also called supervisor mode). In this mode it has complete access to all the hardware and can execute any instruction the machine is capable of executing. While running in Kernel mode, the CPU can execute every instruction in its instruction set & uses every feature of the hardware. If programs are executed in kernel mode, then the program has direct access to the memory, CPU, I/O and other hardware resources. It is called privileged, system, master or supervisor mode because it has a direct access to many of the resources. But the problem is when a program executed in a kernel mode and if the program happens crash during its execution then the entire system should be crash. User mode: in which a subset of the machine instruction is available, in user mode not all instructions are allowed. When the computer is running application software, it is in user mode. Some examples are word application, PowerPoint, reading a PDF file and browsing the internet Instructions that affect control of the machine or do I/O (Input/output) are forbidden to user mode programs. If a program executed in user mode then that program does not have a direct access to the memory, CPU, I/O and other hardware resources. It is also called safer mode, less privileged mode, slave mode or restricted mode., because if a program is executed in user mode and if it happened halt, then the entire system will not crash or halt So, most of the program are executed in a user mode. N.B: The OS runs in kernel mode while User’s applications run in user mode. A kernel is a software program which is used to access hardware components of a computer system. Kernel works as middleware software for hardware and application software/user programs. Kernel mode is generally reserved for low level trusted functions of the operating system. DDU, School of Computing, compiled by Andualem T. Page 1 When the process is executing in user mode and if that process requires hardware resources such as RAM, printer etc, that process should send a request to the kernel. These requests are sent through system calls. Then the computer enters Kernel Mode from user mode. When the task is completed, the mode changes back to user mode from kernel mode. This transition is known as “context switching”. For user programs to obtain services from the operating system, a user-program must make a system call. Kernel mode is also called as system mode or privileged mode. It is not possible to run all processes in the kernel mode because if a process fails the entire operating system might fails. 1.1. Definition of an operating system An Operating System (OS) is an interface between user of the computer and computer hardware. An OS is a program that acts as an interface between the user and the computer hardware and controls the execution of all kinds of programs. It is software that manages the computer hardware. The hardware must provide appropriate mechanisms to ensure the correct operation of the computer system and to prevent user programs from interfering with the proper operation of the system. It is because of the operating system that users of a computer system don’t have to deal with computer’s hardware to get their work done. It is hard to pin down what an operating system is other than saying it is the software that runs in kernel mode and even that is not always true. Part of the problem is that operating systems perform two basically unrelated functions. Providing application programmers (and application programs, naturally) a clean abstract set of resources instead of the messy hardware ones and managing these hardware resources Goals of operating system  Make the computer system convenient to use-primary goal  Use the computer hardware in an efficient manner.  Execute user programs and make solving user problems easier Some popular Operating Systems include Some examples of operating systems are window, Linux, Ubuntu, MS-DOS, Mac OS x iOS, android, etc Computer system Organization 1. Hardware – provides basic computing resources (CPU, memory, I/O devices etc). DDU, School of Computing, compiled by Andualem T. Page 2 2. Operating system – controls and coordinates the use of the hardware among the various application programs for the various users. 3. Applications programs – define the ways in which the system resources are used to solve the computing problems of the users (compilers, database systems, video games, business programs). 4. Users (people, machines, other computers). Fig. 2 Abstract view of the components of a computer system Software Components A program is a sequence of instructions that enables a computer to execute a specific task. Before a program executes, it has to be translated from its original text form (source program) into a machine language program. The program then needs to be linked and loaded into memory. The software components are the collection of programs that execute in the computer. These programs perform computations and control, manage, and carry out other important tasks. There are two general types of software components: - System software, Application software. System software is the set of programs that control the activities and functions of the various hardware components, programming tools and abstractions, and other utilities to monitor the state of the computer system. The most important part of system software is the operating system (OS) that directly controls and manages the hardware resources of the computer. The OS also provides a set of services to the user programs. The most common examples of operating systems are Linux, Unix, Windows, MacOS, and OS/2. Application software is the user programs and consists of those programs that solve specific problems for the users and execute under the control of the operating system. Application programs are developed by individuals and organizations for solving specific problems. DDU, School of Computing, compiled by Andualem T. Page 3 Some basic knowledge of the structure of computer system is required to understand how operating system works. A modern general-purpose computer system consists of one or more CPUs and a number of device controllers connected through a common bus that provides access to shared memory. Each device controller is in charge of a specific type of device (for example, disk drives, audio devices, and video displays). 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 device driver is a software program written by device windows to let the device communicate with the operating system. E.g. Mouse driver- has to accept information from the mouse telling how far it has moved and which button are currently depressed. Every device connected in the computer has to be recognized by the operating system Booting: is the process of loading operating system in to a computer memory. When the CPU is interrupted, it stops what it is doing and immediately transfers execution to a fixed location. The fixed location usually contains the starting address where the service routine for the interrupt is located. The interrupt service routine executes; on completion, the CPU resumes the interrupted computation. DDU, School of Computing, compiled by Andualem T. Page 4 1.1.1 The Operating System as an Extended Machine One of the major tasks of the operating system is to achieve abstraction, is to hide the hardware and present programs (and their programmers) with nice, clean, elegant, consistent, abstractions to work with instead. Operating systems turn the ugly into the beautiful, as shown in Fig.1. Figure 1: Operating systems turn ugly hardware into beautiful abstractions Users and application programmers can communicate with an operating system through its interfaces. There are three general levels of interfaces provided by an operating system: -  Graphical user interface (GUI): allows I/O interaction with a user through intuitive icons, menus, and other graphical objects  Command line interpreter (also called the shell): is a text-oriented interface.  System-call interface: used by the application programs to request the various services provided by the operating system by invoking or calling system functions. 1.1.2 The Operating System as a Resource Manager The concept of an operating system as primarily providing abstractions to application programs is a top-down view. An alternative, bottom-up, view holds that the operating system is there to manage all the pieces of a complex system. The job of the operating system is to provide for an orderly and controlled allocation of the processors, memories, and I/O devices among the various programs wanting them. Modern operating systems allow multiple programs to be in memory and run at the same time. When a computer (or network) has more than one user, the need for managing and protecting the memory, I/O devices, and other resources is even more since the users might otherwise interfere with one another. Resource management includes multiplexing (sharing) resources in two different ways: in time and in space. In short, this view of the os holds that its primary task is to keep track of which programs are using which resource, to grant resource requests, to account for usage, and to mediate conflicting requests from different DDU, School of Computing, compiled by Andualem T. Page 5 programs and users. Resource management includes multiplexing (sharing) resources in two different ways: in time and in space When a resource is time multiplexed, different programs or users take turns using it. First one of them gets to use the resource, then another, and so on. E.g.  with only one CPU and multiple programs that want to run on it  Another example of time multiplexing is sharing the printer The other kind of multiplexing is space multiplexing. Instead of the customers taking turns, each one gets part of the resource. E.g.  main memory is normally divided up among several running programs, so each one can be resident at the same time  Another resource that is space multiplexed is the (hard) disk Jobs or functions of OS include:  Process Management  Resource Management  Memory Management  I/O management  File Management  Security 1.2. History of operating Systems – Computer Generation History of operating systems is tied very much to development of computer hardware and software. We will look about four generations of computer developments. First Generations (1945- 1955) vacuum tubes and plug boards The earliest electronic digital computers had no operating systems. Machines of the time were so primitive that programs were often entered one bit at time on rows of mechanical switches (plug boards). There was no programming language; everything was done in absolute machine language by wiring up plug boards Operating systems were unheard of. During this time computers were used for mathematical and scientific applications. These computers were called Calculating Engines. The hardware devices used for switching were relays and vacuum tubes. In 1950 punched cards were introduced. By then it was possible to write programs on cards and use the machines to read the cads. Second Generations (1955- 1965) transistors and batch systems Transistors were introduced and they replaced vacuum tubes as switches. Resident monitor: this is a system that loads the program into the computer, reading it from a tape or punched cards. This technology gave rise to the first operating system in history, created in 1950for an IBM 704 computer, which was responsible for loading programs successively (starting with the next one when the previous one had finished loading), reducing the work time required. DDU, School of Computing, compiled by Andualem T. Page 6 The system generally ran one job at a time. And there were professional operators to run the computers Steps for running a job:  Punch the program into punched card.  Bring the cards to the input room, hand it the operators  Operators will run the program and would print the output and give the result to the programmers. Computers processing time was wasted while operation was taking input, wait for output and giving the output to the programmer. The solutions for this problem were:  Collect a tray full of jobs  Read them into magnetic tapes /using specialized computers.  The operator then loads the program into the machine which read each tomb from the tape in sequence and run it. Special programs were developed at that time:  FORTRAN MONITOR SYSTEM /FMS/  IBSYS / IBM’s operating system for IBM 7094/ Third generation (1965-1980) - ICs and Multi Programming The systems of the 1960's were also batch processing systems, but they were able to take better advantage of the computer's resources by running several jobs at once. Integrated Circuits (IC): Small electronic circuit that includes all electronic components needed to do electrical switching, storing, amplifying etc. it Made largely by combining silicon with other materials Fourth Generation (1980-Present) personal computers Personal Computers were developed. LSI ICs were the dominant factor in the development of Personal computers. In LSI IC, thousands of transistors were packed into small space and several Calculation and storage could be done on small Chips. With the development of LSI (Large Scale Integration) circuits, chips, operating system entered in the personal computer and the workstation age. Microprocessor technology evolved to the point that it becomes possible to build desktop computers as powerful as the mainframes of the 1970s. Operating System Services Operating system has the following services Program execution: system capability to load a program into memory and to run it. The program must be able to end its execution, either normally or abnormally. I/O operations: since user programs cannot execute I/O operations directly, the operating system must provide some means to perform I/O. DDU, School of Computing, compiled by Andualem T. Page 7 File-system manipulation: program capability to read, write, create, and delete files. Communications: exchange of information between processes executing either on the same computer or on different systems tied together by a network. It implemented via shared memory or message passing. Error detection: ensure correct computing by detecting errors in the CPU and memory hardware, in I/O devices, or in user programs. Additional functions exist not for helping the user, but rather for ensuring efficient system operations. Resource allocation: allocating resources to multiple users or multiple jobs running at the same time. Accounting: keep track of and record which users use how much and what kinds of computer resources for account billing or for accumulating usage statistics. Protection: ensuring that all access to system resources is controlled. Operating System Calls System Calls provide the interface between a running program and the operating system. In general, system calls are available as assembly language instructions. System calls are usually made when a process in user mode requires access to a resource. Then it requests the kernel to provide the resource via a system call. In general, system calls are required in the following situations:  If a file system requires the creation or deletion of files. Reading and writing from files also require a system call.  Creation and management of new processes.  Network connections also require system calls. This includes sending and receiving packets.  Access to a hardware devices such as a printer, scanner etc. requires a system call. Three general methods are used to pass parameters between a running program and the operating system.  Pass parameters in registers. DDU, School of Computing, compiled by Andualem T. Page 8  Store the parameters in a table in memory, and the table address is passed as a parameter in a register.  Push (store) the parameters onto the stack by the program, and pop off the stack by operating system. Types of system calls There are mainly five types of system calls Process control: These system calls deal with processes such as process creation, process termination etc. File management: These system calls are responsible for file manipulation such as creating a file, reading a file, writing into a file etc. Device management: These system calls are responsible for device manipulation such as reading from device buffers, writing into device buffers etc Information maintenance: These system calls handle information and its transfer between the operating system and the user program. Communications: These system calls are useful for interprocess communication. They also deal with creating and deleting a communication connection. Some of the examples of all the above types of system calls in Windows and UNIX are given as follows 1.3. Types of operating systems and operating system structure Operating systems keep evolving over a period of time. Following are a few of the important types of operating system which are most commonly used. DDU, School of Computing, compiled by Andualem T. Page 9 1. Batch operating System The users of batch operating system do not interact with the computer directly. Each user prepares his/her 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. Thus, the programmers left their programs with the operator. The operator then sorts programs into batches with similar requirements. The advantage of batch operating system is:  No interaction between user and computer  No mechanism to prioritize the processes The problems with Batch Systems are the following.  CPU is often idle, because the speeds of the mechanical I/O devices are slower than CPU  Large turnaround time  Difficult to provide the desired priority 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 Multi programmed Batch Systems and Time-Sharing Systems is that in case of multi programmed 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, processor execute each user program in a short burst or quantum of computation. That is if n users are present, each user can get time quantum. When the user submits the command, the response time is in few seconds at most. Operating system uses CPU scheduling and multiprogramming to provide each users with a small portion of time. Computer systems that were designed primarily as batch systems have been modified to time-sharing systems. Advantages of Timesharing operating systems are the following  Provide advantage of quick response  Avoids duplication of software  Reduces CPU idle time Disadvantages of Timesharing operating systems are the following  Problem of reliability  Question of security and integrity of user programs and data DDU, School of Computing, compiled by Andualem T. Page 10  Problem of data communication 3. Distributed operating System Distributed systems use multiple central processors to serve multiple real time application and multiple users. Data processing jobs are distributed among the processors accordingly to which one can perform each job most efficiently. 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, and computers and so on. The advantages of distributed systems are following.  With resource sharing facility 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. 4. Server Operating Systems or Network Operating System They run on servers, which are very large personal computers, workstations, or even mainframes. They serve multiple users at once over a network and allow the users to share hardware and software resources. 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. Servers can provide print service, file service, or Web service. Internet providers run many server machines to support their customers and Websites use servers to store the Web pages and handle the incoming requests. Typical server operating systems are Solaris, FreeBSD, Microsoft Windows Server 2003, Microsoft Windows Server 2008, UNIX, Linux, and Mac OS X. The advantages of network operating systems are following.  Centralized servers are highly stable.  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 following.  High cost of buying and running a server.  Dependency on a central location for most operations.  Regular maintenance and updates are required. DDU, School of Computing, compiled by Andualem T. Page 11 5. Multiprocessor Operating Systems Multiprocessor operating system allows the multiple processors, and these processors are connected with physical memory, computer buses, clocks, and peripheral devices. Main objective of using multiprocessor operating system is to consume high computing power and increase the execution speed of system 6. Personal Computer Operating Systems Personal computer operating system provides a good interface to a single user. Personal computer operating systems are widely used for word processing, spreadsheets and Internet access. Personal computer operating systems are made only for personal. You can say that your laptops, computer systems, tablets etc. are your personal computers and the operating system such as windows 7, windows 10, Linux, FreeBSD, Apple’s OS X and android, etc. are your personal computer operating system. 7. Handheld Computer Operating Systems Continuing on down to smaller and smaller systems, we come to handheld computers. A handheld computer or PDA (Personal Digital Assistant) is a small computer that fits in a shirt pocket and performs a small number of functions, such as an electronic address book and memo pad. The OS that run son handhelds are increasingly sophisticated with the ability to handle telephony, photography and other functions. Two of the most popular operating systems for handhelds are Symbian OS and Palm OS. 8. Embedded Operating Systems. Embedded systems run on the computers that control devices that are not generally thought of as computers and which do not accept user-installed software. Typical examples are microwave ovens, TV sets, cars, DVD recorders, cell phones, MP3 players. The main property which distinguishes embedded systems from handhelds is the certainty that no untrusted software will ever run on it. You cannot download new applications to your microwave oven all the software is in ROM. This means that there is no need for protection between applications, leading to some simplification. Systems such as QNX and VxWorks are popular in this domain 9. Sensor Node Operating Systems Networks of tiny sensor nodes are being deployed for numerous purposes. These nodes are tiny computers that communicate with each other and with a base station using wireless communication. These sensor networks are used to protect the perimeters of buildings, guard national borders, detect fires in forests, measure temperature and precipitation for weather forecasting, glean information about enemy movements on battlefields, and much more. The sensors are small battery-powered computers with built-in radios TinyOS is a well-known operating system for a sensor node. DDU, School of Computing, compiled by Andualem T. Page 12 10. Real-Time Operating Systems These systems are characterized by having time as the key parameter. 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 image systems, industrial control systems, weapon systems, robots, air traffic control systems, etc. There are two types of real-time operating systems. 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. This goal says that all delays in the system must be restricted. 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 realities, Advanced Scientific Projects like undersea exploration and planetary rovers, etc. 11. Smart Card Operating Systems The smallest operating systems run on smart cards, which are credit card sized devices containing a CPU chip. They have very severe processing power and memory constraints. Some smart cards are Java oriented. This means that the ROM on the smart card holds an interpreter for the Java Virtual Machine (JVM). 1.4. Operating System structure For efficient performance and implementation an OS should be partitioned into separate subsystems, each with carefully defined tasks, inputs, outputs, and performance characteristics. These subsystems can then be arranged in various architectural configurations. The following are some typical structures of operating systems. 1. Simple Structure When DOS was originally written its developers had no idea how big and important it would eventually become. It was written by a few programmers in a relatively short amount of time, without the benefit of modern software engineering techniques, and then gradually grew over time to exceed its original DDU, School of Computing, compiled by Andualem T. Page 13 expectations. It does not break the system into subsystems, and has no distinction between user and kernel modes, allowing all programs direct access to the underlying hardware. (Note that user versus kernel mode was not supported by the 8088 chip set anyway, so that really wasn't an option back then. ) Fig. 4 MS-DOS layer structure The original UNIX OS used a simple layered approach, but almost all the OS was in one big layer, not really breaking the OS down into layered subsystems: 2. Monolithic system In this approach the entire operating system runs as a single program in kernel mode. The operating system is written as a collection of procedures, linked together in to a single large executable binary program. When this technique is used, each procedure in the system has a well-defined interface in terms of parameters and results, and each one is free to call any other one, if the latter provides some useful computation that the former needs. To construct the actual object program of the operating system, when this approach is used, one first compiles all the individual procedure and then binds (group) them all together in to a single executable file using the system linker. The services (system calls) provided by the operating system are requested by putting the parameters in a well-defined place (e.g., on the stack) and then executing a trap instruction. This instruction switches the machine from user mode to kernel mode and transfers control to the operating system. The operating system then fetches the parameters and determines which system call is to be carried out. This organization suggests a basic structure for the operating system. A main program that invoke (call up) the requested service procedure. DDU, School of Computing, compiled by Andualem T. Page 14 Fig. 5 Traditional UNIX system structure 3. Layered Approaches Another approach is to break the OS into a number of smaller layers, each of which rests on the layer below it, and relies solely on the services provided by the next lower layer. This approach allows each layer to be developed and debugged independently, with the assumption that all lower layers have already been debugged and are trusted to deliver proper services. The problem is deciding what order in which to place the layers, as no layer can call upon the services of any higher layer, and so many chicken-and-egg situations may arise. Layered approaches can also be less efficient, as a request for service from a higher layer has to filter through all lower layers before it reaches Fig. 6 A layered operating system DDU, School of Computing, compiled by Andualem T. Page 15 4. Microkernel’s The basic idea behind micro kernels is to remove all non-essential services from the kernel, and implement them as system applications instead, thereby making the kernel as small and efficient as possible. Most microkernels provide basic process and memory management, and message passing between other services, and not much more. Security and protection can be enhanced, as most services are performed in user mode, not kernel mode. System expansion can also be easier, because it only involves adding more system applications, not rebuilding a new kernel. Mach was the first and most widely known microkernel, and now forms a major component of Mac OSX. Windows NT was originally microkernel, but suffered from performance problems relative to Windows 95. NT 4.0 improved performance by moving more services into the kernel, and now XP is back to being more monolithic. Another microkernel example is QNX, a real-time OS for embedded systems. Fig. 7 Architecture of a typical microkernel 5. Modules  Most modern operating systems implement kernel modules  Uses object-oriented approach  Each core component is separate  Each talks to the others over known interfaces  Each is loadable as needed within the kernel  Overall, similar to layers but with more flexible Solaris Modular Approach DDU, School of Computing, compiled by Andualem T. Page 16

Use Quizgecko on...
Browser
Browser