Ch 2. Structure of OS

download Ch 2. Structure of OS

of 46

Transcript of Ch 2. Structure of OS

  • 8/7/2019 Ch 2. Structure of OS

    1/46

    07/06/2011

    Chapter 2: Structure of OS

  • 8/7/2019 Ch 2. Structure of OS

    2/46

    Lecture 1

    y Layered view of OS

    y System Components

    2MGR

  • 8/7/2019 Ch 2. Structure of OS

    3/46

    Structure of Operating System:

    Application Programs

    System Programs

    System Components(OS)

    HARDWARE

    3MGR

  • 8/7/2019 Ch 2. Structure of OS

    4/46

    Layered Operating System

    MGR4

  • 8/7/2019 Ch 2. Structure of OS

    5/46

    Structure of Operating System (Contd)

    y The structure of OS consists of 4 layers:

    1. Hardware

    Hardware consists of CPU,Main memory, I/ODevices, etc,

    2. System Components(Operating System)

    Software includes process management routines,memory management routines, I/O controlroutines, file management routines.

    5MGR

  • 8/7/2019 Ch 2. Structure of OS

    6/46

    Structure of Operating System (Contd)

    3. System programs

    This layer consists of compilers, Assemblers, linker

    etc.

    4. Application programs

    This is dependent on users need.

    E.g.Railway reservation system, Bank database

    management etc.,

    6MGR

  • 8/7/2019 Ch 2. Structure of OS

    7/46

    System components......

    PROCESS MANAGEMENTyA process is a program in execution: (A program is passive, a

    process active.)E.g.Word processing program run by an user

    yA process has resources (CPU time, files, memory) andattributes that must be managed.

    yApart from resources, a process may require variousinitialization data.

    E.g. User process compiler requires a file to compile &

    appropriate system calls.y When the process terminates the OS will reclaim any

    reusable resources.

    7MGR

  • 8/7/2019 Ch 2. Structure of OS

    8/46

    PROCESS MANAGEMENT

    yManagement of processes includes:

    y Process Scheduling (priority, time management, . . . )

    y Creation/termination

    y Block/Unblock (suspension/resumption )y Synchronization

    y Communication

    y Deadlock handling

    y

    Debugging

    8MGR

  • 8/7/2019 Ch 2. Structure of OS

    9/46

    MAIN MEMORY MANAGEMENT

    For a program to be executed, it must be mapped to absolute addresses

    and loaded into memory.

    To improve both the utilization of the CPU and speed of the computers

    response to its users, we must keep several programs in main memory.

    Hence, proper memory management schemes are required.

    Memory management activities by OS

    yAllocation/de-allocation for processes, files, I/O.

    yM

    aintenance of several processes at a timeyKeep track of who's using what memory

    yMovement of process memory to/from secondary storage.

    System components......

    9MGR

  • 8/7/2019 Ch 2. Structure of OS

    10/46

    FILE MANAGEMENT

    y A file is a collection of related information defined by its creator.

    Commonly, files represent programs (both source and object

    forms) and data.

    y The operating system is responsible for t

    he following activities inconnections with file management:

    File creation and deletion.

    Directory creation and deletion.

    Support of primitives for manipulating files and directories. Mapping files onto secondary storage.

    File backup on stable (nonvolatile) storage media.

    System components......

    10MGR

  • 8/7/2019 Ch 2. Structure of OS

    11/46

    I/O MANAGEMENT

    y Buffer caching system

    yGeneric device driver code

    y Drivers for each device - translate read/write requests intodisk position commands.

    SECONDARY STORAGE MANAGEMENTy Disks, tapes, optical, ...

    y Free space management ( paging/swapping )

    y Storage allocation ( what data goes where on disk )

    y Disk scheduling

    System components......

    11MGR

  • 8/7/2019 Ch 2. Structure of OS

    12/46

    NETWORKING

    y Communication system between distributed processors.

    yGetting information about files/processes/etc. on a remote

    machine.

    y Can use either a message passing or a shared memory model.

    PROTECTION

    y Of files, memory, CPU, etc.

    yM

    eans controlling of accessy Depends on the attributes of the file and user

    System components......

    12MGR

  • 8/7/2019 Ch 2. Structure of OS

    13/46

    SYSTEM PROGRAMS

    y Command Interpreters -- Program that accepts control

    statements (shell,GUI interface, etc.)

    y Compilers/linkersy Communications (FTP,TELNET,etc)

    13MGR

  • 8/7/2019 Ch 2. Structure of OS

    14/46

    Lecture 2

    MGR

    14

    y Shell

    y Kernel

    y System calls

    y System programsy Virtual machines

    y Java virtual machines

    11/02/2011

  • 8/7/2019 Ch 2. Structure of OS

    15/46

    Shell or Command interpreter

    MGR

    15

    y

    A shell is a piece of software that provides an interface forusers of an operating system which provides access to the

    services of a kernel.

  • 8/7/2019 Ch 2. Structure of OS

    16/46

    MGR

    16

    y OS shells generally fall into one of two categories:- Command-line shells provide a command-line interface (CLI)

    to the operating system.

    E.g. Unix

    - Graphical shells provide a graphical user interface (GUI)

    E.g.Windows

    Shell.

  • 8/7/2019 Ch 2. Structure of OS

    17/46

    Kernel

    MGR

    17

    y The kernel is the essential centre of a computer operating system,

    the core that provides basic services for all other parts of the

    operating system.

    y A kernel includes,

    - An interrupt handler that handles all requests or completed

    I/O operations

    - a scheduler that determines which programs share the kernel's

    processing time in what order, and a supervisor that actually

    gives use of the computer to each process when it is scheduled.-A kernel may also include a manager of the operating system's

    address spaces in memory or storage, sharing these among all

    components and other users of the kernel's services.

  • 8/7/2019 Ch 2. Structure of OS

    18/46

    System Calls

    MGR

    18

    y System calls provide interface between a process & the operatingsystem.

    y System calls can be made either in assembly or high levellanguage.

    y A collection of system calls is sometimes referred to as anapplication program interface (API).

    y Three most common APIs are Win32API for Windows, POSIXAPI for POSIX-based systems (including virtually all versions of

    UNIX, Linux, and Mac OS X), and Java API for the Java virtualmachine (JVM)

  • 8/7/2019 Ch 2. Structure of OS

    19/46

    System calls..

    MGR

    19

  • 8/7/2019 Ch 2. Structure of OS

    20/46

    Example of System Calls

    MGR20

    y System call sequence to copy the contents of one file to another file(Command line

    interface)

  • 8/7/2019 Ch 2. Structure of OS

    21/46

    File copy example..

    MGR

    21

    y The file copy operation makesheavy use of OS (system

    calls).

    y Most users never see this level of details.

    y The run time support system (set of libraries includedwith a compiler) for most programming languages

    provides a much simpler interface.

  • 8/7/2019 Ch 2. Structure of OS

    22/46

    Example..

    MGR

    22

    C++ file copy program: filecopy.cpp

    #include

    #include

    void main()

    {

    ifstream infile(D:input.txt);

    ofstream outfile(D:output.txt);char ch;

    //continue reading file until EOF is reached

    while(infile){

    infile.get(ch);outfile.put(ch);

    }

    }

  • 8/7/2019 Ch 2. Structure of OS

    23/46

    Standard Library functions Vs system calls

    MGR

    23

    y Standard library functions are built on top of system calls. For

    example, the malloc() in C and related functions are built on

    top of the mmap() system call(LINUX).This means that

    greater control over the computers resources can be obtained

    through system calls.

    y Standard library functions tend to be more standardized than

    system calls. since system calls provide direct access to the

    kernel, different O/Ss will have at least slightly different

    system calls.

  • 8/7/2019 Ch 2. Structure of OS

    24/46

  • 8/7/2019 Ch 2. Structure of OS

    25/46

    Passing parameters to operating system

    MGR

    25

    y 3 methods

    1. Parameters in registers.

    2. For more parameters, block of memory is used. Address

    of the memory block where parameters are stored is

    passed as parameter in a register. (LINUX)

  • 8/7/2019 Ch 2. Structure of OS

    26/46

    MGR

    26

    3. Parameters can be placed or pushed onto the stack by the

    program and popped off the stack by the operating system.

    y

    Some operating systems prefer the block or stack met

    hods,

    because those approaches do not limit the number or length of

    parameters being passed.

    Passing parameters to operating system

  • 8/7/2019 Ch 2. Structure of OS

    27/46

  • 8/7/2019 Ch 2. Structure of OS

    28/46

    API System Call OS Relationship

    MGR

    28

  • 8/7/2019 Ch 2. Structure of OS

    29/46

    Standard C Library Example

    MGR

    29

    y C program invoking printf() library call, which calls write()system call

  • 8/7/2019 Ch 2. Structure of OS

    30/46

    MGR30

    There are 11 (or more) steps in making the system call

    read (fd, buffer, nbytes)

    Linux system call

  • 8/7/2019 Ch 2. Structure of OS

    31/46

    Types of System Calls

    MGR31

    y Process control

    y File management

    y Device management

    yInformation maintenance

    y Communications

  • 8/7/2019 Ch 2. Structure of OS

    32/46

    System programs

    MGR32

    y

    System programs provide a convenient environment for programdevelopment and execution.

    y They are divided into these categories:

    1. File management:These programs create, delete, copy, rename,

    print, list and generally manipulate files and directories.

  • 8/7/2019 Ch 2. Structure of OS

    33/46

    System Programs

    MGR33

    2. Status information: Some programs simply ask the system for the

    data, amount of available memory or disk space, number of users,

    etc..

    yThat information is then formatted and presented.

    3. File Modification: Several text editors may be available to createand modify the content of files stored on the disk.

    E.g.MS word, Notepad

  • 8/7/2019 Ch 2. Structure of OS

    34/46

    MGR34

    3. Programming language support: Compilers, assemblers and

    interpreters for common programming languages are often

    provided to user the OS.

    4. Program loading and execution:The system may provide

    absolute loaders, relocatable loaders, linkers, etc..

    5.Communications :Th

    ese programs allow users to send messagesto one anothers screens, to browse web pages, to send email ,

    etc

    E.g. Internet Explorer, windows mail

    y Most important system program for an operating system iscommand interpreter or shell.

    System Programs

  • 8/7/2019 Ch 2. Structure of OS

    35/46

    Simple Structure

    MGR35

    y MS-DOS written to provide the most functionality in the

    least space

    y Not divided into modules

    y AlthoughMS-DOS has some structure, its interfaces and levels

    of functionality are not well separated

  • 8/7/2019 Ch 2. Structure of OS

    36/46

    MS-DOS Layer Structure

    MGR36

  • 8/7/2019 Ch 2. Structure of OS

    37/46

    UNIX

    MGR37

    y UNIX limited by hardware functionality, the original

    UNIX operating system had limited structuring. The UNIX

    OS consists of two separable parts

    y Systems programs

    y The kernel

    y Consists of everything below the system-call interface and above the

    physical hardware

    y Provides the file system, CPU scheduling, memory management, and

    other operating-system functions; a large number of functions for one

    level

  • 8/7/2019 Ch 2. Structure of OS

    38/46

    UNIX System Structure

    MGR38

  • 8/7/2019 Ch 2. Structure of OS

    39/46

  • 8/7/2019 Ch 2. Structure of OS

    40/46

    Microkernel System Structure

    MGR

    40

    y Moves as much from the kernel into user space

    y Communication takes place between user modules usingmessage passing

    y Benefits:y Easier to extend a microkernel

    y Easier to port the operating system to new architectures

    y More reliable (less code is running in kernel mode)

    y More secure

    y Detriments:y Performance overhead of user space to kernel space

    communication

  • 8/7/2019 Ch 2. Structure of OS

    41/46

    Virtual Machines

    MGR41

    y In a Virtual Machine - each process "seems" to execute on its

    own processor with its own memory, devices, etc.

    y A virtual machine provides an interface identicalto the

    underlying bare hardware

    y The operating system creates the illusion of multiple processes,

    each executing on its own processor with its own (virtual)

    memory

  • 8/7/2019 Ch 2. Structure of OS

    42/46

    Virtual Machines (Contd)

    MGR42

    y The resources of the physical computer are shared to create thevirtual machinesy CPU scheduling can create the appearance that users have their

    own processor

    y Spooling and a file system can provide virtual card readers andvirtual line printers

    y A normal user time-sharing terminal serves as the virtual machineoperators console

    y The virtual-mac

    hine concept provides complete protection of systemresources since each virtual machine is isolated from all other virtual

    machines. This isolation, however, permits no direct sharing ofresources.

  • 8/7/2019 Ch 2. Structure of OS

    43/46

    Virtual Machines (Cont.)

    MGR43

    (a) Nonvirtual machine (b) virtual machine

    Non-virtualM

    ach

    ine VirtualM

    achine

  • 8/7/2019 Ch 2. Structure of OS

    44/46

  • 8/7/2019 Ch 2. Structure of OS

    45/46

    JVM

    MGR45

    Verifier

  • 8/7/2019 Ch 2. Structure of OS

    46/46

    JVM

    MGR46

    The class loaderloads .class files from both the Java program

    and Java API for execution by the Java interpreter.

    The verifierchecks the class file is valid Java bytecode and

    does not overflow or underflow the stack.

    The JVMinterpreterthat interprets the bytecodes one at a time

    to turn the architecture neutral bytecodes into native

    machine language of the host computer.

    The JVMmakes it possible to develop programs that are

    architecture neutral and portable.

    The implementation of the JVM is specific for each system.