Module 1-OS overview & Structures PDF
Document Details
Uploaded by LucrativeBananaTree
Tags
Summary
This document is about operating systems, covering an overview of operating system structures such as simple, layered, microkernel and modular systems. It also explains different types of operating systems, such as batch, time-sharing, multiprocessor and real-time systems, and discusses the functions of operating systems, including process, memory, file, I/O, disk management and protection and security.
Full Transcript
CST 206 – OPERATING SYSTEMS TEXTBOOK Syllabus Operating system overview – Operations – Functions Service – System calls – Types Operating System structure – Simple structure – Layered approach – Microkernel Modules – System boot process Wh...
CST 206 – OPERATING SYSTEMS TEXTBOOK Syllabus Operating system overview – Operations – Functions Service – System calls – Types Operating System structure – Simple structure – Layered approach – Microkernel Modules – System boot process What is an OS? Types of Operating Systems 1. Batch Systems 2. Multi-programmed systems 3. Time sharing / Multi-tasking systems 4. Multiprocessor systems 5. Clustered systems 6. Real time systems Functions of Operating System I/O Management One of the purposes of an operating system is to hide the peculiarities of specific hardware devices from the user. Every operating systems has an I/O subsystem for managing its I/O devices. Process Management A process is program in execution. A process needs certain resources to accomplish its task. – CPU time – memory – files – I/O devices. These resources are either given to the process when it is created or allocated to it while it is running. Process Management The operating system is responsible for the following process management activities : – Scheduling processes and threads on the CPUs – Creating and deleting both user and system processes – Suspending and resuming processes – Providing mechanisms for process synchronization – Providing mechanisms for process communication Memory Management Main memory is the only large storage device that the CPU is able to address and access directly. For a program to be executed, it must be mapped to absolute addresses and loaded into memory. As the program executes, it accesses program instructions and data from memory by generating these absolute addresses. When the program terminates, its memory space is declared available, and the next program can be loaded and executed. To improve both the utilization of the CPU and the speed of the computer’s response to its users, general-purpose computers must keep several programs in memory, creating a need for memory management. Memory Management The operating system is responsible for the following memory management activities : – Keeping track of which parts of memory are currently being used and who is using them – Deciding which processes (or parts of processes) and data to move into and out of memory – Allocating and deallocating memory space as needed Storage management-File-System Management Files represent programs (both source and object forms) and data. Data files may be numeric, alphabetic, alphanumeric, or binary. The operating system is responsible for the following file management activities Creating and deleting files Creating and deleting directories to organize files Supporting primitives for manipulating files and directories Mapping files onto secondary storage Backing up files on stable (non-volatile) storage media Disk Management Main memory is too small to accommodate all data and programs, and because the data that it holds are lost when power is lost, the computer system must provide secondary storage to back up main memory. Most modern computer systems use disks as the principal on- line storage medium for both programs and data. The operating system is responsible for the following activities in connection with disk management: Free-space management Storage allocation Disk scheduling Protection and Security If a computer system has multiple users and allows the concurrent execution of multiple processes, then access to data must be regulated. There must be mechanisms to ensure that files, memory segments, CPU, and other resources can be operated on by only those processes that have gained proper authorization from the operating system. For example, memory-addressing hardware ensures that a process can execute only within its own address space. The timer ensures that no process can gain control of the CPU without eventually relinquishing control. Protection and Security Protection is any mechanism for controlling the access of processes or users to the resources defined by a computer system. A system can have adequate protection but still be prone to failure and allow inappropriate access. Job of security is to defend a system from external and internal attacks. Protection and Security Attacks spread across a huge range and include viruses and worms, denial-of service attacks (which use all of a system’s resources and so keep legitimate users out of the system), identity theft, and theft of service (unauthorized use of a system). Prevention of some of these attacks is considered an operating-system function. Protection and security require the system to be able to distinguish among all its users. Most operating systems maintain a list of user names and associated user identifiers (user IDs) System Calls, Types ⚫ The mechanism used by an application program to request service from the operating system. ⚫ System calls causes the processor to change mode (e.g. to "supervisor mode" or "protected mode"). ⚫ This allows the OS to perform restricted actions such as accessing hardware devices or the memory management unit. System Calls ⚫ Systems calls are the programming interface to the services provided by the OS ⚫ Typically written in a high-level language (C or C++) Example of System Calls ⚫ System call sequence to copy the contents of one file to another file Working of system call User Mode: In this mode, execution is done on behalf of the user. Kernel-Mode: In this mode, execution is done on behalf of OS. System Call Implementation and Calling ⚫ Typically, ⚫ a number associated with each system call ⚫ Number used as an index to a table: System Call table ⚫ Table keeps addresses of system calls (routines) ⚫ System call runs and returns ⚫ Caller does not know system call implementation ⚫ Just knows interface Standard C Library Example ⚫C program invoking printf() library call, which calls the write() system call System Call Parameter Passing ⚫ Often, more information is required than simply identity of desired system call ⚫Exact type and amount of information vary according to OS and call ⚫ Three general methods used to pass parameters to the OS ⚫Simplest: pass the parameters in registers ⚫ In some cases, may be more parameters than registers ⚫Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register ⚫ This approach taken by Linux and Solaris ⚫Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system ⚫Block and stack methods do not limit the number or length of parameters being passed Parameter Passing via Table Accessing and executing System Calls ⚫ System calls typically not accessed directly by programs Program ⚫ Mostly accessed by programs via a high-level API (std Application Program Interface (API) (i.e. a library) lib) rather than direct system call use ⚫ Three most common APIs are : OS Sys Calls Rest of ⚫Win32 API for Windows, Kernel ⚫POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), ⚫Java API for the Java virtual machine (JVM) Types of System Calls ⚫ System calls can be grouped into six major categories: ⚫ Process control ⚫ Load, execute, end, abort, create process, get/set process attributes, wait for time/signal, allocate/free memory ⚫ File management (manipulation) ⚫ Create/delete/open/close/read/write a file, get/set file attributes ⚫ Device management ⚫ Request/release device, read/write data, get/set attributes ⚫ Information maintenance ⚫ Get/set time or date, get/set system data, get/set attributes for process/file/device ⚫ Communications ⚫ Create/delete connection, send/receive messages, attach/detach devices ⚫Protection:Protection provides a mechanism for controlling access to the resources provided by a computer system Types of System Calls 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 file read, write, reposition get and set file attributes Types of System Calls 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 and set process, file, or device attributes Communications create, delete communication connection send, receive messages transfer status information attach and detach remote devices Examples of Windows and Unix System Calls Operating System Structures ❏ Simple Structure ❏Monolithic Systems ❏Layered Systems ❏Micro Kernels ❏Modular It is the most SIMPLE STRUCTURE straightforward operating system structure, but it lacks definition and is only appropriate for usage with tiny and restricted systems. Since the interfaces and degrees of functionality in this structure are clearly defined, programs are able to access I/O routines, which may result in unauthorized access to I/O procedures Simple Structure example This organizational structure is used by the MS-DOS operating system: ○ There are four layers that make up the MS-DOS operating system, and each has its own set of features. ○ These layers include ROM BIOS device drivers, MS-DOS device drivers, application programs, and system programs. ○ The MS-DOS operating system benefits from layering because each level can be defined independently and, when necessary, can interact with one another. ○ If the system is built in layers, it will be simpler to design, manage, and update. Because of this, simple structures can be used to build constrained systems that are less complex. ○ When a user program fails, the operating system as whole crashes. ○ Because MS-DOS systems have a low level of abstraction, programs and I/O procedures are visible to end users, giving them the potential Monolithic Systems ⚫ Prominent in the early days. ⚫ In this approach entire operating system runs as a single program in kernel mode. ⚫ The operating system is written as a collection of procedures, linked together into a single large executable binary program. ⚫ When this technique is used, each procedure in the system is free to call any other one. Monolithic Systems ⚫ This organization suggests a basic structure for the operating system: 1. A main program that invokes the requested service procedure. 2. A set of service procedures that carry out the system calls. 3. A set of utility procedures that help the service procedures. ⚫ In this model, for each system call there is one service procedure that takes care of it and executes it. The utility procedures do things that are needed by several service procedures. Layered Approach ⚫In a layered approach, the operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface. ⚫Each layer uses functions (operations) and services of lower-level layers ie Layer n+1 uses services (exclusively) supported by layer n ⚫ Easier to extend and evolve. Layered Operating System Layered Operating System Advantage ⚫ Simplicity of construction and debugging. ⚫ Each layer uses functions (operations)and services of only lower-level layers. This approach simplifies debugging and system verification. ⚫ The first layer can be debugged without any concern for the rest of the system, because, it uses only the basic hardware to implement its functions. ⚫ Once the first layer is debugged, its correct functioning can be assumed while the second layer is debugged, and so on. ⚫ If an error is found during the debugging of a particular layer, the error must be on that layer, because the layers below it are already debugged. Thus, the design and implementation of the system are simplified. Layered Operating System Disadvantage ⚫ It is difficult to appropriately define the various layers. ⚫ Because a layer can use only lower-level layers, careful planning is necessary. ⚫ For example, the device driver for the backing store must be at a lower level than the memory-management routines, because memory management requires the ability to use the backing store. Example of Layered Operating System: THE Microkernel System Structure ⚫ Microkernel design achieves high reliability by splitting the operating system up into small, well-defined modules, only one of which—the microkernel—runs in kernel mode and the rest run as user processes. ⚫ Communication takes place between user modules using message passing. ⚫ By running each device driver and file system as a separate user process, a bug in one of these can crash that component, but cannot crash the entire system. ⚫ Thus a bug in the audio driver will cause the sound to be garbled or stop, but will not crash the computer. ⚫ In contrast, in a monolithic system with all the drivers in the kernel, a buggy audio driver can easily reference an invalid memory address and bring the system to halt instantly. Microkernel System Structure ⚫ Benefits: ⚫Easier to extend a microkernel ⚫Easier to port the operating system to new architectures ⚫More reliable (less code is running in kernel mode) ⚫More secure ⚫ Demerit: ⚫Performance overhead of user space to kernel space communication Microkernel System Structure- Eg:MINIX 3 system ⚫ Outside the kernel, the system is structured as three layers of processes all running in user mode. ⚫ The lowest layer contains the device drivers. Since they run in user mode, they do not have physical access to the I/O port space and cannot issue I/O commands directly. ⚫ To program an I/O device, the driver makes a kernel call telling the kernel to do the write. Microkernel System Structure- Eg:MINIX 3 system ⚫ Above the drivers is another user-mode layer containing the servers, which do most of the work of the operating system. One or more file servers manage the file system(s), the process manager creates, destroys, and manages processes, and so on. ⚫ User programs obtain operating system services by sending short messages to the servers asking for the POSIX system calls. For example, a process needing to do a read sends a message to one of the file servers telling it what to read Microkernel System Structure- Eg:MINIX 3 system ⚫ Reincarnation server check if the other servers and drivers are functioning correctly. If a faulty one is detected, it is automatically replaced without any user intervention. In this way the system is self healing and can achieve high reliability. Modular ⚫ Best current methodology for operating-system design involves using loadable kernel modules. ⚫ Here, the kernel has a set of core components and links in additional services via modules, either at boot time or during run time. ⚫ This type of design is common in modern implementations of UNIX, such as Solaris, Linux, and Mac OS X, as well as Windows. Modular ⚫ Kernel provides core services while other services are implemented dynamically, as the kernel is running. ⚫ Resembles a layered system in that each kernel section has defined, protected interfaces; but it is more flexible than a layered system, because any module can call any other module. ⚫ The approach is also similar to the microkernel approach in that the primary module has only core functions; but it is more efficient, because modules do not need to invoke message passing in order to communicate. Modular-Example :Solaris operating system structure Modular-Example :Solaris operating system structure ⚫The Solaris operating system structure, is organized around a core kernel with seven types of loadable kernel modules: 1. Scheduling classes 2. File systems 3. Loadable system calls 4. Executable formats 5. STREAMS modules 6. Miscellaneous 7. Device and bus drivers Booting of a Computer System 87 Why is Booting Required ? ►Hardware doesn’t know where the operating system resides and how to load it. ►Need a special program to do this job – Bootstrap loader. – E.g. BIOS – Basic Input Output System. ►Bootstrap loader locates the kernel, loads it into main memory and starts its execution. ►In some systems, a simple bootstrap loader fetches a more complex boot program from disk, which in turn loads the kernel. 88 How Boot process occurs ? ►Reset event on CPU (power up, reboot) causes instruction register to be loaded with a predefined memory location. It contains a jump instruction that transfers execution to the location of Bootstrap program. ►This program is form of ROM, since RAM is in unknown state at system startup. ROM is convenient as it needs no initialization and can’t be affected by virus. 89 BIOS Interaction 90 Tasks performed at boot up ►Run diagnostics to determine the state of machine. If diagnostics pass, booting continues. ►Runs a Power-On Self Test (POST) to check the devices that the computer will rely on, are functioning. ►BIOS goes through a preconfigured list of devices until it finds one that is bootable. If it finds no such device, an error is given and the boot process stops. ►Initializes CPU registers, device controllers and contents of the main memory. After this, it loads the OS. 91 BIOS Setup 92 Boot Procedure 93 Tasks performed at boot up (Contd) ►On finding a bootable device, the BIOS loads and executes its boot sector. In the case of a hard drive, this is referred to as the master boot record (MBR) and is often not OS specific. ►The MBR code checks the partition table for an active partition. If one is found, the MBR code loads that partition's boot sector and executes it. ►The boot sector is often operating system specific, however in most operating systems its main function is to load and execute a kernel, which continues startup. 94 Secondary Boot Loaders ►If there is no active partition or the active partition's boot sector is invalid, the MBR may load a secondary boot loader and pass control to it and this secondary boot loader will select a partition (often via user input) and load its boot sector. ►Examples of secondary boot loaders – GRUB – GRand Unified Bootloader – LILO – LInux LOader – NTLDR – NT Loader 95 GRUB Loader 96 Booting and ROM ►System such as cellular phones, PDAs and game consoles stores entire OS on ROM. Done only for small OS, simple supporting hardware, and rugged operation. ►Changing bootstrap code would require changing ROM chips. – EPROM – Erasable Programmable ROM. ►Code execution in ROM is slower. Copied to RAM for faster execution. 97 Questions ► (1) Why is ROM slower than RAM ? (2) How is the boot loader copied from ROM to RAM ? ► (1) Semi-conductor Technology used in constructing these two type of memories gives the answer. RAM is based on positive feedback/capacitive charge for storing the information while ROM contains permanent and non- changeable information stored in its structure. (2) There is a small routine loaded by the BIOS which does this task. This routine could also be part of BIOS 98 Network Operating Systems A network operating system (NOS) is a computer operating system ( OS) that's designed primarily to support workstations, PCs and terminals that are connected on a local area network (LAN). The software behind a NOS enables multiple devices within a network to communicate and share resources with each other. However, a typical NOS no longer exists, as most OSes have built-in network stacks that support a client-server model. A NOS coordinates the activities of multiple computers across a network. This can include such devices as PCs, printers, file servers and databases connected to a local network. The role of the NOS is to provide basic network services and features that support multiple input requests simultaneously in a multiuser environment. Types of NOS Types of NOS Peer to peer Client Server Model There is no dedicated server There are multiple clients and and clients. Each node acts as one server. a server and as well as client. Clients request for a service to Each node in the network can the server and the server request for a service and can responds back with the service. provide a service. The main focus is of sharing The main focus is to develop information. Data is stored at server side connectivity among the nodes. only. Client-Server is more stable and Each node store its own data. scalable than peer to peer Stability reduces when the network. number of nodes increases. Data management is Each user has its own data centralized. and applications. Previous year questions (2019 Scheme) Describe the role of bootstrap loader in booting a computer system. (3) How is distinction of kernel code from user code achieved at hardware level? (3) Which are the three methods used to pass parameters to operating system ? (3) Write three advantages of peer-to-peer system over client server system. (3) What are the operations taking place when a system call is executed? (3) What are multiprocessor systems? What are the advantages of multiprocessor systems? (3) What are the major activities of an operating system with regard to file management? (3) Write the operations taking place during the booting of a system. (3) Explain in detail about the various functions of operating system. (6/12) What is an Operating System? Explain any 3 types of Operating System. (7) What is a system call? What are the different ways to pass parameters to system call? List basic types of system call with examples. (7) Write notes on the following operating system structures. (i) Microkernel structure (ii) Simple Structure (iii) Layered Structure (8) Describe the differences between symmetric and asymmetric multiprocessing. What are the advantages and disadvantages of multiprocessor systems? (6) Explain the essential properties of the following types of Operating systems: i) Batch operating system ii) Time sharing operating system iii) Real time operating system iv) Distributed operating system (10) Explain the layered approach of the operating system structure. (4) Write notes on the following operating system structures. (8) – (i) Layered approach – (ii) Microkernel What is the purpose of a system call? Describe how a system call made by a user application is handled. (7) Explain the micro kernel approach to system design with the help of a diagram. How do user programs and kernel services interact in microkernel architecture? (7) Distinguish among the following terminologies associated with the operating system and explain each of them in detail. (9) – Multiprogramming systems – Multitasking systems – Multiprocessor systems Explain any four Kernel data structures with suitable examples. (8) Justify the statement “Operating System can be viewed as a government, resource allocator and a control program”. (6)