os module i

Upload: kalaraiju

Post on 08-Aug-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/22/2019 OS Module I

    1/25

    MODULE I

    Introduction: Operating System Batch, Multiprogrammed, Time-sharing and

    Real timesystemsOperating system structureOperating system operations

    System Structures: Operating system serviceSystem callsSystem Programs

    SystemstructureSimple structure, Layered approachKernel, Shell.

    Introduction: Operating System

    What is an Operating System?

    A program that acts as an intermediary between a user of a computer and the

    computer hardware.

    Operating system goals: Execute user programs and make solving user problems easier. Make the computer system convenient to use. Use the computer hardware in an efficient manner.

    Computer System Components

    A computer system can be divided roughly into four components: the hardware,

    the operating system, the application programs, and the users.

    Hardware provides basic computing resources (CPU, memory, I/Odevices).

    Operating systemcontrols and coordinates the use of the hardware amongthe various application programs for the various users.

    Applications programsdefine the ways in which the system resources areused to solve the computing problems of the users (compilers, database

    systems, video games, business programs).

    Users (people, machines, other computers).

  • 8/22/2019 OS Module I

    2/25

    Abstract view of the components of a computer system

    Operating systems from two viewpoints: that of the user and that of the system.

    User View

    The user's view of the computer varies according to the interface being used.

    Most computer users sit in front of a PC, consisting of a monitor, keyboard, mouse,

    and system unit. Such a system is designed for one user to monopolize its

    resources. The goal is to maximize the work (or play) that the user is performing.

    In this case, the operating system is designed mostly for ease of use, with someattention paid to performance and none paid to resource utilizationhow various

    hardware and software resources are shared.

    System View

    From the computer's point of view, the operating system is the program most

    intimately involved with the hardware. In this context, we can view an operating

    system as a resource allocator.A computer system has many resources that may be

    required to solve a problem: CPU time, memory space, file-storage space, I/O

    devices, and so on. The operating system acts as the manager of these resources.

    Facing numerous and possibly conflicting requests for resources, the operating

    system must decide how to allocate them to specific programs and users so that it

    can operate the computer system efficiently and fairly.

  • 8/22/2019 OS Module I

    3/25

    Evolution of Operating Systems

    Early Systems (1950)

    Mainframe Computer Systems were the first computers used to tackle

    many commercial and scientific applications.

    Simple Batch Systems (1960)

    Batch jobs together with similar needs and run them through the computer asgroup.

    Batch processing generally requires the program, data and appropriatesystem commands to be submitted together in the form of job.

    Batch operating systems usually allow little or no interaction between theusers and the executing programs.

    Scheduling in batch system is very simple. Jobs are typically processed inthe order of submission that is in first-come, first - served.

    Memory management in batch systems is also very simple. Memory isusually divided into two areas.

    In this execution environment, the CPU is often idle, because the speeds ofthe mechanical I/O devices are intrinsically slower than are those of the

    electronic devices.

    Memory Layout for a Simple Batch System

  • 8/22/2019 OS Module I

    4/25

    Multiprogrammed Batch Systems (1970)

    Multiprogramming needed for efficiency. The O.S. picks and begins to execute one job from memory. Once this job

    needs an I/O operation the O.S. switches to another job (CPU or O.S. alwaysbusy).

    The number of jobs in memory is less than the number of jobs in disk (JobPool).

    If several jobs are ready to be brought into memory and there is not enoughroom for all of them, then the system chooses jobs among them (Job

    Scheduling).

    If several jobs are ready to run at the same time, the system must chooseamong them (CPU Scheduling).

    Having several programs in memory at the same time requires memorymanagement.

    In non-multiprogrammed system, CPU sits idle. In multiprogramming system, CPU will never be idle.

    Memory Layout for a multiprogramming System

    Timesharing

    Timesharing (Interactive Computing) is logical extension in which CPUswitches jobs so frequently that users can interact with each job while it is

    running, creating interactive computing.

  • 8/22/2019 OS Module I

    5/25

    Processors time is shared among multiple usersResponse time should be < 1 second

    Each user has at least one program executing in memory process

    If processes dont fit in memory, swapping moves them in and out to

    runVirtual memory allows execution of processes not completely in

    memory

    In time-sharing systems, several jobs must be kept simultaneously inmemory (job scheduling techniqueRound Robin method), the system must

    have memory management and protection. To obtain reasonable response

    time virtual memoryconcept is used.

    To ensure orderly execution, the system must provide mechanisms for jobsynchronization and communication, and it may ensure that the job do notget stuck in a deadlock.

    Real Time Systems

    Note that not all Operating Systems are general-purpose systems. Real-Time (RT) systems are dedicated systems that need to adhere to

    deadlines , i.e., time constraints

    Real time computing may be defined as that type of computing inwhich the correctness of the system depends not only on the logical result ofthe computation but also on the time at which results are produced.

    A hard realtime Hard real-time system must meet its deadline. Conflicts with time-sharing systems, not supported by general-

    purpose OSs.

    Often used as a control device in a dedicated application: Industrial control

    Robotics Secondary storage limited or absent, data/program is stored in

    short term memory, or Read-Only Memory (ROM).

    Virtual memory is absent (Time Sharing). Also called as special purpose OS

  • 8/22/2019 OS Module I

    6/25

    A soft realtime Deadlines desirable but not mandatory. Limited utility in industrial control or robotics. Useful in modern applications (multimedia, video conference,

    virtual reality) requiring advanced operating-system features

    Multiprocessor Systems (1980)

    System with several CPUs in close communication: processors share memory and a clock. communication usually takes place through the shared memory.

    Also known as parallel systems, tightly-coupled systems. Multiprocessors systems growing in use and importance advantages

    include: Increased throughput Economy of scale- Increased reliabilitygraceful degradation or fault tolerance

    Multiprocessor Architecture

  • 8/22/2019 OS Module I

    7/25

    Multiprogramming vs. Multiprocessing

    Types of Multiprocessor Systems

    Asymmetric Multiprocessing master processor schedules and allocates work to slave processors.

    Symmetric Multiprocessing (SMP) Each processor runs an identical copy of the operating system. Typically each processor does self-scheduling form the pool of

    available process.

    - Most modern operating systems support SMP.Symmetric Multiprocessing (SMP)

    Each processor can perform the same functions and share same mainmemory and I/O facilities (symmetric).

    The OS schedule processes/threads across all the processors (realparallelism).

    Existence of multiple processors is transparent to the user. Incremental growth: just add another CPU. Robustness: a single CPU failure does not halt the system, only the

    performance is reduced.

  • 8/22/2019 OS Module I

    8/25

    Networked/Distributed Systems (1980)

    Networked Systems

    Distribute resources and the computation among several physical processors. Loosely coupled system:

    each processor has its own local memory. processors communicate with one another through various

    communications lines.

    Advantages: Resources Sharing Computation speed upload sharing Reliability

    Node1

    Node2

    network

    . . .

    Node3 node n

    Distributed Systems

    Distributed system is collection of loosely coupled processorsinterconnected by a communications network.

  • 8/22/2019 OS Module I

    9/25

    Processors variously called nodes, computers, machines, hosts. Reasons for distributed systems:

    Resource sharing: sharing and printing files at remote sites. processing information in a distributed database. using remote specialized hardware devices.

    Computation speedupload sharing. Reliability detect and recover from site failure, function transfer,

    reintegrate failed site.

    Communicationmessage passing.Client-Server Systems

    Dumb terminals supplanted by smart PCs. Many systems are now servers, responding to requests generated by clients-Computer-server provides an interface

    to client to request services (i.e., database)

    File-server provides interface for clients to store and retrieve files.GeneralStructure of a Client-Server System

    Peer to Peer systems

    P2P does not distinguish clients and servers. Instead all nodes are considered peers. May each act as client, server or both. Node must join P2P network

  • 8/22/2019 OS Module I

    10/25

    Registers its service with central lookup service on network, or Broadcasts request for service and responds to requests for service via

    discovery protocol

    Web-based Systems (1990)

    Web has become ubiquitous. PCs most prevalent devices. More devices becoming networked to allow web access. New category of devices to manage

    Web traffic among similar servers:

    Load Balancers.

    Basis for Grids/Cloud Computing.

    Grid Computing Systems

    Collection of computer resources, usually owned by multiple parties and inmultiple locations, connected together such that users can share access totheir combined power:

    Can easily span a wide-area network

    Heterogeneous environment

    Crosses administrative/geographic boundaries Supports Virtual Organizations (VOs)

    Examples: EGEE - Enabling Grids for E-SciencE (Europe), Open ScienceGrid (USA).

    Cloud Computing Systems

    Collection of computer resources, usually owned by a single entity,connected together such that users can lease access to a share of theircombined power:

    Location independence: the user can access the desired service fromanywhere in the world, using any device with any (supported) system.

  • 8/22/2019 OS Module I

    11/25

    Cost-effectiveness: the whole infrastructure is owned by the providerand requires no capital outlay by the user.

    - Reliability: enhanced by way of multiple redundant sites, thoughoutages can occur, leaving users unable to remedy the situation

    Hand held Systems

    Handheld systems are also dedicated.

    - Personal Digital Assistants (PDAs).- Cellular telephones

    Issues:

    - Limited memory- Slow processors- Small display screens

    Operating system structure

    One of the most important aspect of OS is the ability to Multiprogramming

    Single user cannot keep CPU and I/O devices busy at all times One job selected and run via job scheduling When it has to wait (for I/O for example), OS switches to another job

    Memory Layout for Multiprogrammed System

  • 8/22/2019 OS Module I

    12/25

    Multiprogramming

    Jobs are stored in Job Pool Virtual memory is the useful technique for the limitation size of physical

    memory

    Operating system operations

    Interrupt (driven by hardware) vs.Trap (called by software or error)

    Trap example: divide by 0; invalid memory access

    We need to make sure that an error in a user program could cause problemsonly for the one program that was running (such as infinite loop) .

    Dual mode operation

    Dual-mode operation allows OS to protect itself and other systemcomponents

    It contains user mode (mode bit:1) and Kernel mode (mode bit:0) The operating system loaded user application starts in user mode. Whenever

    a trap or interrupt occurs, hardware switches to kernel mode.

    Transition from user to kernel mode

  • 8/22/2019 OS Module I

    13/25

    Privileged instructions: some machine instructions that may cause harm, canonly be executed in kernel mode.

    Such as instruction switch to user mode; I/O control; timer management, andinterrupt management.

    Timer

    To prevent the OS out of control by CPU

    Set interrupt after specific period Operating system decrements counter When counter zero generate an interrupt Set up before scheduling process to regain control or terminate program that

    exceeds allotted time

    System Structures: Operating system service

    One set of operating-system services provides functions that are helpfulto the user :

    User interface - Almost all operating systems have a user interface (UI)o Varies between Command-Line (CLI), Graphics User Interface

    (GUI), Batch

    Program execution - The system must be able to load a programintomemory and to run that program, end execution, either normally

    orabnormally (indicating error)

  • 8/22/2019 OS Module I

    14/25

    I/O operations - A running program may require I/O, which may involve afile or an I/O device.

    File-system manipulation - The file system is of particularinterest.Obviously, programs need to read and write files and directories,

    create and delete them, search them, list file Information, permission

    management

    Communications Processes may exchange information, on the samecomputer or between computers over a network

    o Communications may be via shared memory or through messagepassing (packets moved by the OS)

    Error detectionOS needs to be constantly aware of possible errorso May occur in the CPU and memory hardware, in I/O devices, in user

    programo For each type of error, OS should take the appropriate action toensure

    correct and consistent computing

    o Debugging facilities can greatly enhance the users and programmersabilities to efficiently use the system

    Another set of OS functions exists for ensuring the efficient operation of the

    system itself via resource sharing

    Resource allocation - When multiple users or multiple jobs runningconcurrently, resources must be allocated to each of them.

    o Many types of resources - Some (such as CPU cycles, mainmemory,and file storage) may have special allocation code, others

    (such asI/O devices) may have general request and release code.

    Accounting - To keep track of which users use how much and whatkinds ofcomputer resources

    Protection and security - The owners of information stored in a multiuseror networked computer system may want to control use of that information,concurrent processes should not interfere with each other

    o Protection involves ensuring that all access to system resources iscontrolled.

  • 8/22/2019 OS Module I

    15/25

    o Security of the system from outsiders requires userauthentication,extends to defending external I/O devices from invalid

    access attempts.

    o If a system is to be protected and secure, precautions must beinstituted throughout it. A chain is only as strong as its weakest link.

    System Calls

    Programming interface to the services provided by the OS. Typically written in a high-level language (C or C++). Mostly accessed by programs via a high-level Application Program Interface

    (API) rather than direct system call use.

    Three most common APIs are Win32 API for Windows, POSIX API forPOSIX-based systems (including virtually all versions of UNIX, Linux, and

    Mac OS X), and Java API for the Java virtual machine (JVM).

    Example of System Calls

    System call sequence to copy the contents of one file to another file.

  • 8/22/2019 OS Module I

    16/25

    Example of Standard API

    Consider the ReadFile() function in the

    Win32 APIa function for reading from a file

    A description of the parameters passed to ReadFile()HANDLE filethe file to be read

    LPVOID buffera buffer where the data will be read into and written from

    DWORD bytesToReadthe number of bytes to be read into the buffer

    LPDWORD bytesReadthe number of bytes read during the last read

    LPOVERLAPPED ovlindicates if overlapped I/O is being used

    System Call Implementation

    Typically, a number associated with each system call.o System-call interface maintains a table indexed according to these

    numbers.

    The system call interface invokes intended system call in OS kernel andreturns status of the system call and any return values.

    The caller need know nothing about how the system call is implemented.o Just needs to obey API and understand what OS will do as a result callo Most details of OS interface hidden from programmer by API .

  • 8/22/2019 OS Module I

    17/25

    Managed by run-time support library (set of functions built intolibraries included with compiler.

    API System Call OS Relationship

    System Call Parameter Passing

    Often, more information is required than simply identity of desired systemcall.

    o Exact type and amount of information vary according to OS and call. Three general methods used to pass parameters to the OS.

    o Simplest: pass the parameters in registers. In some cases, may be more parameters than registers.

    o Parameters stored in a block, or table, in memory, and address ofblock passed as a parameter in a register .

    This approach taken by Linux and Solaris.o Parameters placed, or pushed, onto the stack by the program and

    popped off the stack by the operating system.

  • 8/22/2019 OS Module I

    18/25

    o Block and stack methods do not limit the number or length ofparameters being passed.

    Parameter Passing via Table

    Types of System Calls

    Process control File management Device management Information maintenance Communications

    Process Control

    end, abort load, execute create process, terminate process get process attributes, set process attributes wait time wait event, signal event allocate and free memory

  • 8/22/2019 OS Module I

    19/25

    File Management

    Common systems calls dealing with files and directories:

    create file, delete file

    open, close read, write, reposition get file attributes, set file attributes

    Device Management

    Similarity between files and I/O devices results in similar device system calls

    (some OS even merges two into a combined filedevice structure):

    request device, release device read, write, reposition get device attributes, set device attributes logically attach or detach devices

    Information Maintanence

    System calls for transferring information between the user program and OS:

    get time or date, set time or date get system data, set system data get process, file, or device attributes set process, file or device attributes

    Communication

    System calls for transferring information between the user program and OS:

    create, delete communication connection send, receive message transfer status information attach or detach remote devices

  • 8/22/2019 OS Module I

    20/25

    System Programs

    System programs provide a convenient environment for programdevelopment and execution. The can be divided into:

    o File manipulationo Status informationo File modificationo Programming language supporto Program loading and executiono Communicationso Application programs

    Most usersview of the operation system is defined by system programs, notthe actual system calls.

    Provide a convenient environment for program development and execution.o Some of them are simply user interfaces to system calls; others are

    considerably more complex.

    File management -Create, delete, copy, rename, print, dump, list, andgenerally manipulate files and directories.

    Status information.o Some ask the system for info -date, time, amount of available

    memory, disk space, number of users.o Others provide detailed performance, logging, and debugging

    information.

    o Typically, these programs format and print the output to the terminalor other output devices.

    o Some systems implement a registry -used to store and retrieveconfiguration nformation.

    File modificationo Text editors to create and modify fileso Special commands to search contents of files or perform

    transformations of the text.

    Programming-language support -Compilers, assemblers, debuggers andinterpreters sometimes provided.

  • 8/22/2019 OS Module I

    21/25

    Program loading and execution-Absolute loaders, relocatableloaders, linkageeditors, and overlay-loaders, debugging systems for higher-level and

    machine language.

    Communications -Provide the mechanism for creating virtual connectionsamong processes, users, and computer systems.

    o Allow users to send messages to one anothers screens, browse webpages, send electronic-mail messages, log in remotely, transfer files

    from one machine to another.

    System structureSimple structure

    MS-DOSwritten to provide the most functionality in the least space.o Not divided into modules

    Although MS-DOS has some structure, its interfaces and levels offunctionality are not well separated.

    MS DOS Layer Structure

  • 8/22/2019 OS Module I

    22/25

    Layered Approach

    The operating system is divided into a number of layers (levels), each builton top of lower layers. The bottom layer (layer 0), is the hardware; thehighest (layer N) is the user interface.

    With modularity, layers are selected such that each uses functions(operations) and services of only lower-level layers.

    Layered Operating System

    UNIX

    UNIXlimited by hardware functionality, the original UNIX operatingsystem had limited structuring. The UNIX OS consists of two separable

    parts.

    o Systems programso The kernel

    Consists of everything below the system-call interface andabove the physical hardware.

  • 8/22/2019 OS Module I

    23/25

    Provides the file system, CPU scheduling, memorymanagement, and other operating-system functions; a large

    number of functions for one level.

    UNIX System Structure

    Microkernel System Structure

    Moves as much from the kernel into userspace. Communication takes place between user modules using message passing. Benefits:

    o Easier to extend a microkernelo Easier to port the operating system to new architectureso More reliable (less code is running in kernel mode)o More secure

    Detriments:o Performance overhead of user space to kernel space communication.

  • 8/22/2019 OS Module I

    24/25

    Mac OS X Structure

    Modules

    Most modern operating systems implement kernel modules.o Uses object-oriented approacho Each core component is separateo Each talks to the others over known interfaceso Each is loadable as needed within the kernel

    Overall, similar to layers but with more flexible.Solaris Modular Approach

  • 8/22/2019 OS Module I

    25/25

    Reference:

    1.Operating System Principles-Abham Silberschatz