Operating Systems Theory c1

Embed Size (px)

Citation preview

  • 8/3/2019 Operating Systems Theory c1

    1/39

    OPERATING SYSTEMSTHEORY

    LECTURE NOTES

    Chapter 1OPERATING SYSTEMS OVERVIEW

  • 8/3/2019 Operating Systems Theory c1

    2/39

    TEXT BOOK

    Operating Systems Theory

    by Dr G O Ofori-Dwumfuo

    Adwinsah Publications, 2007

  • 8/3/2019 Operating Systems Theory c1

    3/39

    Other Literature

    Any good operating systems book

    Internet

    Etc.

  • 8/3/2019 Operating Systems Theory c1

    4/39

    OPERATING SYSTEM OVERVIEW

    Computer systems provide for gathering

    data, performing computations, storing

    information, communicating with other

    computer systems, and generating outputreports. Some of those are implemented in

    hardware, others in software.

    An operating system is the software thatmanages hardware resources, provides

    services for accessing those resources, such

    as creation of files, directories, processes,

    etc.

  • 8/3/2019 Operating Systems Theory c1

    5/39

    Without OS, Computers are just machines

    ApplicationPackages

    Operating

    System

    BIOS

    Software

  • 8/3/2019 Operating Systems Theory c1

    6/39

    A typical computer system (Fig 1.1):

    The hardware does all the actual work and includes thememory, the central processing unit (CPU), and theinput and output (I/O) devices.

    The OS provides a set of services to programs.

    The user interacts with the operating system indirectly,through the programs.

    Systems programs are a set of utility programs suppliedwith an operating system to provide basic services forusers. Eg. window manager for a graphical user

    interface, a command interpreter, and programs torename, copy or delete files.

    Application programs provide the computer with thefunctionality the users require. Eg. tax preparationsoftware, a financial planner, a word processor,

    spreadsheet.

  • 8/3/2019 Operating Systems Theory c1

    7/39

    CPU Organization

    The CPU is the heart and brain of a computer system.

    It contains a number of special-purpose registers, an

    arithmetic logic unit (ALU), and the control unit / logic

    necessary to decode and execute instructions

    Connected to the CPU by way of a communication

    bus are the memory and the I/O devices.

    The operation of the CPU is controlled by the

    instructions the CPU fetches from memory.

    The I/O devices, in turn, are commanded by the CPU.

  • 8/3/2019 Operating Systems Theory c1

    8/39

    CPU operations

    The operation of a CPU can be

    described in terms of a simple loop

    Each time through the loop one

    instruction is executed.

    This basic process by which instructions

    are executed never varies.

    It is called the Fetch-and-execute

    operation

  • 8/3/2019 Operating Systems Theory c1

    9/39

    Fetch and execute operations

    An instruction is fetched from the memory location specifiedby program counter. (All instructions are fetched frommain memory.)

    The instruction is placed in a special register called the

    instruction register. The program counter is incremented so it points to the nextinstruction to be executed.

    The instruction is decoded to determine what action is to beperformed. The action is specified by the instructions op-

    code (operation code) bits. Depending on the operation to be performed, the value of

    one or more operands is fetched from memory.

    The operation specified in the op-code is performed (seebelow).

    If required, a value is stored back into main memory.

  • 8/3/2019 Operating Systems Theory c1

    10/39

    Op-code operations

    Movement: Move a value from one location to another(registers or memory locations).

    Computation: Send one or more operand values to theALU and have a computation performed.

    Conditional Branch: If the branch condition is true, reset

    the program counter to point to the branch address. Procedure Call: Save the current value of the program

    counter. Then reset the program counter to point to thebeginning of a procedure. At the end of the procedure, abranch instruction specifying the saved program counterwill allow the program to return to the current point ofexecution. (The saved program counter may be stored ina register, in memory, or on the stack.)

    Input/Output: Transfer information concerning an input oroutput operation between the CPU and the I/O device.

  • 8/3/2019 Operating Systems Theory c1

    11/39

    Traps and Interrupts

    These are events that disrupt thenormal sequence of instructionsexecuted by the CPU

    A trap is an abnormal conditiondetected by the CPU that indicates anerror; e.g. dividing by zero,

    trying to access a memory location that doesnot exist or for which the program does nothave access,

    executing an instruction with an undefined op-code, or

    trying to access a nonexistent I/O device.

  • 8/3/2019 Operating Systems Theory c1

    12/39

    Traps and Interrupts

    An interrupt is a signal sent to the CPUby an external device, typically an I/Odevice; to stop its current activities and

    attend to the interrupting devicesneeds, eg, to perform a read operation.

    (A CPU will, however, check interruptsonly after it has completed theprocessing of one instruction and beforeit fetches another.)

  • 8/3/2019 Operating Systems Theory c1

    13/39

    Traps and Interrupts.

    The CPU responds to traps and interrupts by

    saving the current value of the program

    counter and resetting the program counter to

    a new address. The CPU then returns to executing at the

    point the trap or interrupt occurred, after it has

    handled the trap or interrupt.

    Information saved when a trap or interrupt

    occurs is stored in a special register

    (program status word, PSW register).

  • 8/3/2019 Operating Systems Theory c1

    14/39

    Traps and Interrupts..

    One difference between trap & interrupts:

    traps are said to be synchronous and

    interrupts are asynchronous.

    Given the same machine state and input

    data, a trap will occur at the same point

    of execution each time the program runs.

    The occurrence of an interrupt, however,

    depends on the relative timing between

    the interrupting device and the CPU.

  • 8/3/2019 Operating Systems Theory c1

    15/39

    Multimode Execution

    To provide an OS with privileges not granted to

    application programs, the hardware must support

    multiple modes of execution. Two modes of execution

    are usually supported: supervisor(orkernel) mode

    and user mode. A system can enter kernel mode from user mode in

    one of three ways.

    Supervisor call or a system call (A special

    instruction call - similar to a procedure call exceptthat it sets the systems state to kernel mode.

    Traps

    Interrupts

  • 8/3/2019 Operating Systems Theory c1

    16/39

    Objectives of Operating Systems

    To hide details of hardware by creating

    abstraction An abstraction is software that hides the lower

    level details and provides a set of higher-levelfunctions

    To allocate resources to processes

    Provide a pleasant and effective userinterface

  • 8/3/2019 Operating Systems Theory c1

    17/39

    Operating System Structure

    The OS provides applications with a virtual machine.

    The OS supervisor calls expand the instruction set

    provided by the raw hardware by supporting

    processes, file systems, etc. In addition, the OS manages the underlying

    hardware resources. Applications cannot access I/O

    devices or execute privileged instructions directly.

    The OS performs these tasks on their behalf. In doing so, the OS attempts to efficiently utilize the

    resources available to it and protect the integrity of

    the applications that must share those resources.

  • 8/3/2019 Operating Systems Theory c1

    18/39

    Operating System Structure.

    The tasks performed by an operating system

    can be divided into four major areas.

    Process Management

    Memory Management

    File System Management

    Device Management

  • 8/3/2019 Operating Systems Theory c1

    19/39

    Process Management

    A process is an executing program.

    Associated with a process are its code, itsdata, a set of resources allocated to it, and

    one or more flows of execution through itscode.

    The OS provides supervisor calls formanaging processes and must manage the

    allocation of resources to processes. If multiple processes can exist

    simultaneously, the OS must provide eachprocess with an appropriate virtual

    environment in which to run

  • 8/3/2019 Operating Systems Theory c1

    20/39

    Process Management

    Five major activities of an operating system in

    regard to process management are:

    Creation and deletion of user and system

    processes. Suspension and resumption of processes.

    A mechanism for process synchronization.

    A mechanism for process communication.A mechanism for deadlock handling.

  • 8/3/2019 Operating Systems Theory c1

    21/39

    Memory Management

    At a minimum, memory must be shared

    by an application program and the OS.

    On more sophisticated systems,

    memory can be shared by a number of

    processes.

    The OS must manage the allocation of

    memory to processes and control the

    hardware that determines which

    memory locations a process may

    access.

  • 8/3/2019 Operating Systems Theory c1

    22/39

    Memory Management

    The major activities of an operating system in

    regard to memory-management are:

    Keep track of which part of memory are

    currently being used and by whom. Decide which processes are loaded into

    memory when memory space becomes

    available.

    Allocate and de-allocate memory space as

    needed.

  • 8/3/2019 Operating Systems Theory c1

    23/39

    File System Management

    Computers process information. That

    information must be transmitted, processed,

    and stored.

    A file system object is an abstract entity forstoring or transmitting a collection of

    information.

    The file system is an organized collection of

    file system objects.

    The OS must provide primitives to manipulate

    those objects

  • 8/3/2019 Operating Systems Theory c1

    24/39

    File System Management

    The five main major activities of an operating

    system in regard to file management are:

    The creation and deletion of files.

    The creation and deletion of directories. The support of primitives for manipulating

    files and directories.

    The mapping of files onto secondary storage.

    The back-up of files on stable storage media.

  • 8/3/2019 Operating Systems Theory c1

    25/39

    Device Management

    A computer communicates information

    through its input and output devices.

    Processes access those devices

    through the OS supervisor calls

    provided for that purpose.

    The OS attempts to manage those

    devices in a manner that allows them to

    be efficiently shared among the

    processes requiring them

  • 8/3/2019 Operating Systems Theory c1

    26/39

    Operating System Services

    The following services are provided by OS to

    the convenience of the users:

    Program Execution

    I/O Operations File System Manipulation

    Inter-process communication

    Error Detection

  • 8/3/2019 Operating Systems Theory c1

    27/39

    Operating System Types

    Batch systems

    Multiprogrammed batch systems

    Time-shared systemsNetwork operating systems

    Real-time operating systems

    Distributed operating systems

  • 8/3/2019 Operating Systems Theory c1

    28/39

    Batch systems

    Earlier, computer input, both programs and data,was prepared on input media; paper tape orpunch cards

    Users would hand these in to an operator andreturn later to pick up the outputs. The operatorwould assemble similar jobs into batches andrun the batches through the computer. Each jobhad total control of the machine until it

    terminated.A batch OS manages a machine run in this

    manner. It provides virtually no functionalitysince there are no complications of sharing

    resources with multiple processes.

  • 8/3/2019 Operating Systems Theory c1

    29/39

    Multiprogrammed batch systems

    On multiprogrammed batch systems,

    jobs are read into a job pool stored on a

    disk.

    When one job is unable to execute

    because it is waiting for an I/O operation

    to complete, another job may be allowed

    to run.This sharing of computer resources by

    concurrently executing processes greatly

    increases operating system complexity.

  • 8/3/2019 Operating Systems Theory c1

    30/39

    Time-shared systems

    Time-shared OS allow for interaction between userand process.

    In batch systems, all data is supplied at the time theprogram is input. This may be fine for a program that

    takes payroll information and prints weekly paycheques.

    But for programs that must interact with the user, theOS must allow programs to respond to user inputs in areasonable amount of time.

    The OS must not only share resources among thevarious processes, but it must create the illusion thatprocesses are running simultaneously.

    It does this by shifting execution rapidly among all the

    active processes.

  • 8/3/2019 Operating Systems Theory c1

    31/39

    Networkoperating systems

    Increasingly, computers exist not as

    stand-alone entities but as part of a

    network of computers.

    Network communications involve

    complex protocols

    For the reliability of the network, support

    for those protocols is built into network

    operating systems.

  • 8/3/2019 Operating Systems Theory c1

    32/39

    Real-time operating systems

    A real-time OS is designed for execution oftasks within specific time constraints.

    Normally, users want the computer systems

    to execute their programs as soon aspossible, but no exact timing is required.

    In real-time systems, the correctness of aprocessing task is dependent on the time at

    which the processing occurred. Eg, a real-time system sensing loss of coolant

    to a nuclear reactor may be required to initiatea backup system within a fraction of a

    second.

  • 8/3/2019 Operating Systems Theory c1

    33/39

    Real-time operating systems.

    In a real-time environment, the OS must

    guarantee that the task can be

    executed within a specified time

    constraint.

    Use of real-time systems is most limited

    to dedicated applications such as

    industrial control systems, weaponsystems and computer-controlled

    products.

  • 8/3/2019 Operating Systems Theory c1

    34/39

    Real-time operating systems.

    Desirable features in a time-shared system,

    (resource sharing and management of I/O

    devices by the operating system) are

    detriments in a real-time system. Minimization of delays in the completion of

    tasks discourages resource sharing and

    encourages low-level access to hardware.

    For this reason, the design of general-

    purpose OS is much different from the design

    of real-time systems.

  • 8/3/2019 Operating Systems Theory c1

    35/39

    Distributed operating systems

    With a network OS, the resources on each

    machine on the network are managed by

    that machines OS. OS support facilitates

    communications among the machines.With a distributed operating system, the

    OS on all the machines work together to

    manage the collective network resources.A single collective distributed OS manages

    the network resources provided by each

    network computer or node.

  • 8/3/2019 Operating Systems Theory c1

    36/39

    The Booting Process

    When power is first supplied to a computer system, aprogram in read-only memory (ROM) executes.

    After performing some diagnostic checks, a stage-0boot program is executed. The program checks for the

    presence of one or more boot devices, eg, floppy disk,a CD-ROM or hard disk.

    Once found, the stage-0 program reads the first sector(called boot sector) from the boot device into mainmemory. This boot sectorshould contain a stage-1

    boot program. There is however, no guarantee. If the boot sector has never been initialized, undefined

    values will be copied into memory. Before transferringcontrol to the next stage in the boot process, the currentboot program will check

  • 8/3/2019 Operating Systems Theory c1

    37/39

    The Booting Process..

    On some systems, the stage-1 boot program then

    reads in the OS.

    On others, a series of bootstrap programs must

    be copied into memory and executed. In either case, the OS eventually gets copied into

    memory and the final boot program branches to

    the OSs initialization entry point.

    On a hard disk PC, the boot sector also contains apartition table which contains the starting and

    ending location of partitions. One partition is

    defined as active.

  • 8/3/2019 Operating Systems Theory c1

    38/39

    The Booting Process..

    At the end of the boot process, the OS has been

    loaded into memory and the boot program has

    branched to the OS.

    The machine is now executing in kernel mode. Data

    structures not set when the operating system wasloaded, system registers and devices are all initialized

    as needed.

    Once the OS is ready to service processes, it creates

    any processes that provide OS services. Once the system is switched into user mode, the OS

    has completed its boot responsibilities and the system

    is running.

  • 8/3/2019 Operating Systems Theory c1

    39/39

    The Booting Process over ..

    The operating system is now

    running and the computer

    system is now ready for use.