cse asg 2 amritpal singh f1004 a31

Embed Size (px)

Citation preview

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    1/18

    LOVELY PROFESSIONAL UNIVERSITY

    MODEL HOME WORK: #2

    Course Code: CSE102 Course Title: Exposure to Computer

    Disciplines

    School: LIE Department:

    CSE/IT

    Name of the faculty member: ISHA SHARMA

    Class: B.Tech 1st yr Term: Spring S

    Batch: 2010-2014

    Max. Marks: 5 Date of Allotment:

    Date of Submission: 21-02-2011

    Submitted by:-Amritpal Singh Regd. No:-

    11005181

    Section :- F1004 Roll no:-A-31

    Part (A)

    Q1 Taking an example, show how loaders and

    linkers are integral part for execution of a program.

    ANS:-

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    2/18

    About Loader:-(role and use of

    loader)As we know before a source program can be executed it must first be

    transformed into machine language and then loaded into main memory, if it is

    not already there. Since the process of loading a translated program into

    memory is logically distinct from the translation of that program, separate

    software modules, called loaders, have been developed to accomplish theloading operation. There are two types of loaders: binary loaders, and relocating

    loaders. Each type of loader can be distinguished by the functions it performs

    and by the characteristics of the inputs that it processes.

    A Loader is a system program that performs the following functions:-

    System program that performs the loading function.

    Allocate space in memory for the program (allocation).

    Resolve symbolic references between object programs (linking).

    Adjust all address dependent locations, such as address constraints, to

    correspond to the allocated space (relocation).

    Physically place the machine instruction and data into memory (loading) for

    execution.

    It brings object program into memory and starts its execution

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    3/18

    Reads executable files header to determine size of text and data segments

    Creates new address space for program large enough to hold text and data

    segments, along with a stack segment

    Copies instructions and data from executable file into the new address space

    (this may be anywhere in memory)

    About Linker:-(Role and use of linkers)

    The linking of subprograms together to form a composite program is of great value

    in the modular development of software. To place the linking function in

    perspective, let us view Figure 1 as a function of time. Source program coding must

    be performed first, translation second, loading third, and execution fourth. Linking,

    however, could be carried out at seven different times, namely: 1) at source

    program coding time ; 2) after coding but before translation time; 3) at translation

    time; 4) after translation but before loading time; 5) at loading time; 6) after loadingbut before execution time; or 7) at execution time.

    Linker (or linkage editor): System program that performs the linking operations(i.e.

    linking and relocation).

    It merges the object files produced by separate compilation or assembly andcreates an executable file.Produce a linked version of the program ( called loadmodule, executable image, or image program).

    Solve external reference and library search, and perform relocation of all sections

    relative to the start of the linked program.

    Although all linking has been performed, information concerning external reference

    is retained in the linked program for further re-linking if necessary

    Example:-

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    4/18

    It is a 2 step process:-

    Linking: Combining a set of programs, including library routines, to create a

    loadable image

    a) Resolving symbols defined within the set

    b) Listing symbols needing to be resolved by loader

    Loading: Copying the loadable image into memory, connecting it with any

    other programs already loaded, and updating addresses as needed

    a) (In Unix) interpreting file to initialize the process address space

    b) (in all systems) kernel image is special (own format)

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    5/18

    Q2. How the state transition diagram

    changed if the wait/blocked state is broken

    into two states.

    Process life cycle:-

    With single-programming, right after a process is born the system starts

    executing its corresponding programs instruction.

    The instruction execution continues until the process needs to read some

    data from an input device or wants to write some results on an output device.

    There are special purpose processors called Input/Output (I/O) processors for

    transferring data from input devices to main memory and from main memory

    to output devices.

    It is understandable that such a processor will perform the specific task better

    than a general-purpose processor, i.e., CPU.

    While an I/O operation is in progress, the CPU has to wait and do nothing.

    After the I/O operation is completed, the CPU will resume the execution of the

    instructions.

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    6/18

    This cycle, of going through process states of running and input/output,

    may be repeated over and over, until the job is completed or, for some

    reason, the process is aborted.

    The life cycle of a process in a single-programming environment is shown in

    Figure below

    Change of path in wait/block condition:-

    The life cycle of a process in multiprogramming is not the same as

    singleprogramming.

    A process may be ready to use the CPU to run its program while the CPU isrunning another program.

    The basic states are thus Ready, Running, and Wait/Blocked. Wait refers to a

    state in which the process is waiting for a device or an event and Blocked is

    for the case the process is waiting for its I/O to be completed by an I/O

    processor.

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    7/18

    Q3 What command will you use to Displaysthe user who invoked the command?

    Ans:-

    The command that we will use in linux to know about the user

    who invoked the command in terminal will be:- logname

    Q4. Why Modern OS are interrupt driven ?

    Give an example.

    Modern OSs are interrupt driven because for the need of:

    Buffering and spooling required I/O interrupts

    Multiprogramming required artificial interrupts (traps) to switch from user to

    supervisor .

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    8/18

    Why Interrupt?

    Interrupt helps in :-

    Hardware protection:When we have single user any error occur to the system then we coulddetermined that this error must be caused by the user program ,but when webegin to dealing with spooling ,multiprogramming, and sharing disk to holdmanyusers data this sharing both improved utilization and increase problems .In multiprogramming system, where one erroneous program might modify

    theprogram or data of another program, or even the resident monitor itself. MSDOSand the Macintosh OS both allow this kind of error.A properly designed operating system must ensure that an incorrect (ormalicious) program cannot cause other program to execute incorrectly.Many programming error are detected by the hardware these error arenormallyhandled by the operating system.

    DualMode Operation:To ensure proper operation, we must protect the operating system and all

    otherprograms and their data from any malfunctioning program.The approach taken by many operating systems provides hardware supportthatallows us to differentiate among various modes of execution

    I/O Operation Protection:

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    9/18

    A use program may disrupt the normal operation of the system by issuingillegalI/O instruction we can use various mechanisms to ensure that suchdisruption cannot take place in the system.

    One of them is by defining all I/O instructions to be privileged instructions.Thususers cannot issue I/O instructions directly they must do it through theoperatingsystem, by execute a system call to request that the operating systemperformingI/O in its behalf. The operating system, executing in monitor mode, checkthat therequest is valid, and (if the request is valid) does the I/O requested. Theoperatingsystem then returns to the user.

    Memory Protection:To insure correct operation, we must protect the interrupt vector andinterruptservice routine from modification by a user program. This protection must beprovided by the hardware, we need the ability to determine the range oflegaladdresses that the program may access, and to protect the memory outsidethat

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    10/18

    space. We could provided the protection by using two registers a baseregisterand limit registerBase register hold the smallest legal physical memoryaddress.Limit register: contains the size of the range.

    This protection is accomplished by the CPU hardware comparing everyaddressgenerated in user mode with the registers. Any attempt by a programexecuting inuser mode to access monitor memory or other users memory results in atrap tothe monitor, which treats the attempts as a fatal error.

    CPU Protection:In addition to protecting I/O and memory we must insure that the operatingsystem maintains control. We must prevent the user from getting stuck in aninfinite loop or not calling system services, and never returning control to theoperating system. To accomplish this goal, we can use a timer.Timer can be set to interrupt the computer after a specified period. Theperiodmay be fixed (for example, 1/60 second) or variable (for example, from 1millisecond to 1 second) A variable timer is generally implemented by a fixedrate

    clock and a counter.We can use the timer to prevent a user program from running too longSimpletechnique is to initialize a counter with the mount of time that a program isallowed to run.Amore common use of timer is to implement time sharing. In the most case,the

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    11/18

    timer could be set to interrupt every N millisecond, where N is the time slicethateach user is allowed to execute before the next user get control of the CPU.Theoperating system is invoked to perform housekeeping tasks.

    Eg:-While a process reading a disk file, can we do...{. . .Reading a file ( ) ;while ( ! done_writing ){let_CPU_wait ( ) ;/ / or . . .Let_CPU_to_others ( ) ;}operate_on_the_file ( ) ;. . .

    }

    Stages of interrupt:-

    Trap (exception):it is a softwaregenerated interrupt caused either by an error

    (eg: division by zero or invalid memory access) or by a specific request from a user

    program that an operating system service be performed.

    Interrupt vector : it is a fixed locations (an array) in the low memory area (first

    100 locations of RAM) of operating system when the interrupt occur the CPU

    stops what its doing and transfer execution to a fixed location contain starting

    address of the interrupt service routine(ISR), on completion the CPU resumes the

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    12/18

    interrupted computation.

    Interrupt Service Routine: is it a routine provided to be responsible for dealing

    with the interrupt.

    Q5. Why we have a transition from theRunning state to the Ready state in the state

    transition diagrams.Explain the answer with

    the help of diagrams.

    For Creating an Executable Program we have to go through these

    processes:-

    Process

    Process a program in execution.

    Process execution must progress in sequential fashion.

    A process is more than a program code - It includes 3 segments:

    Program: code/text.

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    13/18

    Data: program variables.

    Stack: for procedure calls and parameter passing.

    Process States A process can be in one of many possible states:

    new: The process is being created but has not been admitted to the pool of

    executable processes by the operating system.

    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.

    Process Transitions

    As a process executes, it changes its state

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    14/18

    The above figure indicates the types of events that lead to

    each state for a process; the possible transitions are asfollows:

    o Null New: A new process is created to execute a

    program. This event occurs for any of the following

    reasons:

    An interactive logon to the system by a user

    Created by OS to provide a service on behalf of a

    user program

    Spawn by existing program

    The OS is prepared to take on a new batch job

    o New Ready: The OS moves a new process to a ready

    state when it is prepared to take on additional process

    (Most systems set some limit on the number of existing

    processes)

    o Ready Running: OS chooses one of the processes in the

    ready state and assigns CPU to it.

    o Running Terminated: The process is terminated by the

    OS if it has completed or aborted.

    o Running Ready: The most common reason for this

    transition are:

    The running process has expired his time slot.

    The running process gets interrupted because a

    higher priority process is in the ready state.

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    15/18

    o Running Waiting (Blocked): A process is put to this state

    if it requests for some thing for which it must wait:

    A service that the OS is not ready to perform.

    An access to a resource not yet available.

    Initiates I/O and must wait for the result.

    Waiting for a process to provide input.

    o Waiting Ready: A process from a waiting state is moved

    to a ready state when the event for which it has been

    waiting occurs.

    o Ready terminated: Not shown on the diagram. In some

    systems, a parent may terminate a child process at any

    time. Also, when a parent terminates, all child processes

    are terminated.

    o Blocked terminated: Not shown. This transition occurs

    for the reasons given above.

    Another state, Suspend, can also be included in the model.The operating system may move a process from a blocked

    state to suspend state by temporarily taking them out of

    memory.

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    16/18

    Q6 As a networking engineer while settingup a nework, which factors you will take into

    account to decide for network to be a LAN,

    MAN or WAN?

    ANS:- What is LAN , MAN , WAN.

    A LAN (local area network) is a group of computers and network devices connected

    together, usually within the same building. By definition, the connections must be highspeed and relatively inexpensive (e.g., token ring or Ethernet). Most Indian Universitydepartments are on LANs.

    A MAN (metropolitan area network) is a larger network that usually spans severalbuildings in the same city or town. The IUB network is an example of a MAN.

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    17/18

    A WAN (wide area network), in comparison to a MAN, is not restricted to a geographicallocation, although it might be confined within the bounds of a state or country. A WANconnects several LANs, and may be limited to an enterprise (a corporation or anorganization) or accessible to the public. The technology is high speed and relativelyexpensive. The Internet is an example of a worldwide public WAN.

    To decide b/w what to choose we have to obey the following parameters:

    Parameter LAN WAN MAN

    Area Covered Covers small area Covers large areaCovers Larger than LAN, smallerthan WAN

    Error Rates Lowest Highest Moderate

    TransmissionSpeed

    High Speed Low speed Moderate Speed

    Equipment Cost Uses Inexpensiveequipment

    Most Expensiveequipment

    Uses moderately expensiveequipment

    The type of Network area connection that you choose for usage depends upon the

    scope of your needs. It also depends on the areas you want to cover and the

    number of computers you want to connect. To some extent it also depends on who

    is going to own the network.

    A LAN is used when you want to establish a network on a small scale. This is usually

    done in case for houses and small businesses which are operated inside a single

    building. LANs are usually operated and administered by a single person.

    WANs are used when the computers to be connected span on large areas which are

    far away from each other. A WAN has several owners and administrators.

    A MAN is used to connect computers located in the same city or area and are

    usually under the control of the government.

  • 8/7/2019 cse asg 2 amritpal singh f1004 a31

    18/18