Operating Systems 2024-2025 Fall Semester PDF
Document Details
Uploaded by AmazedOctagon268
EELU - The Egyptian E-Learning University
2025
Dr. Wafaa Samy, Dr. Hanaa Eissa
Tags
Summary
These lecture notes cover basic concepts in operating systems. Topics include operating system operations, resource management, and introduction to operating systems. This document is lecture notes.
Full Transcript
Year: 2024-2025 Fall Semester Operating Systems Dr. Wafaa Samy Dr. Hanaa Eissa Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.1 Modified by Dr. Wafaa Samy Chapter 1:...
Year: 2024-2025 Fall Semester Operating Systems Dr. Wafaa Samy Dr. Hanaa Eissa Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.1 Modified by Dr. Wafaa Samy Chapter 1: Introduction (Part 3) Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018 Modified by Dr. Wafaa Samy Chapter 1: Introduction What Operating Systems Do Computer-System Organization Storage Structure Computer-System Architecture Operating-System Operations (Cont.) Resource Management Security and Protection Virtualization Distributed Systems Computing Environments Free/Libre and Open-Source Operating Systems Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.3 Modified by Dr. Wafaa Samy Dual-mode Operation Dual-mode operation allows OS to protect itself and other system components: User mode and kernel mode (also called supervisor mode, system mode, or privileged mode). Mode bit provided by hardware: Provides ability to distinguish when system is running user code or kernel code. When a user code is running mode bit = 1 is “user”. When a kernel code is executing mode bit = 0 is “kernel”. How do we guarantee that user does not explicitly set the mode bit to “kernel”? A user application requests a service from the operating system via a system call. System call changes mode bit to kernel mode, and return from system call resets it to user mode. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.4 Modified by Dr. Wafaa Samy Dual-mode Operation (Cont.) Some instructions designated as privileged, only executable in kernel mode. If an attempt is made to execute a privileged instruction in user mode, the hardware does not execute the instruction but rather treats it as illegal and traps it to the operating system. The instruction to switch to kernel mode is an example of a privileged instruction. Some other examples include I/O control, timer management, and interrupt management. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.5 Modified by Dr. Wafaa Samy Transition from User to Kernel Mode At system boot time, the hardware starts in kernel mode. The OS is then loaded and starts user applications in user mode. Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel mode (i.e. changes the mode bit to 0). When the OS gains control of the computer, it is in kernel mode. The system always switches to user mode (i.e. by setting the mode bit to 1) before passing control to a user program. Eventually, control is switched back to the operating system via an interrupt, a trap, or a system call. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.6 Modified by Dr. Wafaa Samy Timer We must ensure that the operating system maintains control over the CPU. We cannot allow a user program to get stuck in an infinite loop or to fail to call system services and never return control to the operating system. To accomplish this goal, we can use a timer. Clearly, instructions that modify the content of the timer are privileged. Before turning over control to the user, the operating system ensures that the timer is set to interrupt. If the timer interrupts, control transfers automatically to the operating system. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.7 Modified by Dr. Wafaa Samy Timer (Cont.) Timer to prevent infinite loop (or process hogging resources): Set up before scheduling process to regain control or terminate program that exceeds allotted time. Operating system set the counter (privileged instruction). 1. Timer is set to interrupt the computer after some time period. 2. Keep a counter that is decremented by the physical clock. 3. When counter zero generate an interrupt. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.8 Modified by Dr. Wafaa Samy Resource Management OS is a resource manager Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.9 Modified by Dr. Wafaa Samy Process Management A process is a program in execution. It is a unit of work within the system. Program is a passive entity. Process is an active entity. Process needs resources (e.g. CPU, memory, I/O, files, etc.) to accomplish its task: These resources are allocated to the process while it is running. In addition, Initialization data (input) may be passed along. Process termination requires reclaim of any reusable resources. For example, consider a process running a web browser whose function is to display the contents of a web page on a screen. The process will be given the URL as an input and will execute the appropriate instructions and system calls to obtain and display the desired information on the screen. Typically system has many processes, (some user processes and some OS processes) running concurrently on one or more CPUs. All these processes can potentially execute: Concurrently by multiplexing on a single CPU core, or In parallel across multiple CPU cores. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.10 Modified by Dr. Wafaa Samy Process Management (Cont.) A process is a program being executed. A process can be further divided into independent units known as threads. A thread is like a small light-weight process within a process. Single-threaded process has one program counter specifying location of next instruction to execute. The CPU executes instructions of the process sequentially, one at a time, until the process completes. Multi-threaded process has one program counter per thread. The operating system is responsible for the following activities in connection with process management: 1. Creating and deleting both user and OS processes. 2. Scheduling processes and threads on the CPUs. 3. Suspending and resuming processes. 4. Providing mechanisms for process synchronization. 5. Providing mechanisms for process communication. 6. Providing mechanisms for deadlock handling. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.11 Modified by Dr. Wafaa Samy Memory Management To execute a program: All (or part) of the instructions must be in memory. All (or part) of the data that is needed by the program must be in memory. Memory management determines what is in memory and when: Optimizing CPU utilization and computer response to users (must keep several programs in memory at the same time to do that). Eventually, the program terminates, its memory space is declared available, and the next program can be loaded and executed. OS is responsible for the following memory management activities: 1. Keeping track of which parts of memory are currently being used and which process is using them. 2. Allocating and deallocating memory space as needed. 3. Deciding which processes (or parts of processes) and data to move into and out of memory. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.12 Modified by Dr. Wafaa Samy File-system Management OS provides uniform, logical view of information storage: Abstracts physical properties to logical storage unit - file. Each medium is controlled by device (i.e. disk drive, tape drive): Varying properties include access speed, capacity, data-transfer rate, access method (sequential or random). File-System management: Files usually organized into directories. Access control on most systems to determine who can access what (for example, read, write, append, etc.). OS activities include: 1. Creating and deleting files and directories. 2. Primitives to manipulate files and directories. 3. Mapping files onto secondary storage. 4. Backup files onto stable (non-volatile) storage media. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.13 Modified by Dr. Wafaa Samy Mass-Storage Management Usually disks used to store data that does not fit in main memory or data that must be kept for a “long” period of time. Proper management is of central importance. Entire speed of computer operation hinges on disk subsystem and its algorithms. OS activities: 1. Partitioning. 2. Mounting and unmounting. 3. Free-space management. 4. Storage allocation. 5. Disk scheduling: Multiple I/O requests may arrive by different processes and only one I/O request can be served at a time by the disk controller. Thus, other I/O requests need to wait in the waiting queue and need to be scheduled. 6. Protection. Mounting a file system (e.g. NTFS or FAT) is making the file system available for use by the system and its users. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.14 Modified by Dr. Wafaa Samy Cache Management Caching is an important principle, performed at many 1. First, check the levels in a computer (in hardware, operating system, cache memory software). for the required Information in use copied from slower to faster data, if it exists storage temporarily. use it directly. 2. Else, check main It is smaller than storage being cached: memory for the required data, if Cache management important design problem. it exists take a Cache size and replacement policy. copy to the Faster storage (cache) checked first to determine if cache memory then use it from information is there: cache memory. If it is, information used directly from the cache (fast). 3. Else, take a copy from hard If not, data copied to cache and used there. disk to the main memory then take a copy to Main Hard CPU the cache Memory Disk memory then use it from cache memory. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.15 Modified by Dr. Wafaa Samy Characteristics of Various Types of Storage Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.16 Modified by Dr. Wafaa Samy Migration of data “A” from Disk to Register Multitasking environments must be careful to use most recent value, no matter where it is stored in the storage hierarchy. Example: Increment the value of A by 1. A exists in the hard disk, then it is copied to memory, cache, and register. Thus, the copy of A appears in several places: on the hard disk, in main memory, in the cache, and in an internal register. Once the increment takes place in the internal register, the value of A differs in the various storage systems. The value of A becomes the same only after the new value of A is written from the internal register back to the hard disk. Multiprocessor environment must provide cache coherency in hardware such that all CPUs have the most recent value in their cache. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.17 Modified by Dr. Wafaa Samy I/O Subsystem One purpose of OS is to hide peculiarities of hardware devices from the user. Only the device driver knows the peculiarities of the specific device to which it is assigned. We discussed earlier how interrupt handlers and device drivers are used in the construction of efficient I/O subsystems. The I/O subsystem consists of several components: A memory-management of I/O component that includes buffering (storing data temporarily while it is being transferred), caching (storing parts of data in faster storage for performance), and spooling (A spool is a buffer that holds output for a device, such as a printer, that cannot accept interleaved data streams). A general device-driver interface. Drivers for specific hardware devices. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.18 Modified by Dr. Wafaa Samy I/O Structure Two methods for handling I/O: 1. Synchronous: After I/O starts, control returns to user program only upon I/O completion. A process is moved to the wait queue when an I/O request is made, and moved back to the ready queue when the request completes, allowing other processes to run in the meantime. 2. Asynchronous: After I/O starts, control returns to user program without waiting for I/O completion. One approach for programmers to implement non-blocking (i.e. asynchronous) I/O is to have a multi- threaded application. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.19 Modified by Dr. Wafaa Samy Security and Protection Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.20 Modified by Dr. Wafaa Samy Protection If a computer system has multiple users and allows the concurrent execution of multiple processes, then access to data must be regulated. Protection – any mechanism for controlling access of processes or users to resources defined by the OS. Mechanisms 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. Device-control registers are not accessible to users, so the integrity of the various peripheral devices is protected. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.21 Modified by Dr. Wafaa Samy Security A system can have adequate protection but still be prone to failure and allow inappropriate access. Consider a user whose authentication information (e.g. user name and password) is stolen. The user data could be copied or deleted, even though file and memory protection are working. It is the job of security. Security – defense of the system against internal and external attacks. The attacks 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), etc. Prevention of some of these attacks is considered an OS function on some systems, while other systems leave it to additional software. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.22 Modified by Dr. Wafaa Samy Protection and Security Protection and security require the system to be able to distinguish among all its users, to determine who can do what: User identities (user IDs, security IDs) include name and associated number (unique), one per user. User ID then associated with all files, processes, and threads of that user to determine access control. Group identifier (group ID) allows set of users to be defined and controls managed, then also associated with each file, process, and thread. Privilege escalation allows user to change to effective ID with more rights. A user sometimes needs to escalate privileges to gain extra permissions for an activity. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.23 Modified by Dr. Wafaa Samy Virtualization Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.24 Modified by Dr. Wafaa Samy Virtualization Virtualization allows operating systems to run as applications within other operating systems. It abstracts the hardware of a single computer (CPU, memory, disk drives, etc.) into several different execution environments. These environments can be viewed as different individual operating systems (e.g. Windows and UNIX) that may be running at the same time and may interact with each other. Example: An Apple laptop running mac OS on the x86 CPU can run a Windows 10 guest to allow execution of Windows applications. For virtualization, VMware is an application that ran on Windows. It ran one or more guest copies of Windows or other native x86 operating systems, each running its own applications. Windows was the host OS, and the VMware application was the virtual machine manager (VMM). VMM provides virtualization services. The VMM runs the guest operating systems, manages their resource use, and protects each guest from the others. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.25 Modified by Dr. Wafaa Samy Computing Environments - Virtualization On laptops and desktops, a VMM allows the user to install multiple operating systems for exploration or to run applications written for operating systems other than the native host. A computer running (a) a single operating system and (b) three virtual machines. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.26 Modified by Dr. Wafaa Samy Distributed Systems Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.27 Modified by Dr. Wafaa Samy Distributed Systems A distributed system is a collection of separate, possibly heterogeneous, computer systems networked to provide users with access to the various shared resources. Access to a shared resource increases computation speed, functionality, data availability, and reliability. A network is a communication path between two or more systems. TCP/IP is the most common network protocol. Networks are characterized based on the distances between their nodes: Local Area Network (LAN) connects computers within a room, a building, or a campus. Wide Area Network (WAN) usually links buildings, cities, or countries. Metropolitan Area Network (MAN) could link buildings within a city. Personal Area Network (PAN) between a smartphone and a desktop computer (i.e. using BlueTooth). Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.28 Modified by Dr. Wafaa Samy Distributed Systems (Cont.) A network operating system is an operating system that provides features (such as file sharing) across the network, along with a communication scheme that allows different processes on different computers to exchange messages. A computer running a network operating system acts autonomously from all other computers on the network, although it is aware of the network and is able to communicate with other networked computers. A distributed operating system provides a less autonomous environment. The different computers communicate closely enough to provide the illusion that only a single operating system controls the network. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.29 Modified by Dr. Wafaa Samy Computer System Environments How operating systems are used in a variety of computing environments? The operating systems are used in a variety of computing environments: 1. Traditional 2. Mobile 3. Client Server 4. Peer-to-Peer 5. Cloud Computing 6. Real-Time Embedded Systems Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.30 Modified by Dr. Wafaa Samy 1. Traditional Stand-alone general-purpose machines. 1. Consider the “typical office environment”: Just a few years ago, this environment consisted of PCs connected to a network, with servers providing file and print services. Remote access was difficult, and portability was achieved by use of laptop computers. Today, web technologies and increasing WAN bandwidth allow companies to establish portals, which provide web accessibility to their internal servers. 2. At home: Most users once had a single computer with a slow modem connection to the office, the Internet, or both. Today, network-connection speeds once available only at great cost are relatively inexpensive, giving home users more access to more data. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.31 Modified by Dr. Wafaa Samy 2. Mobile Mobile computing refers to computing on smartphones, tablets, etc. These devices share the distinguishing physical features of being portable and lightweight. Two operating systems currently dominate mobile computing: Apple iOS and Google Android. What is the functional difference between mobile devices and a “traditional” laptop? 1. Today, mobile systems are used not only for e-mail and web browsing. Extra feature – more OS features (GPS, accelerometers, and gyroscopes) allow new types of apps like augmented reality. 2. The memory capacity and processing speed of mobile devices are more limited than those of PCs. 3. Mobile devices use IEEE 802.11 wireless, or cellular data networks for connectivity. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.32 Modified by Dr. Wafaa Samy 3. Client Server ▪ Client-Server Computing: Contemporary network architecture features arrangements in which server systems satisfy requests generated by client systems: Dumb terminals supplanted by smart PCs. Servers responding to requests generated by clients. Example: File-server system provides an interface for clients to store and retrieve files (e.g. create, update, read, and delete files). An example of such a system is a web server that delivers files to clients running web browsers. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.33 Modified by Dr. Wafaa Samy 4. Peer-to-Peer Another model of distributed system. Peer-to-Peer (P2P) does not distinguish clients and servers: Instead all nodes are considered peers. May each act as client, server or Peer-to-peer system with both. no centralized service. ▪ Examples of peer-to-peer computing include Napster and Gnutella, Voice over IP (VoIP) such as Skype. Peer-to-peer networks gained widespread popularity in the late 1990s with several file-sharing services, such as Napster and Gnutella, that enabled peers to exchange files with one another. Skype allows clients to make voice calls and video calls and to send text messages over the Internet using a technology known as voice over IP (VoIP). Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.34 Modified by Dr. Wafaa Samy 5. Cloud Computing Cloud computing is a type of computing that delivers computing, storage, and even applications as a service across a network. Many types: e.g. Software as a Service (SaaS) – one or more applications available via the Internet (e.g. word processor or spreadsheets). It is a logical extension of virtualization because it uses virtualization as the base for its functionality. Cloud computing environments composed of traditional operating systems, plus VMMs that manage the virtual machines in which the user processes run, plus cloud management tools to manage VMMs. Internet connectivity requires security like firewalls. Load balancers spread traffic across multiple applications. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.35 Modified by Dr. Wafaa Samy 6. Real-Time Embedded Systems Embedded computers are the most prevalent form of computers in existence. These devices are found everywhere, from car engines and manufacturing robots to optical drives and microwave ovens. They tend to have very specific tasks. The systems they run on are usually primitive, and so the operating systems provide limited features. Usually, they have little or no user interface. These embedded systems vary considerably. Some are general-purpose computers, running standard operating systems—such as Linux—with special-purpose applications to implement the functionality. Others are hardware devices with a special-purpose embedded operating system providing just the functionality desired. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.36 Modified by Dr. Wafaa Samy 6. Real-Time Embedded Systems (Cont.) Embedded systems almost always run real-time operating systems. A real-time system has well-defined, fixed time constraints. Processing must be done within the defined constraints, or the system will fail. A real-time system functions correctly only if it returns the correct result within its time constraints. Contrast this system with a traditional laptop system where it is desirable (but not mandatory) to respond quickly. Systems that control scientific experiments, medical imaging systems, industrial control systems, and certain display systems are real-time systems. Some automobile-engine fuel-injection systems, home-appliance controllers, and weapon systems are also real-time systems. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.37 Modified by Dr. Wafaa Samy Question (1) What are the different types of interrupts? Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.38 Modified by Dr. Wafaa Samy Review: Different Types of Interrupts Hardware Interrupts: I/O completion interrupt (by device controllers). Timer interrupt. Software Interrupts: Exception or trap. System call. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.39 Modified by Dr. Wafaa Samy Question (2) Which of the following instructions should be privileged? a. Set value of timer. b. Read the clock. c. Clear memory. d. Issue a trap instruction. e. Turn off interrupts. f. Modify entries in device-status table. g. Access I/O device. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.40 Modified by Dr. Wafaa Samy Answer Which of the following instructions should be privileged? a. Set value of timer. b. Read the clock. c. Clear memory. d. Issue a trap instruction. e. Turn off interrupts. f. Modify entries in device-status table. g. Access I/O device. The red-colored operations need to be privileged. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.41 Modified by Dr. Wafaa Samy Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 1.42 Modified by Dr. Wafaa Samy