Operating Systems 2024-2025 Fall Semester PDF
Document Details
EELU - The Egyptian E-Learning University
2025
Dr. Wafaa Samy, Dr. Hanaa Eissa
Tags
Summary
These are lecture notes for Operating Systems, presented by Dr. Wafaa Samy and Dr. Hanaa Eissa at The Egyptian E-Learning University (Fall 2024-2025). The lecture notes cover services provided by the operating system for programs and users, including user interfaces (CLI, GUI, touch screen).
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 2.1 Modified by Dr. Wafaa Samy Chap...
Year: 2024-2025 Fall Semester Operating Systems Dr. Wafaa Samy Dr. Hanaa Eissa Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.1 Modified by Dr. Wafaa Samy Chapter 2: Operating-System Services (Part 1) Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 Modified by Dr. Wafaa Samy Outline Operating System Services User and Operating System-Interface System Calls System Services Linkers and Loaders Why Applications are Operating System Specific Design and Implementation Operating System Structure Building and Booting an Operating System Operating System Debugging Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.3 Modified by Dr. Wafaa Samy Operating System Services Operating systems provide an environment for execution of programs and provide services to programs and users. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.4 Modified by Dr. Wafaa Samy Operating System Services One set of operating-system services provides functions that are helpful to the user: 1. User interface - Almost all operating systems have a user interface (UI) varies between: Command-Line Interface (CLI): the user uses a keyboard for typing in text commands in a specific format with specific options. Graphics User Interface (GUI): the most commonly used. Touch-screen interface: provided by mobile systems such as phones and tablets. Some operating systems provide two or all of these UI variations. 2. Program execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error). 3. I/O operations - A running program may require I/O, which may involve a file or an I/O device. For efficiency and protection, users usually cannot control I/O devices directly. So, the OS must provide a means to do I/O. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.5 Modified by Dr. Wafaa Samy Operating System Services (Cont.) 4. File-system manipulation - The file system is of particular interest. Programs need to: Read and write files and directories. Create and delete files and directories by name. Search for a given file. List file Information. Permission management to allow or deny access to files or directories based on file ownership. 5. Communications – Processes may exchange information: Communications may occur between processes that are executing on the same computer or between processes that are executing on different computers over a network. Communications may be via shared memory (two or more processes read and write to a shared section of memory) or through message passing (packets of information in predefined formats are moved between processes by the OS). Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.6 Modified by Dr. Wafaa Samy Operating System Services (Cont.) 6. Error detection – OS needs to be detecting and correcting errors constantly. OS needs to be constantly aware of possible errors: May occur in the CPU and memory hardware (e.g. a memory error or a power failure), in I/O devices (e.g. a parity error on disk, a connection failure on a network, or lack of paper in the printer), or in the user program (e.g. an arithmetic overflow or an attempt to access an illegal memory location). For each type of error, OS should take the appropriate action to ensure correct and consistent computing. Sometimes, it has no choice but to halt the system. At other times, it might terminate an error-causing process or Return an error code to a process for the process to detect and possibly correct. Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.7 Modified by Dr. Wafaa Samy Operating System Services (Cont.) Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing among the different processes: 7. Resource allocation - When multiple processes running concurrently (at the same time), resources must be allocated to each of them: OS manages many types of resources - CPU cycles, main memory, file storage, and I/O devices. 8. Logging - To keep track of which users use how much and what kinds of computer resources. This record keeping may be used for accounting (so that users can be billed) or simply for accumulating usage statistics. Usage statistics may be a valuable tool for system administrators who wish to reconfigure the system to improve computing services. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.8 Modified by Dr. Wafaa Samy Operating System Services (Cont.) 9. Protection and security - The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other or with the operating system itself: Protection ensures that all access to system resources is controlled. Security of the system from outsiders requires user authentication extends to defending external I/O devices from invalid access attempts. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.9 Modified by Dr. Wafaa Samy A View of Operating System Services Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.10 Modified by Dr. Wafaa Samy User and Operating System-Interface Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.11 Modified by Dr. Wafaa Samy Command Line Interpreter (CLI) CLI allows direct command entry. Sometimes implemented in kernel, sometimes by system programs. Primarily fetches a command from user and executes it. The main function of the command interpreter is to get and execute the next user-specified command. Many of the commands given at this level manipulate files: create, delete, list, print, copy, execute, and so on. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.12 Modified by Dr. Wafaa Samy Bourne Shell Command Interpreter Sometimes multiple command interpreters (to choose from) implemented – shells. The Bourne-Again (or bash) shell command interpreter being used on macOS. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.13 Modified by Dr. Wafaa Samy Command Line Interpreter (CLI) (Cont.) The commands can be implemented in two general ways: Sometimes commands built-in, or just names of programs. 1. In one approach, the command interpreter itself contains the code to execute the command. o Disadvantage: Adding new features (commands) requires shell modification. 2. An alternative approach—used by UNIX, among other operating systems - implements most commands through system programs. o The command interpreter uses the command to identify a file to be loaded into memory and executed. o Advantage: Adding new features (commands) doesn’t require shell modification. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.14 Modified by Dr. Wafaa Samy User Operating System Interface - GUI User-friendly desktop metaphor interface: The users usually use mouse, keyboard, and monitor. Icons represent programs, files, directories, system functions, etc. Depending on the mouse pointer’s location, clicking a button on the mouse can invoke a program, select a file or directory (known as a folder) or pull down a menu that contains commands. Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory). GUI Invented at Xerox PARC. GUI first appeared due in part to research taking place in the early 1970s at Xerox PARC research facility. The first GUI appeared on the Xerox Alto computer in 1973. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.15 Modified by Dr. Wafaa Samy The Mac OS X GUI Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.16 Modified by Dr. Wafaa Samy Touch-Screen Interfaces A command-line interface or a mouse-and-keyboard system is impractical for most mobile systems, smartphones and handheld tablet computers typically use a touch-screen interface. Touch-screen devices require new interfaces: Mouse not possible or not desired. Actions and selection based on gestures. For example, pressing and swiping fingers across the screen. Virtual keyboard for text entry. Although earlier smartphones included a physical keyboard, most smartphones and tablets now simulate a keyboard on the touch screen. Voice commands. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.17 Modified by Dr. Wafaa Samy Touch-Screen Interfaces (Cont.) The touch screen of the Apple iPhone. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.18 Modified by Dr. Wafaa Samy Choice of Interface Many systems now include both CLI and GUI interfaces like Microsoft Windows, Apple Mac OS X, Unix and Linux have CLI with optional GUI interfaces. Almost all users of mobile systems interact with their devices using the touch-screen interface. The choice of whether to use a command-line or GUI interface is mostly one of personal preference. System administrators who manage computers and power users who have deep knowledge of a system frequently use the CLI. 1. For them, it is more efficient, giving them faster access to the activities they need to perform. 2. On some systems, only a subset of system functions is available via the GUI, leaving the less common tasks to those who are command-line knowledgeable. 3. Command-line interfaces usually make repetitive tasks easier, in part because they have their own programmability. E.g. if a frequent task requires a set of command line steps, those steps can be recorded into a file, and that file can be run just like a program interpreted. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.19 Modified by Dr. Wafaa Samy System Calls System calls provide a programming interface to the services provided by the OS. Typically written in a high-level language (C or C++). Certain low-level tasks (e.g. tasks where hardware must be accessed directly) may have to be written using assembly- language instructions. Even simple programs may make heavy use of the OS. Frequently, operating systems execute thousands of system calls per second. Mostly accessed by programs via a high-level Application Programming Interface (API) rather than direct system call use. Note: the system-call names used in the lectures are generic examples. Each operating system has its own name for each system call. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.20 Modified by Dr. Wafaa Samy Application Programming Interface (API) Application developers design programs according to an application programming interface (API). The API specifies a set of functions that are available to an application programmer, including the parameters that are passed to each function and the return values the programmer can expect. Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM). A programmer accesses an API via a library of code provided by the operating system. Windows provides an API as a set of C functions. In the case of UNIX and Linux for programs written in the C language, the library is called libc. The functions that make up an API typically invoke the actual system calls on behalf of the application programmer. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.21 Modified by Dr. Wafaa Samy Example of Standard API Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.22 Modified by Dr. Wafaa Samy Standard C Library Example The standard C library provides a portion of the system-call interface for many versions of UNIX and Linux. For example, let’s assume a C program invokes the printf() statement. The C library intercepts this call and invokes the necessary system call (or calls) in the operating system—in this instance, the write() system call. The C library takes the value returned by write() and passes C program invoking printf() library it back to the user program. call, which calls write() system call. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.23 Modified by Dr. Wafaa Samy Example of System Calls System call sequence to copy the contents of one file to another file: Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.24 Modified by Dr. Wafaa Samy Example of System Calls (Cont.) Writing a simple program to read data from one file and copy them to another file. 1. The first input that the program will need is the names of the two files: the input file and the output file. These names is specified in many ways based on the OS design. One approach is to pass the names of the two files as part of the command (e.g. the UNIX cp command: cp in.txt out.txt) This command copies the input file in.txt to the output file out.txt. A second approach is to ask the user for the names (this sequence requires many I/O system calls): Write a prompting message on the screen and then to read from the keyboard the characters that define the two files. On mouse-based and icon-based systems, a menu of file names is usually displayed in a window so the user can select the source name, and a window can be opened for the destination name to be specified. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.25 Modified by Dr. Wafaa Samy Example of System Calls (Cont.) 2. The program must open the input file and create and open the output file. Each of these operations requires another system call. Possible error conditions for each system call must be handled. e.g., when the program tries to open the input file, it may find that there is no file of that name or that the file is protected against access. In these cases, the program should output an error message (another sequence of system calls) and then terminate abnormally (another system call). If the input file exists, then we must create a new output file. We may find that there is already an output file with the same name. This situation may cause the program to abort (a system call), or we may delete the existing file (another system call) and create a new one (yet another system call). Another option, in an interactive system, is to ask the user (via a sequence of system calls to output the prompting message and to read the response from the terminal) whether to replace the existing file or to abort the program. Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.26 Modified by Dr. Wafaa Samy Example of System Calls (Cont.) 3. When both files are set up, we enter a loop that reads from the input file (a system call) and writes to the output file (another system call). Each read and write must return status information regarding various possible error conditions. On input, the program may find that the end of the file has been reached or that there was a hardware failure in the read (such as a parity error). The write operation may encounter various errors, depending on the output device (for example, no more available disk space). 4. Finally, after the entire file is copied, the program may close both files (two system calls), write a message to the console or window (more system calls), and finally terminate normally (the final system call). Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.27 Modified by Dr. Wafaa Samy Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018 2.28 Modified by Dr. Wafaa Samy