Full Transcript

An operating system is software 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. Operating systems are everywhere, from cars and home appliances that include “Internet of Things” dev...

An operating system is software 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. Operating systems are everywhere, from cars and home appliances that include “Internet of Things” devices, to smart phones, personal computers, enterprise computers, and cloud computing environments. A fundamental responsibility of an operating system is to allocate the resources such as CPU, memory, and I/O devices, as well as storage to programs. Because an operating system is large and complex, it must be created piece by piece. Each of these pieces should be a well-delineated portion of the system, with carefully defined inputs, outputs, and functions. What Operating Systems Do? A computer system can be divided roughly into four components: the hardware, the operating system, the application programs, and a user (Figure 1). The operating system controls the hardware and coordinates its use among the various application programs for the various users. The operating system provides the means for proper use of these resources in the operation of the computer system. It simply provides an environment within which other programs can do useful work. We can explore operating system’s role, From two viewpoints: that of the user and that of the system. 1. User View The user’s view of the computer varies according to the interface being used (monitor, keyboard, mouse, touch screen, and voice recognition). In this case, the operating system is designed mostly for ease of use, with some attention paid to performance and security and none paid to resource utilization—how various hardware and software resources are shared. 2. System View From the computer’s point of view, an operating system can be viewed as a resource allocator. A computer system has many resources that may be required to solve a problem: CPU time, memory space, storage space, I/O devices, and so on. The operating system acts as the manager of these resources by allocating them to specific programs and users so that it can operate the computer system efficiently and fairly. It also can be viewed as control program that manages the execution of user programs to prevent errors and improper use of the computer. It is especially concerned with the operation and control of I/O devices. Operating-System Operations For a computer to start running it needs to have an initial or bootstrap program to run. A bootstrap program, tends to be simple. Typically, it is stored within the computer hardware in firmware. It initializes all aspects of the system, from CPU 1 registers to device controllers to memory contents. The bootstrap program must know where to locate the operating-system kernel and how to load it into memory. Once the kernel is loaded and executing, it can start providing services to the system and its users. Once this phase is complete, the system is fully booted, and the system waits for some event to occur. Multiprogramming and Multitasking One of the most important aspects of operating systems is the ability to run multiple programs. Multiprogramming increases CPU utilization, as well as keeping users satisfied, by organizing programs so that the CPU always has one to execute. In a multiprogrammed system, a program in execution is termed a process. The idea is as follows: The operating system keeps several processes in memory simultaneously (Figure 2). The operating system picks and begins to execute one of these processes. Eventually, the process may have to wait for some task, such as an I/O operation, to complete. In a non-multiprogrammed system, the CPU would sit idle. In a multiprogrammed system, the operating system simply switches to, and executes, another process. When that process needs to wait, the CPU switches to another process, and so on. Eventually, the first process finishes waiting and gets the CPU back. As long as at least one process needs to execute, the CPU is never idle. Multitasking is a logical extension of multiprogramming. In multitasking systems, the CPU executes multiple processes by switching among them, but the switches occur frequently, providing the user with a fast response time. When a process executes, it typically executes for only a short time before it either finishes or needs to perform I/O. Since interactive I/O typically runs at “people speeds,” it may take a long time to complete. Rather than let the CPU sit idle as this interactive input takes place, the operating system will rapidly switch the CPU to another process. If several processes are ready to run at the same time, the system must choose which process will run next. Making this decision is CPU scheduling. Finally, running multiple processes concurrently requires that their ability to affect one another be limited in all phases of the operating system, including process scheduling, disk storage, and memory management. 4 Resource Management As an operating system is a resource manager. The system’s CPU, memory space, file-storage space, and I/O devices are among the resources that the operating system must manage. 1. Process Management A program can do nothing unless its instructions are executed by a CPU. A program in execution, is a process. A programs such as a compiler, a word- processing program, and a social media app on a mobile device are processes. A process needs certain resources—including CPU time, memory, files, and I/O devices—to accomplish its task. These resources are typically allocated to the process while it is running. A single-threaded process has one program counter specifying the next instruction to execute. Thus, although two processes may be associated with the same program, they are nevertheless considered two separate execution sequences. A process is the unit of work in a system. A system consists of a collection of processes, some of which are operating-system processes (those that execute system code) and the rest of which are user processes (those that execute user code). The operating system is responsible for the following activities in connection with process management: Creating and deleting both user and system processes Scheduling processes and threads on the CPUs Suspending and resuming processes Providing mechanisms for process synchronization Providing mechanisms for process communication 2. Memory Management Main memory is a large array of bytes, ranging in size from hundreds of thousands to billions. The main memory is generally the only large storage device that the CPU is able to address and access directly. 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. In selecting a memory-management scheme for a specific system, we must take into account many factors—especially the hardware design of the system. Each algorithm requires its own hardware support. 5 The operating system is responsible for the following activities in connection with memory management: Keeping track of which parts of memory are currently being used and which process is using them Allocating and deallocating memory space as needed Deciding which processes (or parts of processes) and data to move into and out of memory 3. File-System Management Computers can store information on several different types of physical media. Secondary storage is the most common, but tertiary storage is also possible. Each of these media has its own characteristics and physical organization. Most are controlled by a device, that also has its own unique characteristics. These properties include access speed, capacity, data-transfer rate, and access method (sequential or random). A file is a collection of related information defined by its creator. Commonly, files represent programs (both source and object forms) and data. files are normally organized into directories to make them easier to use. The operating system is responsible for the following activities in connection with file management: Creating and deleting files Creating and deleting directories to organize files Supporting primitives for manipulating files and directories Mapping files onto mass storage Backing up files on stable (nonvolatile) storage media 4. Mass-Storage Management As we have already seen, the computer system must provide secondary storage to back up main memory. Most modern computer systems use HDDs and NVM devices as the principal on-line storage media for both programs and data. 6 The operating system is responsible for the following activities in connection with secondary storage management: Mounting and unmounting Free-space management Storage allocation Disk scheduling Partitioning Protection At the same time, there are many uses for storage that is slower and lower in cost (and sometimes higher in capacity) than secondary storage. Examples of these storage devices are magnetic tape drives and their tapes and CD DVD and Blu- ray drives and platters. 5. Cache Management Caching is an important principle of computer systems. Here’s how it works. Information is normally kept in some storage system (such as main memory). As it is used, it is copied into a faster storage system—the cache—on a temporary basis. When we need a particular piece of information, we first check whether it is in the cache. If it is, we use the information directly from the cache. If it is not, we use the information from the source, putting a copy in the cache under the assumption that we will need it again soon. Because caches have limited size, cache management is an important design problem. Careful selection of the cache size and of a replacement policy can result in greatly increased performance. Virtualization Virtualization is a technology that allows us to abstract the hardware of a single computer (the CPU, memory, disk drives, network interface cards, and so forth) into several different execution environments, thereby creating the illusion that each separate environment is running on its own private computer. These environments can be viewed as different individual operating systems (for example, Windows and UNIX) that may be running at the same time and may interact with each other. A user of a virtual machine can switch among the various operating systems in the same way a user can switch among the various processes running concurrently in a single operating system. On laptops and desktops, a VMM allows the user to install multiple operating systems for 7 exploration or to run applications written for operating systems other than the native host. Distributed Systems A distributed system is a collection of physically separate, possibly heterogeneous computer systems that are networked to provide users with access to the various resources that the system maintains. Access to a shared resource increases computation speed, functionality, data availability, and reliability. Some operating systems generalize network access as a form of file access, with the details of networking contained in the network interface’s device driver. 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. Linkers and Loaders Usually, a program resides on disk as a binary executable file—for example, a.out or prog.exe. To run on a CPU, the program must be brought into memory and placed in the context of a process. Source files are compiled into object files that are designed to be loaded into any physical memory location, a format known as an relocatable object file. Next, the linker combines these relocatable object files into a single binary executable file. During the linking phase, other object files or libraries may be included as well, such as the standard C or math library (specifiedwith the flag -lm). A loader is used to load the binary executable file into memory, where it is eligible to run on a CPU core. An activity associated with linking and loading is relocation, which assigns final addresses to the program parts and adjusts code and data in the program to match those addresses. When the icon associated with the executable file is double-clicked, the loader is invoked and then it loads the specified program into memory using the address space of the newly created process. The process described thus far assumes that all libraries are linked into the executable file and loaded into memory. In reality, most systems allow a program to dynamically link libraries as the program is loaded. Windows, for instance, supports dynamically linked libraries (DLLs). In this approach the library is conditionally linked and is loaded if it is required during program run time. Object files and executable files typically have standard formats that include the compiled machine code and a symbol table containing metadata about functions and variables that are referenced in the program. For UNIX and Linux systems, this standard format is known as ELF (for Executable and Linkable Format). Windows systems use the Portable Executable (PE) format, and macOS uses the Mach-O format. 8 The Process As mentioned earlier, a process is a program in execution. The status of the current activity of a process is represented by the value of the program counterand the contents of the processor’s registers. The memory layout of a process istypically divided into multiple sections, and is shown in Figure 1. These sections include:  Text section—the executable code  Data section—global variables  Heap section—memory that is dynamically allocated during program run time  Stack section—temporary data storage when invoking functions (such as function parameters, return addresses, and local variables) Although the stack and heap sections grow toward one another, the operating system must ensure they do not overlap one another. Although two processes may be associated with the same program, they are nevertheless considered two separate execution sequences. For instance, several users may be running different copies of the mail program, or the same user may invoke many copies of the web browser program. Each of these is a separate process; and although the text sections are equivalent, the data, heap, and stack sections vary. Process State As a process executes, it changes state. The state of a process is defined in part by the current activity of that process. A process may be in one of the following states:  New. The process is being created.  Running. Instructions are being executed.  Waiting. The process is waiting for some event to occur (such as an I/O  completion or reception of a signal).  Ready. The process is waiting to be assigned to a processor. Process Control Block Each process is represented in the operating system by a process control block (PCB)—also called a task control block. A PCB is shown in Figure 3. It contains many pieces of information associated with a specific process, including these: Process state. The state may be new, ready, running, waiting, halted, and so on. Program counter. The counter indicates9 the address of the next instruction to be executed for this process. CPU registers. The registers vary in number and type, depending on the computer architecture. They include accumulators, index registers, stack pointers, and general-purpose registers, plus any condition-code information. Along with the program counter, this state information must be saved when an interrupt occurs, to allow the process to be continued correctly afterward when it is rescheduled to run. CPU-scheduling information. This information includes a process priority, pointers to scheduling queues, and any other scheduling parameters. Memory-management information. This information may include such items as the value of the base and limit registers and the page tables, or the segment tables, depending on the memory system used by the operating system. Accounting information. This information includes the amount of CPU and real time used, time limits, account numbers, job or process numbers, and so on. I/O status information. This information includes the list of I/O devices allocated to the process, a list of open files, and so on. In brief, the PCB simply serves as the repository for all the data needed to start, or restart, a process, along with some accounting data. Process Scheduling To meet the objectives of multiprogramming and multitasking, the process scheduler selects an available process (possibly from a set of several available processes) for program execution on a core. Each CPU core can run one process at a time. If there are more processes than cores, excess processes will have to wait until a core is free and can be rescheduled. The number of processes currently in memory is known as the degree of multiprogramming. Balancing the objectives of multiprogramming and time sharing also requires taking the general behavior of a process into account. In general, most processes can be described as either I/O bound or CPU bound. An I/O-bound process is one that spends more of its time doing I/O than it spends doing computations. A CPU-bound process, in contrast, generates I/O requests infrequently, using more of its time doing computations. 10 Scheduling Queues As processes enter the system, they are put into a ready queue, where they are ready and waiting to execute on a CPU’s core. Processes that are waiting for a certain event to occur — such as completion of I/O — are placed in a wait queue (Figure 4). A common representation of process scheduling is a queueing diagram, such as that in Figure 5. CPU Scheduling A process migrates among the ready queue and various wait queues throughout its lifetime. The role of the CPU scheduler is to select from among the processes that are in the ready queue and allocate a CPU core to one of them. The CPU scheduler must select a new process for the CPU frequently. Some operating systems have an intermediate form of scheduling, known as swapping, whose key idea is that sometimes it can be advantageous to remove a process from memory (and from active contention for the CPU) and thus reduce the degree of multiprogramming. Later, the process can be reintroduced into memory, and its execution can be continued where it left off. Context Switch When an interrupt occurs, the system needs to save the current context of the process running on the CPU and restore the saved context of a different process in a task called context switch. The context is represented in the PCB of the process. It includes the value of the CPU registers, the process state (see Figure 2), and memory-management information. Generically, we perform a state save of the current state of the CPU core, be it in kernel or user mode, and then a state restore to resume operations(Figure 6). Context switch time is pure overhead, because the system does no useful work while switching. Switching speed varies from machine to machine, depending on the memory speed, the number of registers that must be copied, and the existence of special instructions (such as a single instruction to load or store all registers). A typical speed is a several microseconds. Context-switch times are highly dependent on hardware support. Also, the more complex the operating system, the greater the amount of work that must be done during a context switch. 11

Use Quizgecko on...
Browser
Browser