Introduction to computer science chapter 10 operating systems
1 / 28

Introduction to Computer Science - PowerPoint PPT Presentation

  • Updated On :

Introduction to Computer Science Chapter 10. Operating Systems. Lynn Choi Korea University. What is an Operating System?. A program that acts as an intermediary between the user and the computer hardware. Provides a virtual machine that is easier to program than the raw hardware

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Introduction to Computer Science ' - Melvin

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Introduction to computer science chapter 10 operating systems l.jpg

Introduction to Computer ScienceChapter 10. Operating Systems

Lynn Choi

Korea University

What is an operating system l.jpg
What is an Operating System?

  • A program that acts as an intermediary between the user and the computer hardware.

  • Provides a virtual machine that is easier to program than the raw hardware


    Operating System


  • Provide an environment in which a user can execute programs in a convenient and efficient manner

  • What if you don’t have an operating system?

    • Source code -> compiler -> object code -> hardware

    • How do you get object code onto the hardware?

    • How do you print out the answer?

    • How do you interface HDD and open a file?

Virtual Machine Interface

Physical Machine Interface

Os functions l.jpg
OS Functions

  • OS has two general functions:

    • Standard services

      • Provide standard services that everyone needs

        • Manages computer hardware

      • Provides easy of use for applications/users

      • Examples: standard IO libraries, window systems

    • Coordinator

      • Allows multiple applications/users to work together in efficient and fair ways

        • Resource sharing and efficient use of resources

        • Prevent errors and improper user of the computer by controlling the execution of user programs

      • Examples: concurrency, memory protection, share IO devices

Operating system from different viewpoints l.jpg
Operating System from Different Viewpoints

  • User’s view

    • PC’s operating system

      • Designed mostly for easy of use, and partly for performance

      • Not much attention to resource utilization

    • Mainframe or minicomputer’s operating system

      • Multiple users are sharing the same computer through terminals

    • Designed primarily to maximize resource utilization

  • Workstations and servers

    • Users have dedicated resources but they also share resources such as networking, servers, print servers etc.

  • Designed to compromise individual usability and resource utilization

  • Handheld devices

    • Designed to provide a user-friendly interface, and performance/energy

  • System’s view

    • Resource allocator – manages and allocates resources

      • With numerous conflicting requests, OS must decide how to allocate them to specific user/program

    • Control program – controls the execution of user programs and operations of I/O devices to prevent errors and improper user of the computer

  • Process concept l.jpg
    Process Concept

    • Process

      • Informally, a process is a program in execution

      • A system includes a collection of processes: user processes and system processes

      • A process generally includes (or represented by)

        • PC (program counter)

        • CPU Registers

        • Text section

        • Data section (static data, stack, heap)

    • Process versus program

      • Program

        • Passive entity – an executable file stored on disk

        • Becomes a process when the executable file is loaded into memory

      • Process

        • Active entity – program in execution with a program counter specifying the next instruction to execute

      • Two processes may be associated with the same program

        • Several Internet Explorer processes

        • Although text sections are equivalent, the PC, registers, and the data sections vary

    Process in memory l.jpg
    Process in Memory

    MIPS Memory Map

    Process state l.jpg
    Process State

    • As a process executes, it changes state

      • New: The process is being created

      • Running: Instructions are being executed

      • Waiting: The process is waiting for some event to occur

      • Ready: The process is waiting to be assigned to a processor

      • Terminated: The process has finished execution

        • These names may vary across operating systems.

    Process control block pcb l.jpg
    Process Control Block (PCB)

    • Each process is represented in the operating system by a process control block (PCB), which consists of the following information.

      • Process state – new, running, ready, waiting, etc.

      • Program counter – the address of the next instruction to be executed

      • CPU registers

        • General purpose registers, stack pointers, index registers, condition codes etc.

      • CPU scheduling information

        • Process priority, pointers to scheduling queues, and other scheduling parameters

      • Memory-management information

        • Base address of page tables

      • Accounting information

        • The amount of CPU time used, time limits, account numbers, etc.

      • I/O status information

        • The list of IO devices allocated, a list of open files, etc.

    Context switch l.jpg
    Context Switch

    • When CPU switches to another process,

      • The system must save the state of the old process (called context save), and

      • Load the saved state for the new process (called context restore)

    • Context switching occurs

      • As time slice expires (as a result of CPU scheduling)

      • Exceptions (fault, trap, abort), External interrupts

      • System calls (user mode to system mode and vice versa)

    Process scheduling l.jpg
    Process Scheduling

    • Process execution alternates sequences of CPU and IO bursts

    • Process scheduling

      • Select one from the ready processes and allocates the CPU

      • Can improve CPU utilization, throughput, response time, etc.

    • CPU scheduling decisions may take place when a process:

      • Switches from running to waiting state (i.e. I/O request)

      • Switches from running to ready state (i.e. interrupt)

      • Switches from waiting to ready (i.e. completion of I/O)

      • Terminates

    Process scheduling13 l.jpg
    Process Scheduling

    • Nonpreemptive scheduling

      • The currently executing process gives up the CPU voluntarily

    • Preemptive scheduling

      • The operating system decides to favor another process, preempting the currently executing process

    • Scheduling Criteria

      • CPU utilization – keep the CPU as busy as possible

      • Throughput – # of processes completed per time unit

      • Turnaround time – the amount of time to execute a particular process

      • Waiting time – the amount of time a process has been waiting in the ready queue

      • Response time – the amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)

        • It is more important to minimize the variance in the response time than to minimize the average response time

      • Maximize CPU utilization/Throughput, minimize turnaround time/waiting time/response time

    Cpu scheduling algorithms l.jpg
    CPU Scheduling Algorithms

    First-Come, First-Served (FCFS or FIFO)

    Processes are moved to the CPU in the order in which they arrive in the running state

    Shortest Job Next

    Process with shortest estimated running time in the ready state is moved into the running state first

    Round Robin

    Each process runs for a specified time slice and moves from the running state to the ready state to await its next turn if not finished

    First come first served l.jpg
    First-Come, First-Served

    Assuming the processes

    all arrived at the same

    time, what is the

    average turn-

    around time?

    What is the average

    waiting time?

    Shortest job next l.jpg
    Shortest Job Next

    What is the

    average turn-

    around time?

    What is the

    average waiting


    Round robin l.jpg
    Round Robin

    Every process is treated the same!

    Time slice (quantum)

    The amount of time each process receives before being preempted and returned to the ready state to allow another process its turn

    Round robin18 l.jpg
    Round Robin

    Suppose the time slice is 50

    • Every process is treated the same!

    • Time slice (quantum)

    • The amount of time each process receives before being preempted and returned to the ready state to allow another process its turn

    What is the average

    turnaround time?

    We cannot judge one algorithm is better than the other based on one example

    Virtual vs physical address l.jpg
    Virtual vs. Physical Address

    • Virtual address (also referred as logical address)

      • An address generated by the CPU

      • An address seen by the programmer

        • When a program is compiled, a reference to a variable is assigned a logical address.

      • Virtual address space: the set of all virtual addresses generated by a program

        • If you use 32bit virtual address, the maximum size of virtual address space is 4GB

    • Physical address

      • The address of main memory (physical memory) and caches

      • Physical address space: the set of all physical addresses

        • It is the size of physical memory you have in your PC.

        • The maximum size of physical address space is determined by the size of physical address.

    • Address binding

      • The mapping of a virtual address to a physical address

        • When the program is loaded into memory, each logical address is mapped to a specific physical address.

    Memory management l.jpg
    Memory Management

    • The main memory must accommodate both the operating system and various user processes

      • The OS must allocate parts of the main memory to OS and other processes in an efficient way

      • Two approaches

        • Contiguous allocation versus noncontiguous allocation

    • With contiguous memory allocation

      • Each process is contained in a single contiguous section of memory

      • Main memory is usually divided into two partitions:

        • Resident operating system

        • User processes

    • Memory mapping and protection

      • Relocation register + limit register can be used to protect user processes from each other, and from changing operating-system code and data

        • Relocation register contains value of smallest physical address

        • Limit register contains the range of logical addresses

    Contiguous allocation l.jpg
    Contiguous Allocation

    • Multiple-partition method

      • Fixed size partitions

        • Divide memory into several fixed-sized partitions

          • Each partition may contain exactly one process

      • Variable size partitions

        • Divide memory into several variable size partitions

    • Hole – a contiguous block of free memory

      • When a process arrives, it is allocated memory from a hole large enough to accommodate it





    process 5

    process 5

    process 5

    process 5

    process 9

    process 9

    process 8


    process 2

    process 2

    process 2

    process 2

    Dynamic storage allocation problem l.jpg
    Dynamic Storage-Allocation Problem

    • First-fit: Allocate the first hole that is big enough

    • Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole.

    • Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole.

    How to satisfy a request of size n from a list of free holes

    First-fit and best-fit generally performs better than worst-fit in terms of speed and storage utilization!

    Fragmentation l.jpg

    • External Fragmentation – There is enough total memory space to satisfy a request, but the available spaces are not contiguous

      • Occurs if variable size partitions (i.e. segmentation) are used

      • Can reduce external fragmentation by compaction

        • Shuffle memory contents to place all free memory together in one large block

    • Internal Fragmentation – The allocated memory may be slightly larger than requested memory; this size difference is internal to a partition, but is not being used

      • Occurs if fixed size partitions (i.e. paging) are used

    Paging l.jpg

    • Noncontiguous allocation

      • The virtual address space of a process can be noncontiguous in the physical address space

      • Two approaches

        • Paging: divide virtual address space into fixed size partitions called pages

        • Segmentation: divide virtual address space into variable size partitions called segments

    • Paging

      • Divide virtual memory into blocks of same size called (virtual) pages

      • Divide physical memory into fixed-sized blocks called (physical) page frames

        • Page size is between 512B ~ 16MB

      • To run a program of size n pages, need to find n free frames

    • Frame table

      • OS needs to keep track of free and allocated page frames

    • Page table

      • OS needs to keep track of virtual to physical address mappings for each process

    Paging27 l.jpg

    • Fragmentation

      • Internal fragmentation – on average, one half page per process

      • No external fragmentation

    • Page size

      • Small page – decrease internal fragmentation

      • Large page – decrease the number of entries in the page table

        • Generally page sizes have grown over time as processes and main memory become larger

    • Paging clearly separates user’s view of memory from the actual physical memory

      • Each virtual address generated by the CPU is translated to a physical address by hardware (MMU or TLB) and operating system (page table)

      • This mapping is hidden from the user and controlled by the operating system

      • Protection: each user process has no way of addressing memory outside of its address space

        • Its page table includes only the pages that the process owns

    Paging28 l.jpg

    • Demand paging

      • Bring in a page on a page miss

    • Page table entry (PTE) contains

      • Virtual page number, Physical page frame number (translation)

      • Valid bit (valid entry or not)

      • Presence bit (memory or disk)

      • Reference bits (used for page replacement)

      • Dirty bit (write back to disk or not)

      • Access control: read/write/execute (protection)

      • Privilege level (protection)

      • Other page attributes: cacheable, etc.