Скачать презентацию Operating Systems and Linux Partha Sarathi Dasgupta MIS Скачать презентацию Operating Systems and Linux Partha Sarathi Dasgupta MIS

3a135469c2b073e100a18f0e4d9d5266.ppt

  • Количество слайдов: 41

Operating Systems and Linux Partha Sarathi Dasgupta MIS Group Indian Institute of Management Calcutta Operating Systems and Linux Partha Sarathi Dasgupta MIS Group Indian Institute of Management Calcutta 1

What does an Operating System do? • An Operating System exploits the hardware resources What does an Operating System do? • An Operating System exploits the hardware resources of one or more processors to provide a set of services to system users. • An Operating System also manages secondary memory and input/output devices on behalf of its users. 2

Structural Elements of a Computer • Processor: Controls the operation of the computer and Structural Elements of a Computer • Processor: Controls the operation of the computer and its Data Processing functions. . A single processor is often termed as the Central Processing Unit. • Main memory: Stores data and programs. This memory is typically volatile. Contents of disk memory are retained even when the computer is shut down. • I/O modules: Moves data between the computer and its external environment, such as disks, data communication equipments, and terminals. • System bus: Provides for communication between processors, main memory, and I/O modules. 3

Structural Elements of a Computer: Schematic view CPU 0 PC MBR IR Execution 1 Structural Elements of a Computer: Schematic view CPU 0 PC MBR IR Execution 1 MAR I/O AR 2 Instruction I/O BR Data Buffers n -2 n -1 Input-Output Module 4

Interrupts • A mechanism by which other modules (I/O, memory) may interrupt the normal Interrupts • A mechanism by which other modules (I/O, memory) may interrupt the normal sequencing of the processor • Interrupts help to improve processor utilization. • Classes of interrupts: § Program: generated by some condition that occurs as a result of an instruction execution, such as arithmetic overflow, division by zero, attempt to execute an illegal machine instruction, and reference outside a user’s allowed memory space. § Timer: Generated by a timer within the processor. This allows the operating system to perform certain functions regularly. § I/O: Generated by an I/O controller, to signal normal completion of an operation or to signal a variety of error conditions. § H/W failure: Generated by a failure, such as power, etc. 5

An Example A processor has two programs P 1 and P 2 to execute: An Example A processor has two programs P 1 and P 2 to execute: P 1 is simply reading data from memory and writing the data into the disk. P 2 is doing only calculations. Processor may begin P 1 first, issue a write command to the external device, and then proceed with P 2. Two cases: • Writing to disk initiated by P 1 might finish before P 2 completes calculations. • P 2 completes calculations before the disk writing initiated by P 1 finishes. What are the consequences of these two cases? 6

Memory Hierarchy Registers Cache Main Memory Magnetic disk, CD-ROM, CD-RW DVD-RW, DVD-RAM Magnetic tape Memory Hierarchy Registers Cache Main Memory Magnetic disk, CD-ROM, CD-RW DVD-RW, DVD-RAM Magnetic tape 7

Cache • a portion of the main memory that can be used as a Cache • a portion of the main memory that can be used as a buffer • temporarily holds data that are to br read out to disk • Caches improve the performance in two ways: § Disk writes are clustered. § instead of having many small transfers of data, few large transfers are possible. § some data meant for write-out (from disk) may be directly accessed from the cache very fast. 8

Operating System • It is a program that § controls the execution of application Operating System • It is a program that § controls the execution of application programs § acts as an interface between applications and computer hardware § manages the resources associated with a computer Objectives of an O. S. § Convenience of use of the computer § Efficient use of the computing resources § Should be such that it can permit effective development, testing and introduction of new system functions without affecting he service. 9

Operating System as an Interface Application Programs End user Utilities Programmer Operating System Computer Operating System as an Interface Application Programs End user Utilities Programmer Operating System Computer Hardware OS System Designer 10

Operating System Services • Program Development – variety of services and utilities such as Operating System Services • Program Development – variety of services and utilities such as Editors and debuggers. They are usually referred to as application program development tools. • Program Execution – involves a number of steps, such as loading Instruction and data in the main memory, initialisation of I/O devices and files, and other resources to be allocated. OS handles the scheduling. • Access to I/O devices – Each I/O device has its own set of Instructions and control signals. O. S. hides these details to provide a common interface to the user/programmer. 11

Operating System Services • Controlled access to files- nature of I/O device (disk drive, Operating System Services • Controlled access to files- nature of I/O device (disk drive, tape drive) and structure of the data stored in the files in the storage medium. In the case of multiple users accessing the processor concurrently, proper protection mechanisms have to be used. • System access- For shared or public systems, the O. S. controls access to the system as a whole and to specific system resources. Access system provides protection of resources, and data from unauthorised users, and resolves resource conflicts • Error detection and response – Variety of errors may occur in computer system. Responses may range from program termination, retrial of the same operation, or reporting error to the application. • Accounting – collecting usage statistics, CPU usages, monitor performance, etc. 12

Evolution of Operating Systems • Serial Processing § From 1940 s to mid-1950 s Evolution of Operating Systems • Serial Processing § From 1940 s to mid-1950 s § Programmer interacted with the hardware § Programs in machine code were loaded via the input device (card reader) § In case of any error, they were indicated with lights Associated problems: § Scheduling: Hardcopy sigh-up sheet for reserving time § User could reserve for 45 mins and finish in 30 mins => wastage of time § User may not be able to finish in scheduled time 13

Evolution of Operating Systems • Simple Batch Processing § for maximizing machine utilisation § Evolution of Operating Systems • Simple Batch Processing § for maximizing machine utilisation § batch O. S. used § a piece of software called the monitor used § monitor reads in jobs one at a time from the input device § as a job is read in, control is passed to the current job; control returns back to the monitor when the job is finished § results of a job are sent to an output device such as the printer § Processor is executing the instructions from those of the monitor § Processor will then execute the instruction of the user program until it encounters an ending or error condition § instructions for the monitor are contained in the JCL monitor Interr Device Job upt drivers seque proce ncing ssing Control language interpreter User Program Area 14

Modes of a user program • A user program executes in user mode, in Modes of a user program • A user program executes in user mode, in which certain areas of memory are protected from the user’s use, and • certain instructions may not be executed. • monitor executes in a system mode, or a kernel mode, in which privileged instructions may be executed and protected memory segments accessed. • Batch O. S. – machine time alternates between monitor and the user programs. • Effect: some memory given to the monitor, and some of the machine time is consumed by the monitor. 15

An example of System Utilization Read one record from a file = 19 μs An example of System Utilization Read one record from a file = 19 μs Execute 100 instructions = 2 μs Write one record to a file = 19 μs ----- TOTAL 40 μs Percent CPU utilization = 2/40 = 0. 005 = 0. 5% 16

An example of Multiprogramming P 1 Run P 2 Wait P 3 P 1, An example of Multiprogramming P 1 Run P 2 Wait P 3 P 1, P 2, P 3 Wait Run Wait Run Run Wait Any Advantage? 17

Multiprogramming/Multitasking: Some Figures Multiprogramming Operating systems are more complex • Memory management • Scheduling Multiprogramming/Multitasking: Some Figures Multiprogramming Operating systems are more complex • Memory management • Scheduling Uniprogramming Multiprogramming Processor use 20% 40% Memory use 33% 67% Disk use 33% 67% Printer use 33% 67% Elapsed time 30 min 15 min Throughput 6 jobs/hr 12 jobs/hr Mean response time 18 min 10 min Effect of Multiprogramming on Resource Utilization 18

Time-Sharing Systems • For some jobs, e. g. , for transaction processing jobs, it Time-Sharing Systems • For some jobs, e. g. , for transaction processing jobs, it is desirable that users may interact directly with the computer • Processor time is shared among multiple users through time sharing • multiple users simultaneously access the system through terminals, with the O. S. interleaving the execution of each user program in time quanta. • For n users actively requesting service at one time (for instance, all editing files), each user will only see on the average 1/n of the effective computer capacity (approx. ) • Given the slow human reaction time, response time is similar to that on a dedicated machine 19

Multiprogramming and Time-Sharing • Multiprogramming maximises CPU utilization • Time-sharing minimizes user response rime Multiprogramming and Time-Sharing • Multiprogramming maximises CPU utilization • Time-sharing minimizes user response rime What about the Throughput? 20

Major theoretical advances in development of O. S. • Processes • Memory management • Major theoretical advances in development of O. S. • Processes • Memory management • Information protection and security • Scheduling and resource management • System structure 21

Processes A process is • a program in state of execution • An instance Processes A process is • a program in state of execution • An instance of a program running on a computer • The entity that can be assigned to and executed on a processor • A unit of activity characterised by a single sequential thread of execution, a current state, and an associated set of system resources 22

Why Processes need to be scheduled? • Improper synchronization: for example, a process that Why Processes need to be scheduled? • Improper synchronization: for example, a process that initiates an I/O read must wait until the data are available in a buffer. This requires signal from some other process. • Mutual exclusion: multiple users might try to access a shared resource concurrently, e. g. , editing the same file at the same time. Mutual exclusion mechanism required. • Non-determinate program operation: Results of a program normally depend on the input to that program only. When programs share memory, and their execution is interleaved by the processor, they may interfere with each other. Order of program execution may affect the execution of a particular program. • Deadlock: It is possible for two or more programs to be hung up waiting for each other. 23

Parts of a Process • Components of a process § An executable program § Parts of a Process • Components of a process § An executable program § Associated data required by the program (variable, work space, buffer, etc. ) § Execution context: internal data used by O. S. to supervise a process = process state. Process list Main memory Program code data context 24

Process Control Block • Identifier: A unique integer associated with a process • State Process Control Block • Identifier: A unique integer associated with a process • State : A currently executing process is in running state • Priority : Priority level relative to other processes • Program counter : Address of the next instruction of the program to be executed. • Memory pointers: pointers to the program code and data associated with the process, and any shared memory blocks • Context data: Data in the registers in the processor during process execution. • I/O status information: outstanding I/O requests, I/O devices allocated to the process, a list of files is use by the process, etc. • Accounting information: amount of processor time, etc. 25

Key responsibilities of Resource management • O. S. manages the resources of a computer Key responsibilities of Resource management • O. S. manages the resources of a computer system • Factors for scheduling policy: § Fairness: processes competing for a resource should be given fair chance of resource access § Differential responsiveness: O. S. should make allocation and scheduling decisions to meet total set of requirements, and in a dynamic manner. E. g. , if a process is waiting for an I/O device, O. S. may schedule that process as soon as the device is free. § Efficiency: Maximize throughput, minimize response time, and accommodate as many concurrent users as possible. 26

Virtual Memory • A facility that allows programs to address memory from a logical Virtual Memory • A facility that allows programs to address memory from a logical viewpoint • Disregards the amount of physical memory actually available • Meets the requirements of multiple user processes to reside simultaneously in main memory without any interference • (Demand) Paging system and Page faults • Address of a word of a program = page number + offset within page • Pages vs Blocks mapping 27

Problem of contiguous block assignment File A 10 File B 20 File C 30 Problem of contiguous block assignment File A 10 File B 20 File C 30 Is the contiguous block allocation OK? 28

Why use Linux/Unix? • System is written in a high-level language => easy to Why use Linux/Unix? • System is written in a high-level language => easy to read, understand, change and port to other machines. • Simpler user interface or user services • Provides simple routines to write complex programs/develop utilities • Hierarchical file system for easy maintenance • Consistent format for files (byte streams) making application development easier • Simple, consistent interface to peripheral devices 29

UNIX Architecture • Kernel Application Programs • Shell UNIX commands and libraries • Utilities UNIX Architecture • Kernel Application Programs • Shell UNIX commands and libraries • Utilities System call interface bash H/W Kernel who wc vi 30

Traditional Unix Kernel User programs Libraries User level Kernel level System call interface File Traditional Unix Kernel User programs Libraries User level Kernel level System call interface File subsystem IPC Process control Buffer cache scheduler subsystem Character Block Memory management Device drivers Hardware control Kernel level Hardware 31

Some Basic Characteristics of Linux • Multi-user System • Multiprogramming/Multitasking system • Uses Time Some Basic Characteristics of Linux • Multi-user System • Multiprogramming/Multitasking system • Uses Time Sharing • Access rights for Files and Processes • Uses File and Process hierarchies 32

Linux File System Characteristics: • Hierarchical structure • Consistent treatment of file data • Linux File System Characteristics: • Hierarchical structure • Consistent treatment of file data • Ability to create, modify and delete files • Dynamic growth of files • Protection of file data • Treating peripheral devices (terminals, tapes, etc. ) as files 33

Linux File System Layout (Red. Hat) 34 Linux File System Layout (Red. Hat) 34

Directory Structure of Linux File System Directory Content /bin Common programs, shared by the Directory Structure of Linux File System Directory Content /bin Common programs, shared by the system, the system administrator and the users. /boot The startup files and the kernel, vmlinuz. In recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today. /dev Contains references to all the CPU peripheral hardware, which are represented as files with special properties. /etc Most important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows /home Home directories of the common users. /initrd (on some distributions) Information for booting. Do not remove! /lib Library files, includes files for all kinds of programs needed by the system and the users. 35

Directory Structure of Linux File System Directory Content /lost+found Every partition has a lost+found Directory Structure of Linux File System Directory Content /lost+found Every partition has a lost+found in its upper directory. Files that were saved during failures are here. /misc For miscellaneous purposes. /mnt Standard mount point for external file systems, e. g. a CD-ROM or a digital camera. /net Standard mount point for entire remote file systems /opt Typically contains extra and third party software. /proc A virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. /root The administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the root user. /sbin Programs for use by the system and the system administrator. /tmp Temporary space for use by the system. /usr Programs, libraries, documentation etc. for all user-related programs. /var Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it. 36

Mounting of file systems etc usr tom harry 37 Mounting of file systems etc usr tom harry 37

Types of files in a Linux System Types of files in a Linux System "On a UNIX system, everything is a file; if something is not a file, it is a process. " Regular files : they contain normal data, for example text files, executable files or programs, input for or output from a program and so on. Directories: files that are lists of other files. Special files: Devices treated as files, used for input and output. They exist in /dev. Links: a system to make a file or directory visible in multiple parts of the system's file tree. (Domain) sockets: a special file type, similar to TCP/IP sockets, providing inter-process networking protected by the file system's access control. Named pipes: act more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics. 38

Permissions of a file • Read • Write • execute 39 Permissions of a file • Read • Write • execute 39

Listing files in a Linux System The -l option to ls displays the file Listing files in a Linux System The -l option to ls displays the file type, using the first character of each input line: psdg/Documents> ls –l total 8 -rw-rw-r-- 1 psdg faculty 31744 Feb 21 17: 56 samplefile 1. doc lrw-rw-r-- 1 psdg faculty 41472 Feb 21 17: 56 samplefile 2 drwxrwxr-x 2 psdg faculty 4096 Feb 25 11: 50 os-course/ crw-rw-r-- 1 psdg faculty 41472 Feb 21 17: 56 /dev/tty 00 Symbol Meaning - Regular file d Directory l Link c Special file s Socket p Named pipe 40

User Accounts • login nmes • passwords • user id • group id • User Accounts • login nmes • passwords • user id • group id • Home directory 41