Operating System Fundamentals PDF
Document Details
Uploaded by Deleted User
null
null
null
Tags
Summary
This document provides notes on operating systems, covering topics such as transition from user to kernel mode, process management, memory management, and storage management. It includes key concepts and principles related to operating systems.
Full Transcript
Transition from User to Kernel Mode EL PT N 1 Timer To prevent process to be in infinite loop (process hogging resources), a timer is used, which is a hardware device. EL...
Transition from User to Kernel Mode EL PT N 1 Timer To prevent process to be in infinite loop (process hogging resources), a timer is used, which is a hardware device. EL Timer is a counter that is decremented by the physical clock. Timer is set to interrupt the computer after some time period Operating system sets the counter (privileged instruction) PT When counter reaches the value zero, and interrupt is generated. The OS sets up the value of the counter before scheduling a process to regain control or terminate program that exceeds N allotted time 2 Process Management A process is a program in execution. It is a unit of work within the system. Program is a passive entity, process is an active entity. Process needs resources to accomplish its task EL CPU, memory, I/O, files, etc. Initialization data Process termination requires reclaim of any reusable resources A thread is a basic unit of CPU utilization within a process. PT Single‐threaded process. Instructions are executed sequentially, one at a time, until completion Process has one program counter specifying location of next instruction to execute Multi‐threaded process has one program counter per thread N Typically, a system has many processes, some user, some operating system running concurrently on one or more CPUs Concurrency by multiplexing the CPUs among the threads 3 Process Management Activities The operating system is responsible for the following activities in connection with process management: EL Creating and deleting both user and system processes Suspending and resuming processes PT Providing mechanisms for process synchronization Providing mechanisms for process communication Providing mechanisms for deadlock handling N 4 Memory Management To execute a program all (or part) of the instructions must be in memory All (or part) of the data that is needed by the program must be in EL memory. Memory management determines what is in memory and when Optimizing CPU utilization and computer response to users PT Memory management activities Keeping track of which parts of memory are currently being used and by whom Deciding which processes (or parts thereof) and data to move into and out N of memory Allocating and deallocating memory space as needed 5 Storage Management OS provides uniform, logical view of information storage Abstracts physical properties to logical storage unit ‐ file EL Files are stored in a number of different storage medium. Disk Flash Memory Tape drive) PT Each medium is controlled by device drivers (i.e., disk drive, tape Varying properties include access speed, capacity, data‐transfer rate, access method (sequential or random) N 6 File System Management Files usually organized into directories Access control on most systems to determine who can access what EL OS activities include Creating and deleting files and directories Primitives to manipulate files and directories PT Mapping files onto secondary storage Backup files onto stable (non‐volatile) storage media N 7 Secondary‐Storage Management Usually disks used to store data that does not fit in main memory or data that must be kept for a “long” period of time Proper management is of central importance EL Entire speed of computer operation hinges on disk subsystem and its algorithms OS activities Free‐space management Storage allocation Disk scheduling PT Some storage need not be fast N Tertiary storage includes optical storage, magnetic tape Still must be managed – by OS or applications 8 Caching Important principle, performed at many levels in a computer (in hardware, operating system, software) Information in use copied from slower to faster storage temporarily EL Faster storage (cache) checked first to determine if information is there If it is, information used directly from the cache (fast) PT If not, data copied to cache and used there Cache are smaller (size‐wise) than storage being cached Cache management important design problem N Cache size and replacement policy 9 Performance of Various Levels of Storage EL PT N Movement between levels of storage hierarchy can be explicit or implicit 10 Migration of data “A” from Disk to Register Multitasking environments must be careful to use most recent value, no matter where it is stored in the storage hierarchy EL Multiprocessor environment must provide cache coherency in cache PT hardware such that all CPUs have the most recent value in their Distributed environment situation even more complex N Several copies of a datum can exist 11 I/O Subsystem One purpose of an operating system is to hide peculiarities of hardware devices from the user EL I/O subsystem responsible for Memory management of I/O including buffering (storing data temporarily while it is being transferred), caching (storing parts of data in faster storage for performance), spooling (the overlapping of output of one job with input of other jobs) PT General device‐driver interface Drivers for specific hardware devices N 12 Protection and Security Protection – A mechanism for controlling access of processes (or users) to resources defined by the OS Security – A defense of the system against internal and external attacks EL Huge range, including denial‐of‐service, worms, viruses, identity theft, theft of service Systems generally first distinguish among users, to determine who can do what PT User identities (user IDs, security IDs) include name and associated number, one per user User ID is associated with all files and processes of that user to determine access control Group identifier (group ID) allows set of users to be defined and controls managed, N then also associated with each process, file Privilege escalation allows user to change to effective ID with more rights 13 Conclusion: Operating system acts as an interface between computer hardware and users Makes the system usable in an user‐friendly manner EL Controls usage of different hardware and software resources in a computer system What is an Operating System? PT Specific activities include: Process Management Memory Management Storage Management N Protection and Security 14 N PT EL 15 EL Operating System Fundamentals Santanu Chattopadhyay Electronics and Electrical Communication Engg. PT Operating System Structures N 16 Concepts Covered: Services an operating system provides EL to users, processes, and other systems Various ways of structuring an operating system PT How operating systems are installed and customized and how they boot N 17 Operating System Services Provides an environment for the execution of programs. Provides certain services to: EL Programs Users of those programs Basically two types of services: PT Set of operating‐system services provides functions that are helpful to the user Set of operating‐system functions for ensuring the N efficient operation of the system itself via resource sharing 18 OS Services Helpful to the User User interface ‐ Almost all operating systems have a user interface (UI). Several forms: Command‐Line (CLI) ‐‐ uses text commands and a method for entering them EL (say, a keyboard for typing in commands in a specific format with specific options). Graphics User Interface (GUI) ‐‐ the interface is a window system with a pointing device to direct I\O, choose from menus, and make selections and a keyboard to enter text.. PT Batch Interface ‐‐ commands and directives to control those commands are entered into files, and those files are executed Some systems provide two or all three of these variations. N 19 OS Services Helpful to the User (Contd.) Program execution ‐ The system must be able to load a program into memory and to run that program, end execution, either normally or EL abnormally (indicating error) I/O operations ‐ A running program may require I/O, which may involve a file or an I/O device PT File‐system manipulation ‐ Programs need to read and write files and directories, create and delete them, search them, list file Information, permission management. N 20 OS Services Helpful to the User (Contd.) Communications – Processes may exchange information, on the same computer or between computers over a network EL Communications may be via shared memory or through message passing (packets moved by the OS) 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 PT For each type of error, OS should take the appropriate action to ensure correct and consistent computing N Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system 21 OS Services for Ensuring Efficient Operation Resource allocation ‐ When multiple users or multiple jobs are running concurrently, resources must be allocated to each of them EL Many types of resources ‐ CPU cycles, main memory, file storage, I/O devices. Accounting ‐ To keep track of which users use how much and what kinds of computer resources PT N 22 OS Services for Ensuring Efficient Operation (Contd.) Protection and security ‐ The owners of information stored in a multiuser or networked computer system may want to EL control use of that information, concurrent processes should not interfere with each other Protection involves ensuring that all access to system resources is controlled PT Security of the system from outsiders requires user authentication, extends to defending external I/O devices N from invalid access attempts 23 A View of Operating System Services EL PT N 24 Command Interpreters (CLI) CLI allows users to directly enter commands to be performed by the operating system. Some operating systems include the command interpreter in the kernel. EL Some operating systems, such as Windows and UNIX, treat the command interpreter as a special program that is running when a job is initiated or when a user first logs on. PT On systems with multiple command interpreters to choose from, the interpreters are known as shells. The main function of the command interpreter is to get and execute the next user‐specified command. N Sometimes commands built‐in, sometimes just names of programs If the latter, adding new features doesn’t require shell modification 25 The Bourne shell command interpreter in Solaris EL PT N 26 Bourne Shell Command Interpreter EL PT N 27 Graphical User Interfaces (GUI) User‐friendly desktop metaphor interface Usually mouse, keyboard, and monitor Icons represent files, programs, actions, etc EL 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 PT 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 N Unix and Linux have CLI with optional GUI interfaces (CDE, KDE, GNOME) 28 Touchscreen Interfaces Touchscreen devices require new interfaces Mouse not possible or not desired Actions and selection based on gestures EL Virtual keyboard for text entry Voice commands. PT N 29 The Mac OS X GUI EL PT N 30 System Calls Programming interface to the services provided by the OS Typically written in a high‐level language (C or C++) EL Mostly accessed by programs via a high‐level Application Programming Interface (API) rather than direct system call Three most common APIs are: Win32 API for Windows, PT POSIX API for POSIX‐based systems (including virtually all versions of UNIX, Linux, and Mac OS X), Java API for the Java virtual machine (JVM) N 31 Example of System Calls System call sequence to copy the contents of one file to another file EL PT N 32 Example of Standard API EL PT N 33 System Call Implementation Typically, a number is associated with each system call System‐call interface maintains a table indexed according to these numbers The system call interface invokes the intended system call in OS kernel and returns EL status of the system call and any return values The caller need not know a thing about how the system call is implemented Just needs to obey the API and understand what the OS will do as a result call Most details of OS interface hidden from programmer by API PT Managed by run‐time support library (set of functions built into libraries included with compiler) N 34 System Call ‐‐ OS Relationship The handling of a user application invoking the open() system call EL PT N 35 System Call Parameter Passing Often, more information is required than simply identity of desired system call Exact type and amount of information vary according to OS and call EL Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers In some cases, may be more parameters than registers Parameters stored in a block, or table, in memory, and address of block PT 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 N Block and stack methods do not limit the number or length of parameters being passed 36 Parameter Passing via Table x points to a block of parameters. x is loaded into a register EL PT N 37 Types of System Calls System calls can be grouped roughly into six major categories: Process control, EL File manipulation, Device manipulation, Information maintenance, Communications, Protection. PT The figure in the slide # 28 summarizes the types of system calls normally provided by an operating system. N 38 System Calls – Process Control create process, terminate process end, abort load, execute EL get process attributes, set process attributes wait for time wait event, signal event Dump memory if errorPT allocate and free memory Debugger for determining bugs, single step execution N Locks for managing access to shared data between processes 39 System Calls – File Management Create file Delete file EL Open and Close file Read, Write, Reposition Get and Set file attributes PT N 40 System Calls – Device Management request device, release device read, write, reposition EL get device attributes, set device attributes logically attach or detach devices PT N 41 System Calls ‐‐ Information Maintenance get time or date, set time or date EL get system data, set system data PT get and set process, file, or device attributes N 42 System Calls – Communications create, delete communication connection if message passing model: EL send, receive message To host name or process name From client to server If shared‐memory model: PT create and gain access to memory regions transfer status information attach and detach remote devices N 43 System Calls ‐‐ Protection Control access to resources Get and set permissions EL Allow and deny user access PT N 44 Examples of Windows and Unix System Calls EL PT N 45 Example ‐‐ Standard C Library C program invoking printf() library call, which calls write() system call EL PT N 46 System Programs 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. EL They can be divided into: File manipulation Status information sometimes stored in a File modification Programming language support Communications Background services Application programs PT Program loading and execution N Most users’ view of the operation system is defined by system programs, not the actual system calls 47 System Programs File management Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories EL Status information Some programs ask the system for information ‐ date, time, amount of available memory, disk space, number of users debugging information PT Others programs provide detailed performance, logging, and Typically, these programs format and print the output to the terminal or other output devices N Some systems implement a registry ‐ used to store and retrieve configuration information 48 System Programs (Cont.) File modification Text editors to create and modify files Special commands to search contents of files or perform transformations of the text EL Programming‐language support ‐ Compilers, assemblers, debuggers and interpreters sometimes provided Program loading and execution‐ Absolute loaders, relocatable loaders, linkage editors, and overlay‐loaders, debugging systems for higher‐level and machine language PT Communications ‐ Provide the mechanism for creating virtual connections among processes, users, and computer systems N Allow users to send messages to one another’s screens, browse web pages, send electronic‐mail messages, log in remotely, transfer files from one machine to another 49 System Programs (Cont.) Background Services Launch at boot time Some for system startup, then terminate EL Some from system boot to shutdown Provide facilities like disk checking, process scheduling, error logging, printing Run in user context not kernel context Application programs PT Known as services, subsystems, daemons Don’t pertain to system N Run by users Not typically considered part of OS Launched by command line, mouse click, finger poke 50 Operating System Design and Implementation Design and Implementation of OS not “solvable”, but some approaches have proven successful Internal structure of different Operating Systems can vary widely EL Start the design by defining goals and specifications Affected by choice of hardware, type of system – batch, time sharing, single user, multiuser, distributed, real‐time PT Two groups in terms of defining goals: User goals –should be convenient to use, easy to learn, reliable, safe, and fast System goals –should be easy to design, implement, and maintain, as well as flexible, reliable, error‐free, and efficient N Specifying and designing an OS is highly creative task of software engineering 51 Mechanisms and Polices Important principle to separate Policy: What will be done? EL Mechanism: How to do it? Mechanisms determine how to do something, policies decide what will be done PT The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later (example – timer) N 52 Implementation Much variation Early Operating Systems were written in assembly language Then with system programming languages like Algol, PL/1 EL Now C, C++ Actually usually a mix of languages Lowest levels in assembly Main body in C PT Systems programs in C, C++, scripting languages like PERL, Python, shell scripts High‐level language easier to port to other hardware But slower N Emulation can allow an OS to run on non‐native hardware 53 Operating System Structure Various ways to structure an operating system: Monolithic structure Simple structure – MS‐DOS EL More complex – UNIX More complex – Linux Layered – An abstraction PT Microkernel ‐ Mach N 54 MS‐DOS MS‐DOS – written to provide the most functionality in the least amount of space EL MS‐DOS was limited by hardware funcionality. Not divided into modules Although MS‐DOS has some PT structure, its interfaces and levels of functionality are not well separated N 55 UNIX UNIX – the original UNIX operating system had limited structuring and was limited by hardware functionality. EL The UNIX OS consists of two separable parts Systems programs The kernel Consists of everything below the system‐call interface and above the physical hardware PT Provides the file system, CPU scheduling, memory management, and other operating‐system functions; a large number of functions for one level N 56 Traditional UNIX System Structure EL PT N 57 Linux System Structure EL PT N 58 Modularity The monolithic approach results in a situation where changes to one part of the system can have wide‐ranging effects to other parts. EL Alternatively, we could design system where the operating system is divided into separate, smaller components that have specific and limited functionality. The sum of all these PT components comprises the kernel. Advantage: Changes in one component only affect that component, and no others, allowing system implementers more freedom when changing the inner workings of the N system and in creating modular operating systems. 59