Chapter 2: System Structures Operating System Concepts (Silberschatz et al.) 2.1 What You’ll Learn Today You will be able: To describe the services an operating system provides to users, processes, and other systems To discuss the various ways of structuring an operating system To explain how operating systems are installed and customized and how they boot Operating System Concepts (Silberschatz et al.) 2.2 Three Perspectives on the OS Operating systems provide an environment for execution of programs We can view OS from 3 vantage points, regarding: The services it provides The interface made available to users and programmers Its components and interconnections Operating System Concepts (Silberschatz et al.) 2.3 OS Services Examples: Services that are helpful to user: functions related to user interface (e.g., UI), functions related to program execution (load, execute and stop program), I/O operations (e.g., allow to read from and write to filesystem) Functions allowing processes to exchange information Functions for error detection (and take action), and debugging Functions related to resource allocation (e.g.?) Functions related to accounting (e.g.?) Functions related to protection and security: e.g.?. Operating System Concepts (Silberschatz et al.) 2.4 OS Services Examples: Services that are helpful to user: functions related to user interface (e.g., UI), functions related to program execution (load, execute and stop program), I/O operations (e.g., allow to read from and write to filesystem) Functions allowing processes to exchange information Functions for error detection (and take action), and debugging Functions related to resource allocation (CPU cycles, main memory, file storage, etc.) Functions related to accounting (which user have which and how much resources?) Functions related to protection and security: e.g., access to resource is controlled, access from outside requires authentication, defend I/O devices form invalid access attempts Etc. Operating System Concepts (Silberschatz et al.) 2.5 OS Services For the User Operating systems provide an environment for execution of programs and services to users and programs One set of operating-system services provides functions that are helpful to the user: User interface - Almost all operating systems have a user interface (UI). e.g.? 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) I/O operations - A running program may require I/O, which may involve a file or an I/O device File-system manipulation - The file system is of particular interest. Programs need to read and write files and directories, create and delete them, search them, list file Information, permission management Operating System Concepts (Silberschatz et al.) 2.6 OS Services For the User Operating systems provide an environment for execution of programs and services to users and programs One set of operating-system services provides functions that are helpful to the user: User interface - Almost all operating systems have a user interface (UI). Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch 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) I/O operations - A running program may require I/O, which may involve a file or an I/O device File-system manipulation - The file system is of particular interest. Programs need to read and write files and directories, create and delete them, search them, list file Information, permission management Operating System Concepts (Silberschatz et al.) 2.7 OS Services for Communication And Errors Communications – Processes may exchange information, on the same computer or between computers over a network How to implement communication? Error detection – OS needs to be constantly aware of possible errors Examples: what can go wrong? Operating System Concepts (Silberschatz et al.) 2.8 OS Services for Communication And Errors Communications – Processes may exchange information, on the same computer or between computers over a network Communications may be via shared memory or through message passing (packets moved by the OS) – Or also by files ☺ Error detection – OS needs to be constantly aware of possible errors May occur in the CPU and memory hardware, in I/O devices, in user program For each type of error, OS should take the appropriate action to ensure correct and consistent computing Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system Operating System Concepts (Silberschatz et al.) 2.9 OS Services for Operation and Sharing Another set of OS functions for efficient operation of the system itself via resource sharing: Resource allocation - When multiple users or jobs run concurrently, resources must be allocated to each of them Accounting - To keep track of which users use how much and what kinds of computer resources 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 Protection involves ensuring 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 If a system is to be protected and secure, precautions must be instituted throughout it: A chain is only as strong as the weakest link Operating System Concepts (Silberschatz et al.) 2.10 A View of Operating System Services User interfaces Interface to the services offered by the OS OS Services Operating System Concepts (Silberschatz et al.) 2.11 User OS Interface - CLI Command Line Interface (CLI) or Command Interpreter allows direct command entry: Primarily fetches a command from user and executes it Sometimes implemented in kernel, sometimes by system program (when a job is initiated or when a user first logs on) Sometimes multiple command interpreters implemented: then interpreters are called shells e.g., UNIX and Linux: Bourne shell, C shell, Bourne-Again shell, Korn shell, etc.) Often used to manipulate files: create, delete, copy, list, execute Operating System Concepts (Silberschatz et al.) 2.12 Bourne Shell Command Interpreter Operating System Concepts (Silberschatz et al.) 2.13 Types of Command Interpreters Two types of interpreters: Variant 1: Command interpreter itself contains the code to execute the command Example: Command to delete a file causes the command interpreter to jump to a section of its code that sets up the parameters and makes the appropriate system call Variant 2 (e.g., UNIX): Implement most commands through system programs In this case, the command interpreter does not understand the command in any way It merely uses the command to identify a file to be loaded into memory and executed Operating System Concepts (Silberschatz et al.) 2.14 Types of Command Interpreters Two types of interpreters: Variant 1: Command interpreter itself contains the code to execute the command How large is the code of the interpreter? Example: Command to delete a file causes the command interpreter to jump to a section of its code that sets up the parameters and makes the appropriate system call Variant 2 (e.g., UNIX): Implement most commands through system programs How large is the code of the interpreter? In this case, the command interpreter does not understand the command in any way It merely uses the command to identify a file to be loaded into memory and executed Operating System Concepts (Silberschatz et al.) 2.15 Types of Command Interpreters Two types of interpreters: Variant 1: Command interpreter itself contains the code to execute the command Example: Command to delete a file causes the command interpreter to jump to a section of its code that sets up the parameters and makes the appropriate system call Variant 2 (e.g., UNIX): Implement most commands through system programs In this case, the command interpreter does not understand the command in any way It merely uses the command to identify a file to be loaded into memory and executed Operating System Concepts (Silberschatz et al.) How large is the code of the interpreter? Depends on number of supported commands: each command has its own implementation! How large is the code of the interpreter? Independent of number of commands: simply loads the file indicated by command and executes that 2.16 Example: Variant 2 What happens behind the scene? What will command interpreter do? rm file.txt Operating System Concepts (Silberschatz et al.) 2.17 Example: Variant 2 What happens behind the scene? What will command interpreter do? rm file.txt Command interpreter does not understand the command It merely searches for a file called rm, loads the file into memory, and executes it with the parameter file.txt The function associated with the rm command is defined by the code in the file rm Operating System Concepts (Silberschatz et al.) 2.18 Types of Command Interpreters Two types of interpreters: Variant 1: Command interpreter itself contains the code to execute the command Example: Command to delete a file causes the command interpreter to jump to a section of its code that sets up the parameters and makes the appropriate system call How to add a new command? Variant 2 (e.g., UNIX): Implement most commands through system programs In this case, the command interpreter does not understand the command in any way It merely uses the command to identify a file to be loaded into memory and executed Operating System Concepts (Silberschatz et al.) 2.19 Types of Command Interpreters Two types of interpreters: Variant 1: Command interpreter itself contains the code to execute the command Example: Command to delete a file causes the command interpreter to jump to a section of its code that sets up the parameters and makes the appropriate system call Variant 2 (e.g., UNIX): Implement most commands through system programs In this case, the command interpreter does not understand the command in any way It merely uses the command to identify a file to be loaded into memory and executed Operating System Concepts (Silberschatz et al.) How to add a new command? Easy: Programmers can simply create new files with the proper names. The commandinterpreter program, does not have to be changed for new commands to be added. 2.20 User OS Interface - GUI User-friendly desktop metaphor interface Usually mouse, keyboard, and monitor Icons represent files (and folders), 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 (1973) 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 optional GUI interfaces (CDE, KDE, GNOME) Operating System Concepts (Silberschatz et al.) 2.21 Touchscreen Interfaces Touchscreen devices require new interfaces Mouse not possible or not desired Actions and selection based on guestures Virtual keyboards simulated on the touchscreen for text entry Operating System Concepts (Silberschatz et al.) 2.22 The Mac OS X GUI Operating System Concepts (Silberschatz et al.) 2.23 Which Interface is Better: CLI or GUI? Operating System Concepts (Silberschatz et al.) 2.24 Which Interface is Better: CLI or GUI? Matter of personal preference… GUI: simpler, requires less technical knowledge GUI provides only a subset of the available functions Power users and sysadmins prefer CLI: More flexibilities Faster: frequent tasks require multiple steps which can be recorded in a file and then the file run like a program: interpreted (not compiled!) by the CLI. A.k.a. shell scripts! Operating System Concepts (Silberschatz et al.) 2.25 5 Minute Break Operating System Concepts – 9th Edition 2.26 Silberschatz, Galvin and Gagne ©2013 System Calls Programming interface to the services provided by the OS Typically written in a high-level language (C or C++), but some low-level tasks (with direct hardware access) also in assembly language Usually, systems execute thousands of system calls per second Mostly accessed by programs via a high-level Application Program Interface (API) (a code library offered by the OS) rather than direct system call use Three most common APIs are Win32 API for Windows, POSIX API for POSIXbased systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) The functions that make up the API then invoke the system calls on behalf of the application programmer. E.g., the Windows function CreateProcess() actually invokes the NTCreateProcess() system call in the Windows kernel Operating System Concepts (Silberschatz et al.) 2.27 System Calls Programming interface to the services provided by the OS Typically written in a high-level language (C or C++), but some low-level tasks (with direct hardware access) also in assembly language Usually, systems execute thousands of system calls per second Mostly accessed by programs via a high-level Application Program Interface (API) (a code library offered by the OS) rather than direct system call use Three most common APIs are Win32 API for Windows, POSIX API for POSIXbased systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) The functions that make up the API then invoke the system calls on behalf of the application programmer. E.g., the Windows function CreateProcess() actually invokes the NTCreateProcess() system call in the Windows kernel Why use API? Why not system call directly? Operating System Concepts (Silberschatz et al.) 2.28 System Calls Programming interface to the services provided by the OS Typically written in a high-level language (C or C++), but some low-level tasks (with direct hardware access) also in assembly language Usually, systems execute thousands of system calls per second Mostly accessed by programs via a high-level Application Program Interface (API) (a code library offered by the OS) rather than direct system call use Three most common APIs are Win32 API for Windows, POSIX API for POSIXbased systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) The functions that make up the API then invoke the system calls on behalf of the application programmer. E.g., the Windows function CreateProcess() actually invokes the NTCreateProcess() system call in the Windows kernel Why use API? Why not system call directly? Operating System Concepts (Silberschatz et al.) Portability: will run on any system with this API. And it is often easier to work with the API. 2.29 Example of System Calls System call sequence to copy the contents of one file to another file What needs to be done? Operating System Concepts (Silberschatz et al.) 2.30 Example of System Calls (1) System call sequence to copy the contents of one file to another file Need two inputs: names of 2 files (input and output) In interactive systems, could ask user to provide them: Sequence of syscalls required: write prompting message on screen, then to read from keyboard the characters, etc. In mouse-based systems: syscalls to display menu, allow user to select name, then open window for the destination name to be specified Then syscalls to open the input file and create the output file System calls for error handling: e.g., when program tries to open file, if no file or file protected, program should print message to console (a syscall) and terminate abnormally (another syscalls) e.g., when output file already exists (abort: syscall, or delete existing one: syscall) Operating System Concepts (Silberschatz et al.) 2.31 Example of System Calls (2) When both files set up: loop to read from input file (syscalls) and write to output file (syscalls) Each read and write must return status information regarding errors on read: end of file reached, hardware failure (parity bit error) on write: e.g., no more disk space When copied close both files (another syscall) write message to console (a syscall) or window (many syscalls) terminate normally (the final syscall) Operating System Concepts (Silberschatz et al.) 2.32 Example of System Calls: Summary System call sequence to copy the contents of one file to another file Operating System Concepts (Silberschatz et al.) 2.33 Example of Standard API Try yourself: man pages Return: how much read? Or error? Operating System Concepts (Silberschatz et al.) How much to read into buffer? 2.34 System Call Implementation Typically, a number associated with each system call System-call interface maintains a table indexed according to these numbers The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values The caller need know nothing about how the system call is implemented Just needs to obey API and understand what OS will do as a result call Most details of OS interface hidden from programmer by API Managed by runtime support library (set of functions built into libraries included with compiler) Operating System Concepts (Silberschatz et al.) 2.35 API – System Call – OS Relationship Example: user application invokes open() system call In kernel mode: lookup in table and execute implementation Thus: Caller does not know how call is implemented But managed by the runtime support library Most of the syscall interface details are hidden from programmer by the API Operating System Concepts (Silberschatz et al.) 2.36 API – System Call – OS Relationship Example: user application invokes open() system call In kernel mode: lookup in table and execute implementation Thus: Caller does not know how call is implemented But managed by the runtime support library Most of the syscall interface details are hidden from programmer by the API How to pass parameters to OS? Operating System Concepts (Silberschatz et al.) 2.37 System Call Parameter Passing Often, more information is required than simply identity of desired system call Example: To get input, need to specify the file or device to use as the source, as well as the address and length of the memory buffer into which the input should be read Exact type and amount of information vary according to OS and call, e.g., the device or file and length may also be implicit in the call. Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers Drawback? Operating System Concepts (Silberschatz et al.) 2.38 System Call Parameter Passing Often, more information is required than simply identity of desired system call Example: To get input, need to specify the file or device to use as the source, as well as the address and length of the memory buffer into which the input should be read Exact type and amount of information vary according to OS and call, e.g., the device or file and length may also be implicit in the call. Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers However, in some cases, may be more parameters than registers Operating System Concepts (Silberschatz et al.) 2.39 System Call Parameter Passing Often, more information is required than simply identity of desired system call Example: To get input, need to specify the file or device to use as the source, as well as the address and length of the memory buffer into which the input should be read Exact type and amount of information vary according to OS and call, e.g., the device or file and length may also be implicit in the call. Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers However, in some cases, may be more parameters than registers Parameters stored in a block, or table, in memory, and address to 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 Operating System Concepts (Silberschatz et al.) 2.40 System Call Parameter Passing Often, more information is required than simply identity of desired system call Example: To get input, need to specify the file or device to use as the source, as well as the address and length of the memory buffer into which the input should be read Exact type and amount of information vary according to OS and call, e.g., the device or file and length may also be implicit in the call. Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers However, in some cases, may be more parameters than registers Parameters stored in a block, or table, in memory, and address to 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 Operating System Concepts (Silberschatz et al.) 2.41 Parameter Passing via Table Principle: Put parameters in table Put address (pointer) to table X in register Call syscall 13 OS code can load them from table Operating System Concepts (Silberschatz et al.) 2.42 Types of System Calls Roughly 6 categories of system calls: Process control File manipulation Device manipulation Information maintenance, Communications and protection Operating System Concepts (Silberschatz et al.) 2.43 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute ? create process, terminate process get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Operating System Concepts (Silberschatz et al.) 2.44 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Operating System Concepts (Silberschatz et al.) 2.45 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time Where to return to after it terminates? wait event, signal event allocate and free memory Operating System Concepts (Silberschatz et al.) 2.46 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time Where to return to after it terminates? wait event, signal event allocate and free memory It depends: is existing program lost, saved, or run concurrently to new program? If return: we have a mechanism for one program to call another one! Need to save image of existing program. If run concurrently: we have created a new job or process to be multiprogrammed! Operating System Concepts (Silberschatz et al.) 2.47 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time E.g., if job no longer needed or incorrect. wait event, signal event allocate and free memory Operating System Concepts (Silberschatz et al.) 2.48 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time wait event, signal event Why needed? allocate and free memory Operating System Concepts (Silberschatz et al.) 2.49 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time wait event, signal event Why needed? allocate and free memory Needed to control the execution of a job: modify job’s priority, max allowable execution time Operating System Concepts (Silberschatz et al.) 2.50 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Operating System Concepts (Silberschatz et al.) Why needed? 2.51 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Why needed? Want to wait for a certain amount of time to pass or signal when event occurs. Operating System Concepts (Silberschatz et al.) 2.52 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Operating System Concepts (Silberschatz et al.) OS allows processes to lock shared data: to ensure integrity! Supports coordination. 2.53 Types of System Calls Process control end (normally), abort (abnormally) running program (= process) load, execute: e.g., user clicks to execute another program create process, terminate process get process attributes, set process attributes wait for time wait event, signal event allocate and free memory If program runs into a problem and causes an error trap: A dump of memory is written to disk and an error message generated OS transfers control to the invoking command interpreter which reads next command resp. asks user for reaction (in window system: pop up) Operating System Concepts (Silberschatz et al.) 2.54 Debugger and Recovery Dump can be examined by debugger: A system program to aid the programmer to find and fix bugs May also support single-step executions (reproduce error) Some systems may allow for special recovery actions in case an error occurs If the program discovers an error in its input and wants to terminate abnormally, it may indicate an error level The command interpreter or a following program can use this error level to determine the next action automatically Operating System Concepts (Silberschatz et al.) 2.55 Types of System Calls File management create file, delete file open, close file e.g., rewind or skip to the end of file read, write, reposition get and set file attributes e.g., file name, type, protection codes, etc. Device management request device, release device read, write, reposition get device attributes, set device attributes logically attach or detach devices Operating System Concepts (Silberschatz et al.) 2.56 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 (Silberschatz et al.) 2.57 Types of System Calls (Cont.) Protection Control access to resources Get and set permissions Allow and deny user access Operating System Concepts (Silberschatz et al.) 2.58 Examples of Windows and Unix System Calls Operating System Concepts (Silberschatz et al.) 2.59 Standard C Library Example C program invoking printf() library call, which calls write() system call Operating System Concepts (Silberschatz et al.) 2.60 Example: Process and Job Control in MS-DOS MS-DOS: Single-tasking Shell invoked when system boots Simple method to run program No new process created Single memory space Loads program into memory, overwriting all but the kernel Sets instruction pointer to first instruction of program Program exit (either caused by trap or syscall to terminate) -> shell (command interpreter) reloaded (a) At system startup (b) running a program Error code made available to user or next program Operating System Concepts (Silberschatz et al.) 2.61 Example: Process and Job Control in MS-DOS MS-DOS: Single-tasking Shell invoked when system boots Simple method to run program No new process created Single memory space Loads program into memory, overwriting all but the kernel Shrink: make as much space as possible for the program. Sets instruction pointer to first instruction of program Program exit (either caused by trap or syscall to terminate) -> shell (command interpreter) reloaded (a) At system startup (b) running a program Error code made available to user or next program Operating System Concepts (Silberschatz et al.) 2.62 Example: Process and Job Control in MS-DOS https://www.houstonpress.com/arts/5-glitches-in-video-games-the-makers-tried-to-pass-off-as-intentional-6386631 MS-DOS: Single-tasking Shell invoked when system boots Simple method to run program No new process created Single memory space Loads program into memory, overwriting all but the kernel Sets instruction pointer to first instruction of program Program exit (either caused by trap or syscall to terminate) -> shell (command interpreter) reloaded (a) At system startup (b) running a program Error code made available to user or next program Operating System Concepts (Silberschatz et al.) 2.63 Example: Process and Job Control in FreeBSD FeeBSD: a Unix variant Example of multi-tasking User login -> invoke user’s choice of shell: executes programs that user requests Shell executes fork() system call to create process Executes exec() to load program into process Shell waits for process to terminate or continues with user commands Multi-tasking: command interpreter continues running while another process is executed; user can ask shell to run additional programs Process exits with code of 0 – no error or > 0 – error code Operating System Concepts (Silberschatz et al.) 2.64 Example: Process and Job Control in FreeBSD FeeBSD: a Unix variant Example of multi-tasking User login -> invoke user’s choice of shell: executes programs that user requests Shell executes fork() system call to create Multi-tasking: many process concurrent processes. Executes exec() to load program into process Shell waits for process to terminate or continues with user commands Multi-tasking: command interpreter continues running while another process is executed; user can ask shell to run additional programs Process exits with code of 0 – no error or > 0 – error code Operating System Concepts (Silberschatz et al.) 2.65 System Programs Recall: modern systems come with a collection of system programs (a.k.a. system utilities) Application programs: word processor, browser, etc. (installed by user) Operating System Concepts (Silberschatz et al.) 2.66 System Programs OS often also come with entire system programs Provide a convenient environment for program development and execution Some of them are simply user interfaces to system calls; others are considerably more complex Most users’ view of the operation system as defined by system programs, not the actual system calls System programs can be divided into: File manipulation Status information sometimes stored in a file modification Programming language support Program loading and execution Communications Background services Application programs Operating System Concepts (Silberschatz et al.) 2.67 System Programs File modification Text editors to create and modify files Special commands to search contents of files or perform transformations of the text Programming-language support - Compilers, assemblers, debuggers and interpreters sometimes provided File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories Status information Some system calls or system programs transfer information between user program and OS E.g., ask the system for information like date, time, amount of available memory, disk space, number of users Others provide detailed performance, logging, and debugging information Typically, these programs format and print the output to the terminal or other output devices Some systems implement a registry - used to store and retrieve configuration information Operating System Concepts (Silberschatz et al.) 2.68 System Programs (Cont.) Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language Communications - Provide the mechanism for creating virtual connections among processes, users, and computer systems Allow users to send messages to one another’s screens, browse web pages, send e-mail messages, log in remotely, transfer files from one machine to another Background Services Launch at boot time Some only for system startup, then terminate Some throughout system boot to shutdown Provide facilities like disk checking, process scheduling, error logging, printing Run in user context not kernel context Known as services, subsystems, daemons Operating System Concepts (Silberschatz et al.) 2.69 Application Programs Application programs Don’t pertain to system Run by users Not typically considered part of OS Launched by command line, mouse click, finger poke Operating System Concepts (Silberschatz et al.) 2.70 What You’ll Learn Today You will be able: To describe the services an operating system provides to users, processes, and other systems To discuss the various ways of structuring an operating system To explain how operating systems are installed and customized and how they boot Operating System Concepts (Silberschatz et al.) 2.71 Operating System Design and Implementation Design and Implementation of OS: Internal structure of different Operating Systems can vary widely Some approaches have proven successful Start by defining goals and specifications User goals and System goals User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast System goals – operating system should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient Operating System Concepts (Silberschatz et al.) 2.72 Operating System Design and Implementation (Cont.) Important principle to separate Policy: What will be done? Mechanism: How to do it? Operating System Concepts (Silberschatz et al.) 2.73 Operating System Design and Implementation (Cont.) Important principle to separate Policy: What will be done? Mechanism: How to do it? For example: How to make sure that OS maintains control over CPU even if a user program can get stuck in infinite loop or fails to call system services? Operating System Concepts (Silberschatz et al.) 2.74 Operating System Design and Implementation (Cont.) Important principle to separate Policy: What will be done? Mechanism: How to do it? For example: How to make sure that OS maintains control over CPU even if a user program can get stuck in infinite loop or fails to call system services? Use a timer: interrupts after e.g. 1/60sec What is policy and what mechanism here? Operating System Concepts (Silberschatz et al.) 2.75 Operating System Design and Implementation (Cont.) Important principle to separate Policy: What will be done? Mechanism: How to do it? For example: How to make sure that OS maintains control over CPU even if a user program can get stuck in infinite loop or fails to call system services? Use a timer: interrupts after e.g. 1/60sec What is policy and what mechanism here? The timer construct is a mechanism for ensuring CPU protection, but deciding how long the timer is to be set for a particular user is a policy decision Operating System Concepts (Silberschatz et al.) 2.76 Operating System Design and Implementation (Cont.) Important principle to separate Policy: What will be done? Mechanism: How to do it? The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later Policies are likely to change over time, but will not affect mechanism! Specifying and designing OS is highly creative task of software engineering Operating System Concepts (Silberschatz et al.) 2.77 Implementation Much variation Early OSes in assembly language Then system programming languages like Algol, PL/1 Now C, C++ Actually usually a mix of languages Lowest levels in assembly Main body in C System programs in C, C++, scripting languages like PERL, Python, shell scripts More high-level language easier to port to other hardware But slower Emulation can allow an OS to run on non-native hardware Operating System Concepts (Silberschatz et al.) 2.78 Operating System Structure A general-purpose OS can be a very large program Various ways to structure one Example: MS-DOS – written to provide the most functionality in the least space Not divided into modules Although MS-DOS has some structure, its interfaces and levels of functionality are not well separated Application programs can access basic I/O routines and write directly to disk drives: can lead to system crash when program fails Operating System Concepts (Silberschatz et al.) 2.79 Example: Traditional UNIX UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The UNIX OS consists of two separable parts: System programs The kernel Consists of everything below the system-call interface and above the physical hardware Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level Beyond simple but not fully layered Operating System Concepts (Silberschatz et al.) 2.80 Layered OS Designs 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 With modularity, layers are selected such that each uses functions (operations) and services of only lowerlevel layers Advantages and disadvantages of layering? Operating System Concepts (Silberschatz et al.) 2.81 Layered OS Designs 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 With modularity, layers are selected such that each uses functions (operations) and services of only lowerlevel layers Simplifies system verification and debugging: test layer by layer! Operating System Concepts (Silberschatz et al.) How to define layers? Overheads per layer… 2.82 Microkernel System Structure Moves as much from the kernel into user space Take policy and mechanism separation to the extreme: primitive building blocks almost policy-free: Complex policies added via user-created kernel modules Mach example of microkernel Mac OS X kernel (Darwin) partly based on Mach Communication takes place between user modules using message passing Pros and cons? Operating System Concepts (Silberschatz et al.) 2.83 Microkernel System Structure Moves as much from the kernel into user space Take policy and mechanism separation to the extreme: primitive building blocks almost policy-free: Complex policies added via user-created kernel modules Mach example of microkernel Mac OS X kernel (Darwin) partly based on Mach Communication takes place between user modules using message passing 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 Detriments: Performance overhead of user space to kernel space communication Operating System Concepts (Silberschatz et al.) 2.84 Microkernel System Structure Communication via message passing Application Program File System messages Interprocess Communication Device Driver user mode messages memory managment CPU scheduling kernel mode microkernel hardware Operating System Concepts (Silberschatz et al.) 2.85 Optional Reading: Microkernel vs Monolithic Kernel https://en.wikipedia.org/wiki/Tanenbaum%E2%80%93Torvalds_debate Operating System Concepts (Silberschatz et al.) 2.86 (Loadable) Modules Most modern operating systems implement loadable kernel modules Uses object-oriented approach Each core component is separate Each talks to the others over known interfaces Each is loadable as needed within the kernel Overall, similar to layers but with more flexibilities Linux, Solaris, etc Similar to micro-kernel concept (primary module has only core functions), but more efficient: no need for message passing between kernel modules Operating System Concepts (Silberschatz et al.) 2.87 Hybrid Systems Most modern operating systems actually not one pure model Hybrid combines multiple approaches to address performance, security, usability needs Linux and Solaris: entire OS in single address space, so monolithic (good for performance!) but also modular for dynamic loading of functionality (good for flexibility!) Windows mostly monolithic, but supports separate subsystems (”personalities” ) Apple Mac OS X hybrid: it is layered (top layer:) Aqua UI plus Cocoa programming environment Below is kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit and dynamically loadable modules (called kernel extensions) Operating System Concepts (Silberschatz et al.) 2.88 macOS and iOS Structure Operating System Concepts (Silberschatz et al.) 2.89 Darwin Operating System Concepts (Silberschatz et al.) 2.90 iOS Apple mobile OS for iPhone, iPad Structured on Mac OS X, but added functionality for mobile devices Does not run OS X applications natively Also runs on different CPU architecture (ARM vs. Intel) Cocoa Touch Objective-C API for developing apps Media services layer for graphics, audio, video Core services provides cloud computing, databases Core operating system, based on Mac OS X kernel Operating System Concepts (Silberschatz et al.) 2.91 Android Developed by Open Handset Alliance (mostly Google) Open Source Similar stack to IOS Based on Linux kernel but modified Provides process, memory, device-driver management Adds power management Runtime environment includes core set of libraries and Dalvik virtual machine Apps developed in Java plus Android API Java class files compiled to Java bytecode then translated to executable than runs in Dalvik VM Libraries include frameworks for web browser (webkit), database (SQLite), multimedia, smaller libc Operating System Concepts (Silberschatz et al.) 2.92 Android Architecture Operating System Concepts (Silberschatz et al.) 2.93 Operating-System Debugging Debugging is finding and fixing errors, or bugs OSes generate log files containing error information Failure of an application can generate core dump file capturing memory of the process Operating system failure can generate crash dump file containing kernel memory Beyond crashes, performance tuning can optimize system performance Sometimes using trace listings of activities (events with time), recorded for analysis Profiling is periodic sampling of instruction pointer to look for statistical trends (which code is executed?) Kernighan’s Law: “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” Operating System Concepts (Silberschatz et al.) 2.94 Performance Tuning Improve performance by removing bottlenecks OS must provide means of computing and displaying measures of system behavior For example, “top” program or Windows Task Manager Operating System Concepts (Silberschatz et al.) 2.95 Tracing Collects data for a specific event such as steps involved in a system call invocation Tools include strace – trace system calls invoked by a process gdb – source-level debugger perf – collection of Linux performance tools tcpdump – collects network packets Many other tools (next slide) Operating System Concepts (Silberschatz et al.) 2.96 https://github.com/iovisor/bcc Operating System Concepts (Silberschatz et al.) 2.97 What You’ll Learn Today You will be able: To describe the services an operating system provides to users, processes, and other systems To discuss the various ways of structuring an operating system To explain how operating systems are installed and customized and how they boot Operating System Concepts (Silberschatz et al.) 2.98 Building and Booting an Operating System Operating systems generally designed to run on a class of systems with variety of perpherals Commonly, operating system already installed on purchased computer But can build and install some other operating systems If generating an operating system from scratch Write the operating system source code Configure the operating system for the system on which it will run Compile the operating system Install the operating system Boot the computer and its new operating system Operating System Concepts (Silberschatz et al.) 2.99 Operating System Generation SYSGEN program obtains information concerning the specific configuration of the hardware system e.g., what CPU is used, what instruction sets are available how is the boot disk formatted how much memory, what devices, etc.? e.g. from file or by probing hardware Used to build system-specific compiled kernel or system-tuned Can general more efficient code than one general kernel Operating System Concepts (Silberschatz et al.) 2.100 System Boot When power initialized on system, execution starts at a fixed memory location Firmware ROM used to hold initial boot code: between software and hardware: slower than RAM and expensive, so copy to memory for execution) Operating system must be made available to hardware so hardware can start it Small piece of code – bootstrap loader, stored in ROM or EEPROM locates the kernel, loads it into memory, and starts it Sometimes two-step process where boot block at fixed location loaded by ROM code, which loads bootstrap loader from disk Common bootstrap loader, GRUB, allows selection of kernel from multiple disks, versions, kernel options Kernel loads and system is then running Operating System Concepts (Silberschatz et al.) 2.101 What You’ll Learn Today You will be able: To describe the services an operating system provides to users, processes, and other systems To discuss the various ways of structuring an operating system To explain how operating systems are installed and customized and how they boot Operating System Concepts (Silberschatz et al.) 2.102 Have a great weekend ☺ Operating System Concepts (Silberschatz et al.) 2.103