Operating System Concepts PDF
Document Details
2018
Silberschatz, Galvin and Gagne
Tags
Summary
This is an introductory textbook on operating system concepts. It covers fundamental topics like computer hardware, user interfaces, and important concepts such as operating systems, system calls, interrupts, and their implementation. It provides an overview of various operating systems like Windows, Unix, and Linux. The textbook presents the material in a clear and comprehensive manner.
Full Transcript
Section 2: Introduction Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018 Section 2: Overview ▪ Chapters 1 and 2 in textbook Operating System Concepts Overall computer system Computer hardware...
Section 2: Introduction Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018 Section 2: Overview ▪ Chapters 1 and 2 in textbook Operating System Concepts Overall computer system Computer hardware User interfaces OS versus kernel User mode / kernel mode System calls Interrupts Operating System Concepts – 10th Edition 1.2 Silberschatz, Galvin and Gagne ©2018 Computer system structure ▪ Computer system can be divided into three components: Application programs – define the ways in which the system resources are used to solve the computing problems of the users Word processors, compilers, web browsers, database systems, video games Operating system Controls and coordinates use of hardware among various applications and users Hardware – provides physical computing resources CPU, memory, I/O devices Operating System Concepts – 10th Edition 1.3 Silberschatz, Galvin and Gagne ©2018 View of computer system structure Operating System Concepts – 10th Edition 1.4 Silberschatz, Galvin and Gagne ©2018 Computer System Hardware ▪ Computer-system hardware One or more CPUs, device controllers connect through common bus providing access to the memory and other I/O devices Operating System Concepts – 10th Edition 1.5 Silberschatz, Galvin and Gagne ©2018 Input/Output (I/O) devices ▪ I/O devices consist of storage devices (disks, tapes), transmission devices (network connections, Bluetooth), and human-interface devices (screen, keyboard, mouse,audio in and out) ▪ I/O devices have two physical parts: a controller and the device itself ▪ A device controller is a chip that physically controls the device Operating System Concepts – 10th Edition 1.6 Silberschatz, Galvin and Gagne ©2018 Storage system ▪ Storage system can be represented as a hierarchy of storage device medias ▪ The devices at each level of the hierarchy have different characteristics in terms of: Storage capacity Access time Transfer speed Cost Volatility Operating System Concepts – 10th Edition 1.7 Silberschatz, Galvin and Gagne ©2018 Characteristics of Various Types of Storage Medias Operating System Concepts – 10th Edition 1.8 Silberschatz, Galvin and Gagne ©2018 Main memory/secondary storage ▪ Main memory and secondary storage are managed by the operating system ▪ We will study in detail how the OS manages these two device types Operating System Concepts – 10th Edition 1.9 Silberschatz, Galvin and Gagne ©2018 Main memory ▪ Main memory – is the only large storage media that the CPU can access directly Typically volatile Typically random-access memory in the form of Dynamic Random-access Memory (DRAM) Operating System Concepts – 10th Edition 1.10 Silberschatz, Galvin and Gagne ©2018 External memory ▪ Secondary storage – extension of main memory that provides large nonvolatile storage capacity ▪ These devices are either hard disk drive, ranging from 30GB to 9TB, such as X18 with 9 platters, 18 heads ▪ Or Solid-State Drive SSD with up to 100TB Operating System Concepts – 10th Edition 1.11 Silberschatz, Galvin and Gagne ©2018 Computer time units at human scale ▪ 1 ns = 1 billion of a second ▪ A 2Ghz CPU executes one instruction every 0.5ns ▪ In order to bring execution time of computer operations to human scale, let assume that 0.5n = 1 second ▪ Note, the fastest typist can type a keystroke every 100ms Operating System Concepts – 10th Edition 1.12 Silberschatz, Galvin and Gagne ©2018 User interfaces Operating System Concepts – 10th Edition 1.13 Silberschatz, Galvin and Gagne ©2018 Command line interpreter Operating System Concepts – 10th Edition 1.14 Silberschatz, Galvin and Gagne ©2018 Command Line interpreter ▪ CLI allows direct command entry ▪ Primarily fetches a command from user and executes it ▪ Sometimes commands built-in, sometimes just names of programs If the latter, adding new features doesn’t require shell modification ▪ Sometimes implemented in kernel, sometimes by systems program ▪ Sometimes multiple flavors implemented – shells Ubuntu has Bourne shells (bash, sh, zsh) Operating System Concepts – 10th Edition 1.15 Silberschatz, Galvin and Gagne ©2018 Graphical User Interfaces - GUI ▪ User-friendly desktop metaphor interface Usually mouse, keyboard, and monitor Icons represent files, programs, actions, etc Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory (known as a folder) Invented at Xerox PARC ▪ Many systems now include both CLI and GUI interfaces Microsoft Windows is GUI with CLI “command” shell Apple Mac OS X is “Aqua” GUI interface with UNIX kernel underneath and shells available Unix and Linux have CLI with GUI interfaces (CDE, KDE, GNOME) Operating System Concepts – 10th Edition 1.16 Silberschatz, Galvin and Gagne ©2018 Windows 10 screen desktop Operating System Concepts – 10th Edition 1.17 Silberschatz, Galvin and Gagne ©2018 Touchscreen Interfaces ▪ Touchscreen devices require new interfaces Mouse not possible or not desired Actions and selection based on gestures Virtual keyboard for text entry ▪ Voice commands Operating System Concepts – 10th Edition 1.18 Silberschatz, Galvin and Gagne ©2018 Difference between OS and kernel ▪ The kernel is a program (object) that is part of the OS ▪ Process and memory management is done by the kernel while interfacing with the user such as desktop icons or command line interpreters (terminals) are part of the OS but not in the kernel ▪ Note, the kernel is stored in a protect area of the main memory called the kernel space Operating System Concepts – 10th Edition 1.19 Silberschatz, Galvin and Gagne ©2018 User mode / kernel mode ▪ Most computers have at least two modes of operation: kernel mode and user mode: Operating System Concepts – 10th Edition 1.20 Silberschatz, Galvin and Gagne ©2018 User mode / kernel mode ▪ The code of most of the services provided by the OS is accessed in kernel mode ▪ The rest of the software, in particular the user code, always runs in user mode where only a subset of the machine instructions is available Operating System Concepts – 10th Edition 1.21 Silberschatz, Galvin and Gagne ©2018 C code example #include #include #include #include int main (int argc, char *argv[]) { pid_t childpid = 0; int i, n; n = atoi(argv); for (i = 1; i < n; i++) if (childpid = fork()) break; fprintf(stderr, "i:%d process ID:%ld parent ID:%ld child ID:%ld\n", i, (long)getpid(), (long)childpid, (long)getppid()); wait(NULL); return 0; } Operating System Concepts – 10th Edition 1.22 Silberschatz, Galvin and Gagne ©2018 Transition from user to kernel mode ▪ To obtain services from the operating system, a user program must make a system call, which invokes the kernel. ▪ In order to execute kernel mode instructions the system switch from user mode to kernel mode and starts running code from the kernel in order to answer the system call Operating System Concepts – 10th Edition 1.23 Silberschatz, Galvin and Gagne ©2018 Transition from user to kernel mode ▪ The system call executes a “trap instruction” which causes a change in the value of the mode bit ▪ The mode bit is stored in a register of the CPU and is used by the system to decide whether a hardware instruction is allowed to execute Operating System Concepts – 10th Edition 1.24 Silberschatz, Galvin and Gagne ©2018 Transition from user to kernel mode ▪ Once the mode bit is set to 0, the kernel instructions related to the service requested by the system call are then executed ▪ Prior to return to user mode, the mode bit is reset to user mode status Operating System Concepts – 10th Edition 1.25 Silberschatz, Galvin and Gagne ©2018 System calls ▪ They are functions in the kernel that are called by a user program to execute kernel code ▪ For example, if a user program want to write a file, it will execute a kernel function through a routine call defined by the programming language ▪ System call can also refer to the function in the user code because this fct does everything to prepare for the execution of the kernel fct Operating System Concepts – 10th Edition 1.26 Silberschatz, Galvin and Gagne ©2018 System call at high level ▪ Step 1: A user program is running until a system call interrupts it ▪ Step 2: The system call is executed in kernel- mode ▪ Step 3: Once the system call is completed, user code resume execution in user mode Operating System Concepts – 10th Edition 1.27 Silberschatz, Galvin and Gagne ©2018 System call implementation ▪ The fct printf() look like a normal fct responsible for implementing a write ▪ But in fact, printf is just an envelop that prepare the arguments for the write() function, transfer these arguments to the kernel, Last, execute an interrupt that stops the execution of the user code and pass the control to a code in the kernel Operating System Concepts – 10th Edition 1.28 Silberschatz, Galvin and Gagne ©2018 System Call Implementation ▪ The fcts in user code calling kernel fcts have a similar role, they constitute the System-call interface ▪ The difference is a number is associated with each system call, rather then a name. ▪ The kernel has a table of the system call functions Operating System Concepts – 10th Edition 1.29 Silberschatz, Galvin and Gagne ©2018 System calls ▪ There are many system calls, for example one particular Linux kernel has 393 different system calls: ▪ getitimer(), getpageside(), getpid(), fork(), open(), close(), read(), reboot(), getcpu(), write() ▪ You can find the source code of Linux system calls in the Linux kernel source which anyone can download Operating System Concepts – 10th Edition 1.30 Silberschatz, Galvin and Gagne ©2018 Examples of Windows and Unix System Calls Operating System Concepts – 10th Edition 1.31 Silberschatz, Galvin and Gagne ©2018 Types of system calls ▪ System calls can be grouped roughly into six major categories: process control, file management, device management, information maintenance, communications, protection. ▪ Process control create process, terminate process end, abort load, execute get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Locks for managing access to shared data between processes Operating System Concepts – 10th Edition 1.32 Silberschatz, Galvin and Gagne ©2018 Types of system calls (Cont.) ▪ File management create file, delete file open, close file read, write, reposition get and set file attributes ▪ Device management request device, release device read, write, reposition get device attributes, set device attributes logically attach or detach devices Operating System Concepts – 10th Edition 1.33 Silberschatz, Galvin and Gagne ©2018 Types of system calls (Cont.) ▪ 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 if message passing model to host name or process name From client to server Shared-memory model create and gain access to memory regions transfer status information attach and detach remote devices Operating System Concepts – 10th Edition 1.34 Silberschatz, Galvin and Gagne ©2018 Types of system calls (Cont.) ▪ Protection Control access to resources Get and set permissions Allow and deny user access Operating System Concepts – 10th Edition 1.35 Silberschatz, Galvin and Gagne ©2018 Interrupts ▪ Interrupt: Means to stop the execution of a sequence of computer instructions ▪ While the CPU is executing a program, an interrupt stops the execution of this program and start the execution of another program ▪ Generally, there are two types of interrupts: Hardware interrupts: I/O devices need to be serviced by the CPU. The CPU is made aware of I/O devices needs through interrupts which are signals sent on the system bus Software interrupts: Alternatively,a program may want to voluntary interrupt itself or may cause an error that raises an interrupt signal Operating System Concepts – 10th Edition 1.36 Silberschatz, Galvin and Gagne ©2018 Harware interrupts Operating System Concepts – 10th Edition 1.37 Silberschatz, Galvin and Gagne ©2018 Hardware interrupts ▪ Hardware interrupts are issued by hardware devices like disk, network cards, keyboards, clocks, etc. Each device or set of devices will have its own IRQ (Interrupt ReQuest) line. ▪ Then the interrupt controller converts these signals into a number sent on the CPU interrupt request line ▪ After executing each instruction, the CPU checks the interrupt request line if an interrupt has been raised ▪ If an interrupt has occurred, the number of this interrupt will be passed to the kernel to the appropriate interrupt handler function ▪ This function is executed by the CPU Operating System Concepts – 10th Edition 1.38 Silberschatz, Galvin and Gagne ©2018 Example ▪ Keystroke(pressing of key on) will generate a signal which is given to the processor to do action (such as to execute a kernel function. ▪ Keystroke: keyboard controller determines which key has been stroke, raise a signal on the IRQ line for the keyboard Upon receiving the signal, the CPU interrupts what ever it was doing, and pass the signal id to the kernel which executes the corresponding handler which will fetch from the keyboard the character corresponding to the keystroke. Then this character maybe display on the screen and/or store in a file opened by a word processing. Operating System Concepts – 10th Edition 1.39 Silberschatz, Galvin and Gagne ©2018 Software interrupts Software interrupt can be divided into two types: Normal Interrupts: the interrupts which are caused by the software instructions such as a system call Exception: unplanned interrupts while executing a program. For example: while executing a program, a value is divided by zero, this raises an interrupt called an exception. Software interrupts are initiated by inserting in the code a special machine instruction (which is dependent on the computer architecture): example: INT X where INT is an interrupt machine instruction (for x86 architectures) and X identifies the type of the interrupt The last instruction of a system call is a INT X typically can take 256 values (1 byte long) Operating System Concepts – 10th Edition 1.40 Silberschatz, Galvin and Gagne ©2018 Software interrupts ▪ Software interrupts can only be generated by processes which are currently running. ▪ The software interrupt only talks to the kernel. Typical software interrupts are requests for I/O (Input or Output). These will call kernel routines which will schedule the I/O to occur. ▪ Software interrupts do not reach the CPU, they are handled by the kernel. They avoid the hardware signaling step. The process generating the software request must be a currently running process, so they don’t need to interrupt the CPU. Operating System Concepts – 10th Edition 1.41 Silberschatz, Galvin and Gagne ©2018 Handling Interrupts ▪ Different routines handle different interrupts – called Interrupt Service Routines (ISR) (device drivers) ▪ When CPU is interrupted, it stops what it was doing, a generic routine called Interrupt Handling Routine (IHR) is run ▪ This code examines the nature of interrupt, through the interrupt vector, which contains the addresses of all the service routines ▪ Which then calls the corresponding Interrupt Service Routine (ISR) (for example code inside a device driver) ▪ After servicing the interrupt, the CPU resumes the interrupted computation Operating System Concepts – 10th Edition 1.42 Silberschatz, Galvin and Gagne ©2018 Linkers and Loaders ▪ Source code compiled into object files designed to be loaded into any physical memory location – relocatable object file ▪ Linker combines these into single binary executable file Also brings in libraries ▪ Program resides on secondary storage as binary executable ▪ Must be brought into memory by loader to be executed Relocation assigns final addresses to program parts and adjusts code and data in program to match those addresses ▪ Modern general purpose systems don’t link libraries into executables Rather, dynamically linked libraries (in Windows, DLLs) are loaded as needed, shared by all that use the same version of that same library (loaded once) ▪ Object, executable files have standard formats, so operating system knows how to load and start them Operating System Concepts – 10th Edition 1.43 Silberschatz, Galvin and Gagne ©2018 The Role of the Linker and Loader Operating System Concepts – 10th Edition 1.44 Silberschatz, Galvin and Gagne ©2018 Operating System - Examples Windows: Commercial operating system developed and marketed by Microsoft. Different versions such as Windows 8, Windows 11 etc. and most of them are paid. Linux Unix based, most loved operating system, first released on September 17, 1991 by Linus Torvalds. Today, it has 30+ variants, like Fedora, OpenSUSE, CentOS, Ubuntu, etc. Most are free of charge. Android Mobile Operating System based on a modified version of the Linux kernel and other open-source software, designed primarily for touchscreen mobile devices such as smartphones and tablets MacOS This is again a kind of Unix operating system developed and marketed by Apple Inc. since 2001. iOS Mobile operating system created and developed by Apple Inc. exclusively for its mobile devices like iPhone and iPad etc. Operating System Concepts – 10th Edition 1.45 Silberschatz, Galvin and Gagne ©2018 End of Introduction Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018