introduction To Operating System


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

introduction To Operating System

  1. 1. Operating Systems 7.1 Introduction 7.2 Storage Management 7.3 Process Management 7.4 I/O Management
  2. 2. Introduction <ul><li>Os – “Executive Manager” is the part of the computing system that manages all of the hardware and all of the software. </li></ul><ul><li>OS controls every device, every section of memory and every nanosecond of processing time. </li></ul><ul><li>OS also controls who can use the system and how. </li></ul><ul><li>OS is a program running at all times on a computer with all other programs being application programs. </li></ul><ul><li>Without an OS, no applications can be run. </li></ul><ul><li>A computer system interfaces the user through an operating system. The user through an operating system enters instructions into a computer system. </li></ul><ul><li>Examples : MS-DOS, Windows NT/2000, Mac OS </li></ul>
  3. 3. Major OS Components <ul><li>Memory Manager </li></ul><ul><ul><li>In charge of main memory such as check the validity of each request for memory space etc. </li></ul></ul><ul><li>Processor Manager </li></ul><ul><ul><li>Decides how to allocate the CPU. </li></ul></ul><ul><ul><li>Keep track of status of each process </li></ul></ul><ul><li>Device Manager </li></ul><ul><ul><li>Monitors every device, channel and control unit. </li></ul></ul><ul><li>File Manager </li></ul><ul><ul><li>Keeps track for every file in the system including data files, assemblers, compilers and application programs. </li></ul></ul><ul><li>User Command Interface </li></ul>
  4. 4. OS Subsystem Manager Tasks <ul><li>Monitor its resources continuously </li></ul><ul><li>Enforce the policies that determine who gets what, when and how much </li></ul><ul><li>Allocate the resources - reclaim it - when appropriate </li></ul><ul><li>Deallocate the resource - reclaim it - when appropriate </li></ul>
  5. 5. OS Services <ul><li>Program execution </li></ul><ul><li>I/O operation </li></ul><ul><li>File and directory services </li></ul><ul><li>Communication </li></ul><ul><li>Error detection and handling </li></ul><ul><li>Resource allocation </li></ul><ul><li>Protection </li></ul><ul><li>Accounting </li></ul>
  6. 6. OS Services <ul><li>i)     Program execution : loads and executes programs, allows debugging </li></ul><ul><li>ii) I/O operation : does all read and write operations which may involve a file or an I/O device like printer </li></ul><ul><li>iii)   File system manipulation : allows to read/write files as well as create and delete them </li></ul><ul><li>iv)   Communication : allows processes to communicate with each other </li></ul><ul><li>v)    Error detection : CPU, hardware, instructions, device errors </li></ul><ul><li>vi)    Resource allocation : manages resources so that they are optimally utilized </li></ul><ul><li>vii) Security/protection : stop unauthorized access, protect system from imposters </li></ul><ul><li>viii) Accounting : user bills, user/system, statistics </li></ul>
  7. 7. <ul><li>OS functions </li></ul><ul><ul><li>1. Provides interface to computer system </li></ul></ul><ul><ul><li>2. Control program: controls the various I/O devices and user programs </li></ul></ul><ul><ul><li>3. Resource allocator: operating system acts as the manager of these resources and allocates them to specific programs and user. (CPU time, memory space, file storage space and I/O device) </li></ul></ul><ul><li>OS deals with : </li></ul><ul><ul><li>1. storage management </li></ul></ul><ul><ul><li>2. memory management </li></ul></ul><ul><ul><li>3. process management </li></ul></ul><ul><ul><li>4. I/O management </li></ul></ul>
  8. 9. Components of OS <ul><li>1. Shell </li></ul><ul><ul><li>Shell is the outer layer of an operating system </li></ul></ul><ul><ul><li>is the part of the operating system that interfaces with the user. </li></ul></ul><ul><ul><li>is the interface to which accepts, interprets and then executes commands from users. </li></ul></ul><ul><ul><li>2 types : </li></ul></ul><ul><ul><ul><li>Command Line Interpreter (CLI) </li></ul></ul></ul><ul><ul><ul><li>Graphical User Interface (GUI) </li></ul></ul></ul>
  9. 10. Components of OS (cont.) <ul><li>2. Kernel </li></ul><ul><ul><li>the central module of an operating system. </li></ul></ul><ul><ul><li>Kernel's position is between application program and device driver. </li></ul></ul><ul><ul><li>is responsible for resource allocation, low-level hardware interfaces, security </li></ul></ul><ul><ul><li>is the part of the operating system that is loaded first, and remains in main memory. </li></ul></ul><ul><ul><li>Because it stays in memory, it is important for kernel to be as small as possible. </li></ul></ul>
  10. 11. Functions performed by kernel <ul><li>Amongst the functions performed by the kernel are: </li></ul><ul><ul><li>Managing the machine’s memory and allocating it to each process </li></ul></ul><ul><ul><li>Scheduling the work done by the CPU so that the work of each user is carried out as efficiently as is possible </li></ul></ul><ul><ul><li>Organizing the transfer of data from one part of the machine to another </li></ul></ul><ul><ul><li>Accepting instructions from the shell and carrying them out </li></ul></ul><ul><ul><li>Enforcing the access permissions that are in force on the file system </li></ul></ul>
  11. 12. 7.2 Primary Storage Management <ul><li>Execution of a program involves a sequence of instructions within that program. </li></ul><ul><li>The execution of an individual program is called a process or task. </li></ul><ul><li>Many processes are loaded into RAM. All these processes compete in using the CPU. </li></ul><ul><li>A part of kernel, which is called memory manager, manages processes in RAM. </li></ul>
  12. 13. <ul><li>Functions of a memory manager: </li></ul><ul><ul><li>1.keeping track of which parts of memory are currently being used and by whom </li></ul></ul><ul><ul><li>2.deciding which processes are to be loaded into memory when memory space becomes available </li></ul></ul><ul><ul><li>3. allocating and deallocating memory space as needed </li></ul></ul><ul><ul><li>4. allowing the running of programs that are larger than memory . </li></ul></ul>
  13. 14. <ul><li>For a program to be executed, it must be mapped to absolute addresses and loaded into memory. As the program executes, it accesses program instructions and data from memory by generating these absolute addresses. </li></ul><ul><li>Eventually, when the program terminates, its memory space is declared available, and the next program can be loaded and executed. </li></ul>
  14. 15. 7.2 Secondary Memory Management <ul><li>Secondary storage is needed because : </li></ul><ul><ul><li>I.Main memory is not big enough to keep all data and program </li></ul></ul><ul><ul><li>2. Data kept in main memory will be lost if computer is shut down </li></ul></ul><ul><li>In relation to secondary memory management, OS is concerned about: </li></ul><ul><ul><li>Free space management </li></ul></ul><ul><ul><li>Storage allocation </li></ul></ul><ul><ul><li>Disk scheduling </li></ul></ul>
  15. 16. 7.2 Virtual Memory <ul><li>Computer can get out of memory when: </li></ul><ul><ul><li>we run more applications than is allowed by the amount of RAM in the computer </li></ul></ul><ul><ul><li>we run a program that requires amount of memory that exceeds the amount of RAM in the computer </li></ul></ul><ul><li>to overcome this problem, virtual memory can be used. </li></ul><ul><li>In virtual memory, part of hard disk is used as an extension to RAM. </li></ul><ul><li>When a program is executed, part of it is stored on RAM and another part is stored on disk. The part of the program that is stored on disk is only brought into memory when it is executed. </li></ul><ul><li>Implementation of virtual memory uses paging method . </li></ul>
  16. 17. 7.2 Virtual Memory <ul><li>Paging method: </li></ul><ul><ul><li>a program is divided into small segments called page. </li></ul></ul><ul><ul><li>A page size is normally between 1-4 kB. This size is constant. </li></ul></ul><ul><ul><li>An area of hard disk called swap page is specified to hold pages not held in main memory. </li></ul></ul><ul><ul><li>Main memory is also divided into pages called frame. </li></ul></ul><ul><ul><li>During program execution, one or more pages are held in memory and the remainder is held in disk or swap space. </li></ul></ul><ul><ul><li>The pages in disk are copied into main memory when needed for current processing. </li></ul></ul>
  17. 18. 7.2 Virtual Memory <ul><li>Paging method: </li></ul><ul><ul><li>If necessary, existing pages in main memory can be swapped out to disk to make room for pages being swapped in. The selected page that is swapped out is called victim. </li></ul></ul><ul><ul><li>Pages that are least recently used or least frequently used are usually victims. When a victim is selected, it might or might not be copied back to the swap space. </li></ul></ul><ul><ul><li>Each memory reference made by a program must be checked to see it refers to a page in memory. References to pages not contained in memory are referred as page faults. </li></ul></ul><ul><ul><li>Tables are used to store information about the allocation of program segments to pages and the location of those pages in primary and secondary storage. </li></ul></ul><ul><ul><li>Each active process will have a table page or portion of a table page dedicated to storing its page information. </li></ul></ul>
  18. 19. 7.2 Virtual Memory <ul><li>Advantages of virtual memory: </li></ul><ul><ul><li>Programs requiring memory space larger than physical memory can be run. No constraint on the memory size. </li></ul></ul><ul><ul><li>More programs can be run at one time because one program could take less physical memory. </li></ul></ul><ul><ul><li>Less I/O would be needed to load or swap each user program into memory, so each user program would run faster. Only pages from disk are swapped instead of programs. </li></ul></ul><ul><ul><li>Programming task is easier. Programmer does not have to worry about memory available. </li></ul></ul>
  19. 20. Swapping Vs Paging <ul><li>Swapping: </li></ul><ul><ul><li>Moving the entire process which is idle/not running together with all the data from main memory to be used by other processes. </li></ul></ul><ul><ul><li>Moves the entire address spaces between disk and memory. </li></ul></ul><ul><li>Paging: </li></ul><ul><ul><li>Dividing the whole process into pages and the memory into frames. Size of page and frames are the same. When loading a program, any page of the program can be placed in any unused page frame. </li></ul></ul><ul><ul><li>Moves individual pages only between disk and memory, so part of an address space on disk while the other part is in main memory. </li></ul></ul>
  20. 21. 7.3 Process Management <ul><li>A process is a program in execution. </li></ul><ul><li>Example : saving a Word document, spooling files to printer, a single mathematical calculation </li></ul><ul><li>A process is active, it contains a program counter that indicates the address in memory of the next instruction to be executed. </li></ul><ul><li>A process can be in 5 states: </li></ul><ul><ul><li>1. New </li></ul></ul><ul><ul><li>2. Running </li></ul></ul><ul><ul><li>3. Waiting : for some event to occur </li></ul></ul><ul><ul><li>4. Ready : to be assigned to a processor </li></ul></ul><ul><ul><li>5. Terminated : finished execution </li></ul></ul>
  21. 22. <ul><li>Only one process can be running at one time. However, many processes may be ready or waiting. </li></ul><ul><li>Processes are executed in a sequential manner. The CPU executes one process after another until the process is completed. </li></ul><ul><li>Management of processes by the operating system is called scheduling . </li></ul><ul><li>Scheduling is done by scheduler (a part of the kernel). </li></ul><ul><ul><li>Job scheduler: only concerned with selecting jobs from a queue of incoming jobs and placing them in the process queue </li></ul></ul><ul><ul><li>Process scheduler: assigns the CPU to execute the processes of those jobs placed on the ready queue by the Job Scheduler. </li></ul></ul><ul><li>In scheduling, a queue is created where each process will wait for its execution. </li></ul><ul><li>When a process is created, it will be placed at the end of the queue. Process in the front of the queue is taken out and is executed. </li></ul>
  22. 23. <ul><li>A process waiting for a source to use can give in to another process : e.g. waiting for an I/O transfer to finish. </li></ul><ul><li>Operating system puts the process in a waiting list and does context switching . </li></ul><ul><li>In context switching, operating system switches execution from one process to another and comes back to the first process. </li></ul><ul><li>Various policies for managing processes : FCFS, SPN, Round Robin. </li></ul>
  23. 24. Job and Process Status Handled by Process Scheduler (low-level scheduler) Handled by Job Scheduler (high-level scheduler) New Ready Running Waiting I/O or event completion Scheduler dispatch I/O or event wait Admitted Interrupt Exit Finished
  24. 25. Transition Among Process States <ul><li>NEW to READY : Job Scheduler using a predefined policy. </li></ul><ul><li>READY to RUNNING : Process Scheduler using some predefined algorithm </li></ul><ul><li>RUNNING back to READY : Process Scheduler according to some predefined time limit or other criterion. </li></ul><ul><li>RUNNING to WAITING : Process Scheduler and is initiated by an instruction in the job. </li></ul><ul><li>WAITING to READY : Process Scheduler and is initiated by signal from I/O device manager that I/O request has been satisfied and job can continue. </li></ul><ul><li>RUNNING to FINISHED : Process Scheduler or Job Scheduler. </li></ul>
  25. 26. 7.3 Time-sharing <ul><li>Occurs when several processes run concurrently on one processor or in parallel on many processors at the same time. </li></ul><ul><li>A time-sharing operating system uses CPU scheduling and multiprogramming to allow users to share time. </li></ul><ul><li>Time-sharing systems are developed to provide interactive use of a computer system at a reasonable cost. </li></ul><ul><li>Almost all mainframes and minicomputers are time-sharing systems. </li></ul>
  26. 27. Mechanism of Time-Sharing <ul><li>A time-sharing operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of time-shared computer-> to share time. </li></ul><ul><li>Several processes are run concurrently -> must be in memory </li></ul><ul><ul><li>Needs memory management and protection. </li></ul></ul><ul><ul><li>Virtual memory may be used </li></ul></ul>
  27. 28. Advantages of Time-Sharing <ul><li>Allows many users use the computer simultaneously. </li></ul><ul><li>At any one time, only a little CPU time is given to a user. </li></ul><ul><li>->System switches very rapidly from one user to the next : user assumes that he/she owns the computer (actually is shared with other users) </li></ul>
  28. 29. Time Slicing <ul><li>Is a technique where each process is given a slice of time before being preempted. </li></ul><ul><ul><li>(each process is given a portion of computer time) </li></ul></ul><ul><li>When a process is running and the period to run the process has ended, the process will be preempted. Then the next process in the queue will run. </li></ul><ul><li>A process will be preempted if the period has ended even though it is not finished. CPU will execute the unfinished process later. </li></ul>
  29. 30. <ul><li>To preempt a process, a clock interrupt is generated. </li></ul><ul><li>The running process will be put into a ready queue and the first process in the ready queue will be selected. </li></ul><ul><li>The order of which process to run at one time is determined by the CPU scheduling algorithms . </li></ul>
  30. 31. A Good Scheduling Policy <ul><li>Maximize throughput by running as many jobs as possible in a given amount of time. </li></ul><ul><li>Maximize CPU efficiency by keeping CPU busy 100 % of time. </li></ul><ul><li>Ensure fairness for all jobs by giving everyone an equal amount of CPU and I/O time. </li></ul><ul><li>Minimize response time by quickly turning around interactive requests. </li></ul><ul><li>Minimize turnaround time by moving entire jobs in/out of system quickly. </li></ul><ul><li>Minimize waiting time by moving jobs out of READY queue as quickly as possible. </li></ul>
  31. 32. Characterization of Scheduling Policies <ul><li>The selection function : determines which process in the ready queue is selected next for execution </li></ul><ul><li>The decision mode : specifies the instants in time at which the selection function is exercised </li></ul><ul><ul><li>Non-preemptive </li></ul></ul><ul><ul><ul><li>Once a process is in the running state, it will continue until it terminates or blocks itself for I/O </li></ul></ul></ul><ul><ul><li>Preemptive </li></ul></ul><ul><ul><ul><li>Currently running process may be interrupted and moved to the Ready state by the OS </li></ul></ul></ul><ul><ul><ul><li>Allows for better service since any one process cannot monopolize the processor for very long </li></ul></ul></ul>
  32. 33. Non-Preemptive Scheduling <ul><li>A process stays on the CPU until it voluntarily releases the CPU </li></ul><ul><ul><li>Long waiting and response times </li></ul></ul><ul><ul><li>May lead to starvation </li></ul></ul><ul><li>Simple, easy to implement </li></ul><ul><li>Not suited for multi-user systems </li></ul><ul><li>Euphemism: “cooperative multitasking” </li></ul>
  33. 34. Preemptive Scheduling <ul><li>The execution of a process may be interrupted by the operating system at any time </li></ul><ul><ul><li>interrupt </li></ul></ul><ul><ul><li>higher priority process </li></ul></ul><ul><ul><ul><li>Arrival of a new process, change the status </li></ul></ul></ul><ul><ul><li>time limit </li></ul></ul><ul><li>Prevents a process from using the CPU for too long </li></ul><ul><li>May lead to race conditions </li></ul><ul><ul><li>Can be solved by using process synchronization </li></ul></ul>
  34. 35. Scheduling Policies <ul><li>First Come First Served (FCFS) </li></ul><ul><li>Round Robin (RR) </li></ul><ul><li>Shortest Process Next (SPN) </li></ul><ul><li>Shortest Remaining Time (SRT) </li></ul><ul><li>Highest Response Ratio Next (HRRN) </li></ul>
  35. 36. Example to Discuss Various Scheduling Policies Service time = total processor time needed in one (CPU-I/O) cycle Jobs with long service time are CPU-bound jobs and are referred to as “long jobs” Process Arrival Time Service Time 1 2 3 4 5 0 2 4 6 8 3 6 4 5 2
  36. 37. First Come First Served (FCFS) <ul><li>Selection function: the process that has been waiting the longest in the ready queue (hence, FCFS) </li></ul><ul><li>Decision mode: non-preemptive </li></ul><ul><ul><li>a process runs until it blocks itself </li></ul></ul>
  37. 38. First Come First Served (FCFS) <ul><li>Non-preemptive. </li></ul><ul><li>Handles jobs according to their arrival time - the earlier they arrive, the sooner they’re served. </li></ul><ul><li>Simple algorithm to implement - uses a FIFO queue. </li></ul>
  38. 39. Disadvantages of FCFS <ul><li>-A process that does not perform any I/O will monopolize the processor </li></ul><ul><li>-Favors CPU-bound processes </li></ul><ul><ul><li>I/O-bound processes have to wait until CPU-bound process completes </li></ul></ul><ul><ul><li>They may have to wait even when their I/O are completed (poor device utilization) </li></ul></ul><ul><ul><li>We could have kept the I/O devices busy by giving a bit more priority to I/O bound processes </li></ul></ul>
  39. 40. <ul><li>Selection function : same as FCFS </li></ul><ul><li>Decision mode : preemptive </li></ul><ul><ul><li>a process is allowed to run until the time slice period (quantum, typically from 10 to 100 ms) has expired </li></ul></ul><ul><ul><li>then a clock interrupt occurs and the running process is put on the ready queue </li></ul></ul>Round-Robin
  40. 41. Round Robin <ul><li>Preemptive. </li></ul><ul><li>Used extensively in interactive systems because it’s easy to implement. </li></ul><ul><li>Isn’t based on job characteristics but on a predetermined slice of time that’s given to each job. </li></ul><ul><ul><li>Ensures CPU is equally shared among all active processes and isn’t monopolized by any one job. </li></ul></ul><ul><li>Time slice is called a time quantum </li></ul><ul><ul><li>size crucial to system performance (100 ms to 1-2 secs) </li></ul></ul>
  41. 42. Round-Robin
  42. 43. Quantum <ul><li>Quantum is a specific time interval used to prevent any one process monopolizing the system. </li></ul><ul><li>If the process does not voluntarily release the CPU when the interval/quantum is over, a clock interrupt is generated. </li></ul>
  43. 44. Shortest Process Next (SPN) <ul><li>Selection function: the process with the shortest expected CPU burst time </li></ul><ul><li>Decision mode: non-preemptive </li></ul><ul><li>I/O bound processes will be picked first </li></ul><ul><li>We need to estimate the required processing time (CPU burst time) for each process </li></ul>
  44. 45. Shortest Job Next (SJN) <ul><li>Non-preemptive. </li></ul><ul><li>Handles jobs based on length of their CPU cycle time. </li></ul><ul><ul><li>Use lengths to schedule process with shortest time. </li></ul></ul><ul><li>Optimal – gives minimum average waiting time for a given set of processes. </li></ul><ul><ul><li>optimal only when all of jobs are available at same time and the CPU estimates are available and accurate. </li></ul></ul><ul><li>Doesn’t work in interactive systems (time-sharing systems) because users don’t estimate in advance CPU time required to run their jobs. </li></ul>
  45. 46. Shortest Remaining Time (SRT) <ul><li>Preemptive - version of the SJN algorithm. </li></ul><ul><li>Processor allocated to job closest to completion. </li></ul><ul><ul><li>This job can be preempted if a newer job in READY queue has a “time to completion” that's shorter. </li></ul></ul><ul><li>Can’t be implemented in interactive system - requires advance knowledge of CPU time required to finish each job. </li></ul><ul><li>SRT involves more overhead than SJN. </li></ul><ul><ul><li>OS monitors CPU time for all jobs in READY queue and performs “context switching”. </li></ul></ul>
  46. 47. 7.4 I/O Management <ul><li>I/O Operation and Interrupt </li></ul><ul><li>Every request from a user program must be done through the OS. </li></ul><ul><li>When the device is ready to provide service, the device tells the operating system of its status by giving an interrupt. </li></ul><ul><li>I/O interrupts happen when: </li></ul><ul><ul><ul><ul><li>an I/O operation completes, </li></ul></ul></ul></ul><ul><ul><ul><ul><li>an I/O error occurs, or </li></ul></ul></ul></ul><ul><ul><ul><ul><li>a device is made ready. </li></ul></ul></ul></ul>
  47. 48. <ul><li>When an interrupt happens, operating system does the following: </li></ul><ul><ul><ul><ul><li>The operating system gains control. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The operating system saves the state of the interrupted process. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The operating system analyzes the interrupt and passes the control to the appropriate routine to handle interrupt. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The interrupt handler routine processes the interrupt. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The state of the interrupted process is restored. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The interrupted process executes. </li></ul></ul></ul></ul>
  48. 49. Spooling <ul><li>Spooling uses buffer to manage files to be printed. </li></ul><ul><li>Files which are spooled are queued and copied to printer one at a time. </li></ul><ul><li>To manage I/O requests, operating system has a component that is called spooler . </li></ul><ul><li>Spooler manages I/O requests to a printer. Spooler operates in the background and creates a printing schedule. </li></ul>
  49. 50. Importance of Spooling <ul><li>1. In spooling, programs can run to completion faster. Therefore, other programs can start sooner. Spooling improves the system by disassociating a program from the slow operating speed of devices such as printers. </li></ul><ul><li>2. Since files are stored in a buffer, where the printer can access them; we can perform other operations on the computer while the printing takes place. </li></ul><ul><li>Therefore, computation of one job can overlap with the I/O of other jobs. Thus, spooling can keep both the CPU and the I/O devices working at much higher performance rates. </li></ul><ul><li>3. Spooling lets us put a number of print jobs in queue instead of waiting for each one to finish before specifying the next one. If we need to remove unwanted jobs before the jobs print, we are able to do so. We can also suspend a printing job if the printing job is still on queue. </li></ul>
  50. 51. Discussion <ul><li>What are main services provided by an operating system? </li></ul><ul><li>What are some advantages of paging? </li></ul><ul><li>Distinguish swapping and paging. </li></ul><ul><li>What potential CPU-allocation problems exist if a purely round-robin (no-priority) system is used to select the next job from the ready queue? </li></ul><ul><li>What is the main difference of a time-sharing system and how is it usually implemented? </li></ul>
  51. 52. Discussion <ul><li>Five jobs are in the READY queue waiting to be processed. Their estimated CPU cycles are as follows: 10, 3, 6, 6 and 2. Using SJN, in what order should they be processed to minimize average waiting time? </li></ul>
  52. 53. Discussion <ul><li>Given the following information: </li></ul><ul><li>Draw a time line for each of the following scheduling algorithms: </li></ul><ul><ul><li>FCFS </li></ul></ul><ul><ul><li>SJN </li></ul></ul><ul><ul><li>SRT </li></ul></ul><ul><ul><li>Round-Robin (using a time quantum of 2) </li></ul></ul>