Top Banner

of 29

distsys_STUDENTMANUAL_9OCT

Apr 10, 2018

Download

Documents

Prateek Joshi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    1/29

    Distributed Operating systems

    (IT-703)

    Student Name:-PRATEEK JOSHI

    Enrollment No.:-0704IT071053

    Branch/Year/Semester:-IT/4TH/7TH

    Affiliated to Rajiv Gandhi Prodyogiki Vishwavidyalaya Bhopal

    (MP)

    MAHAKAL INSTITUTE OFTECHNOLOGY

    BEHIND AIR STRIP UJJAIN (MP)Approved By All India Council of Technical Education

    (New Delhi)

    DEPARTMENT OF

    INFORMATION TECHNOLOGY

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    2/29

    INDEX

    DISTRIBUTED OPERATING SYSTEMS (IT-703)

    S.NO NAME OF

    EXPERIMENT

    DATE

    OF

    PERFORMANCE

    DATE

    OF

    SUBMISSION

    REMARK

    1Case Study CORBA.

    2 Case Study on.Inventory Management

    3 Case Study on.Supply Chain

    Management

    4 Case Study on.Reservation System

    5 Case Study on.University Counseling

    6 Case Study on.

    Online Chain

    Management

    7 Implementation ofElection Algorithm.

    8 S/W Simulation forClock Synchronization in

    Distributed System using

    Lamports Algorithm.

    9 Implementation ofBankers Algorithm foravoiding Deadlock.

    10 Implementation ofDeadlock through

    Simulation.

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    3/29

    PROGRAM NO: - 1

    PROBLEM DEFINITION:

    Case study on CORBA and implement of RMI

    OBJECTIVE:

    Client and RMI Server Implementation and The RMI application comprises of the two separate

    programs, a server and a client. A typical server program creates some remote objects,

    makes references to these objects accessible, and waits for clients to invoke methods onthese objects. The RMI application provides the mechanism by which the server and the

    client communicate and pass information back and forth. The RMI distributed application

    uses the RMI Registry to obtain a reference to a remote object. The server calls the registryto associate a name with a remote object. The client looks up the remote object by its name

    in the servers registry and then invokes a method on it.

    CONTENT:

    a. Introduction

    b. Basic Interface

    c. CORBA architecture

    d. The object request broker

    e. IDL

    f. Java RMI

    g. Implement of RMI

    INPUT SET:

    In this section, you will learn how to send massage from RmiClient to the RmiServer. Here, we

    are going to create "ReceiveMessageInterface" interface. The interface defines the methods thatcan be invoked from the client. Essentially, the interface defines the client's view of the remote

    object. After that, we will create a class named "RMIServer". The RMI Server accepts tasks fromclients, runs the tasks, and returns any result. The server code consists of an interface and a

    class.

    In this class, the receiveMessage() method, which is called from the remote client, is defined.

    This class is the implementation of the RMI interface. The RmiServer creates the registry. This

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    4/29

    is a kind of directory. Its key is a name (which is the ID of a remote object) and its content is an

    object. This object is looked up from a remote program by the name. This registry is accessed

    from a remote object by the IP address or host name and the port number.

    createRegistry(): This is the method creates and exports a registry on the local host that accepts

    requests on the specified port.

    ReceiveMessageInterface.java

    import java.rmi.*;

    public interface ReceiveMessageInterface extends Remote{

    void receiveMessage(String x) throws RemoteException;

    }

    The above code defines the RMI interface. The receiveMessage() method is implemented in the

    server class.

    Here is the code ofRMI Server:

    import java.rmi.*;

    import java.rmi.registry.*;

    import java.rmi.server.*;

    import java.net.*;

    public class RmiServer extends

    java.rmi.server.UnicastRemoteObject implements ReceiveMessageInterface{

    String address;

    Registry registry;

    public void receiveMessage(String x) throws RemoteException{

    System.out.println(x);}

    public RmiServer() throws RemoteException{

    try{

    address = (InetAddress.getLocalHost()).toString();

    }

    catch(Exception e){

    System.out.println("can't get inet address.");

    }

    int port=3232;

    System.out.println("this address=" + address + ",port=" + port);

    try{

    registry = LocateRegistry.createRegistry(port);registry.rebind("rmiServer", this);

    }

    catch(RemoteException e){

    System.out.println("remote exception"+ e);

    }

    }

    static public void main(String args[]){

    try{

    RmiServer server = new RmiServer();

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    5/29

    }

    catch (Exception e){

    e.printStackTrace();

    System.exit(1);

    }

    }

    }

    The above class uses LocateRegistry class to create a remote object registry that accepts calls on

    a specific port.

    Output of the above program:

    C:\rose>javac RmiServer.javaC:\rose>java RmiServer

    this address=roseindi/192.168.10.104,port=3232t=

    _3232

    Here is the code ofRMI Client:

    import java.rmi.*;

    import java.rmi.registry.*;

    import java.net.*;

    public class RmiClient{

    static public void main(String args[]){

    ReceiveMessageInterface rmiServer;

    Registry registry;

    String serverAddress=args[0];String serverPort=args[1];

    String text=args[2];

    System.out.println

    ("sending " + text + " to " +serverAddress + ":" + serverPort);

    try{

    registry=LocateRegistry.getRegistry

    (serverAddress,(new Integer(serverPort)).intValue());

    rmiServer=(ReceiveMessageInterface)(registry.lookup("rmiServer"));

    // call the remote method

    rmiServer.receiveMessage(text);

    }

    catch(RemoteException e){

    e.printStackTrace();}

    catch(NotBoundException e){

    System.err.println(e);

    }

    }

    }

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    6/29

    lookup(): This is the method that returns a reference, a stub, for the remote object associated with

    the specified name.

    OUTPUT SET:

    C:\rose>java RmiClient 192.168.10.1043232 roseindia

    sending roseindia to 192.168.10.104:3232

    C:\rose>

    If the RMI client sends any type of massage then massage will be displayed on the RMI Server.

    C:\rose>java RmiServer

    this

    address=roseindi/192.168.10.104,port=3232roseindia

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:

    DATE:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    7/29

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    8/29

    PROGRAM NO: - 3

    PROBLEM DEFINITION:

    Case study on Supply chain Management

    OBJECTIVE:

    Case study on Supply chain Management

    CONTENT:

    a. Introduction

    b. Process Management

    c. Memory Management

    d. Communication

    e. Conclusion

    INPUT SET:

    OUTPUT SET:

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:DATE:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    9/29

    PROGRAM NO: - 4

    PROBLEM DEFINITION:

    Case study on Railway Reservation system

    OBJECTIVE:

    Case study on Railway Reservation system

    CONTENT:

    a. Introduction

    b. Process Management

    c. Memory Management

    d. Communication

    e. Conclusion

    INPUT SET:

    OUTPUT SET:

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:

    DATE:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    10/29

    PROGRAM NO: - 5

    PROBLEM DEFINITION:

    Case study on University Counseling.

    OBJECTIVE:

    Case study on University Counseling.

    CONTENT:

    a. Introduction

    b. Process Management

    c. Memory Management

    d. Communication

    e. Conclusion

    INPUT SET:

    OUTPUT SET:

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:

    DATE:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    11/29

    PROGRAM NO: - 6

    PROBLEM DEFINITION:

    Case study on Online Chain Management.

    OBJECTIVE:

    Case study on Online Chain Management.

    CONTENT:

    a. Introduction

    b. Process Management

    c. Memory Management

    d. Communication

    e. Conclusion

    INPUT SET:

    OUTPUT SET:

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:

    DATE:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    12/29

    PROGRAM NO: - 7

    PROBLEM DEFINITION:

    Implementation of Election Algorithms.

    OBJECTIVE:

    The Election Algorithm is a method in distributed computing for dynamically selecting a coordinator by

    process ID number.

    ALGORITHMS:

    Selects the process with the largest identifier as the coordinator:

    1. When a process p detects that the coordinator is not responding to requests, it initiates

    an election:

    a. p sends an election message to all processes with higher numbers.b. If nobody responds, then p wins and takes over.

    c. If one of the processes answers, then p's job is done.

    2. If a process receives an election message from a lower numbered process at any time, it:

    a. sends an OK message back.

    b. holds an election (unless its already holding one).

    3. A process announces its victory by sending all processes a message telling them that it isthe new coordinator.

    4. If a process that has been down recovers, it holds an election.

    Process 4 holds an election

    Processes 5 and 6 respond, telling 4 to stop

    Example:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    13/29

    At any moment, a process can get an ELECTION message from one of its lower-numbered colleagues. When such a message arrives, the receiver sends an OKmessage back to the

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    14/29

    Sender to indicate that he is alive and will take over. The receiver then holds anelection, unless it is already holding one. Eventually, all processes give up but one andthat one is the new coordinator. It announces it victory by sending all processes amessage telling them that starting immediately it is the new coordinator. If a processthat was previously down comes back up, it holds an election. If it happens to be the

    highest-numbered process currently running, it will win the election and take over theco-coordinators job. Thus the biggest guy in town always wins, hence the name bullyalgorithm. In the figure above we see an example of how the bully algorithm works. Thegroup consists of eight processes, numbered from 0 to 7. Previously process 7 was thecoordinator, but it has just crashed. Process 4 is the first one to notice this, so it sendsELECTION messages to all the processes higher than it, namely 5, 6, and 7, as shownin (a). Processes 5 and 6 both re-spond with OK, as shown in (b). Upon getting the firstof these responses, 4 know that its job is over. It knows that one of these bigwigs willtake over and become coordinator. It just sits back and waits to see who the winner willbe (although at this point it can make a pretty good guess). In (c), both 5 and 6 holdelections, each one only sending message to those processes higher than itself. In (d)

    process 6 tells 5 that it will take over. At this point 6 know that 7 is dead and that it (6) isthe winner. If there is state information to be collected from disk or elsewhere to pick upwhere the old coordinator left off, 6 must now do what is needed. When it is ready totake over, 6 announce this by sending a COORDINATOR message to all running proc-esses. When 4 gets this message, it can now continue with the operation it was trying todo when it discovered that 7 was dead, but using 6 as the coordinator this time. In thisway the failure of 7 is handled and the work can continue. If process 7 is ever restarted,it will just send all the others a COORDINATOR message and bully them intosubmission.

    INPUT SET:Bully election algorithm program

    import java.io.*;

    public class Bully {

    static class Message {

    String type; Participant candidate;Message (String t, Participant p){

    type=t; candidate=p;

    }}

    static class Participant extends Thread{

    MessageQueue inbox;MessageQueue[] neighbour;

    int value;

    Participant boss;

    Participant me;

    public void run(){

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    15/29

    boss=this; me=this;

    (new Thread(){public void run(){

    for(int i=0;iboss.value) boss=m.candidate;

    }

    }}catch(Exception e){}

    }

    }

    public static void main(String[] args) throws IOException {

    final int n = 9;

    final int [] value = {11,9,17,6,15,19,2,12,7};

    Participant[] part = new Participant[n];

    MessageQueue[] q = new MessageQueue[n];

    for(int i=0;i

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    16/29

    q[i]=new MessageQueue(10);

    }

    for(int i=0;i

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    17/29

    OUTPUT SET:

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:

    DATE:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    18/29

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    19/29

    0

    10

    20

    30

    40

    50

    60

    70

    80

    90

    100

    P1 p2 p3

    Three processes each with its own clock. The clock runs at different

    rates.

    At times 6, process P1 sends message m1 to processes p2. How long this message

    takes to arrived depends on clock you beloved In any events the clock in process

    p2 reads 16 when it arrives .if The message carries the starting time 6 in it if the

    message carries the starting time 6 in it process p2 will conclude that it took 10ticks to makes the journey .Now consider message m3.It leaves process p3 at 60

    and arrives. At P2 at 56.Similarly message m4 from p2 to p1 leaves at 64 and

    arrives at 54.these values are clearly impossible.

    0

    612

    18

    24

    30

    36

    42

    48

    54

    60

    08

    16

    24

    32

    40

    48

    56

    64

    72

    80

    M2

    M3

    M4

    M1

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    20/29

    Lamports Soln: - follows directly from the happens-before relation. Since m3 left

    at 60 it must arrive at 61 or later. Therefore, each message carries the sending time

    according to the senders clock. When a message arrives and the receivers Clock

    shows a value prior to the time the message was sent, the Receiver fast forwards its

    clock to be one more than the sending time. We see that m3 now arrives at 61.

    Similarly, m4 arrives at 70.

    P1 p2 p3

    0

    10

    20

    30

    40

    50

    6070

    80

    90

    100

    Consider the message as sent by the three processes shown in .Denote by Tsnd

    (mi) the logical time at which message mi was sent and likewise, by Trcv(mi) the

    time of its receipt. We known that for each message Tsnd (mi)

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    21/29

    P1 p2 p3

    0

    10

    20

    30

    40

    50

    60

    70

    80

    90

    100

    Concurrent Message transmission using logical clock.

    Vector Clocks:-

    A Vector clock VC (a) assigned to an events a has a property that if VC(a)

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    22/29

    The first property is maintained by incrementing VCi[i] at the occurrence of each

    new event that happens at process Pi. The Second property is maintained

    piggybacking vector along with Messages that are sent.

    1) Before executing an event (i.e. sending a message over the network, delivering a

    message to an application, or some other

    Internal event Pi executes VCi[i]-->VCi[i]+1.

    2) When process Pi sends a message m to Pj ,it sets ms (vector)

    Time stamp ts(m) equal to VCi.

    3) Upon the receipt of a message m, process Pj adjusts its own vector by setting

    VCj[k]max {VCj[k],ts(m)[K]} for each k

    After which it execute the first step and delivers the message

    To the application.

    INPUT SET:

    OUTPUT SET:

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:

    DATE:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    23/29

    PROGRAM NO: - 9

    PROBLEM DEFINITION:

    Implementation of Deadlock through Simulation.

    OBJECTIVE:

    To Understanding the Concept Deadlock through Simulator.

    ALGORITHME:Simulation modeling and analysis has long been a major tool in the operational analysisof manufacturing systems. A subtle and often problematic aspect of simulation that hasnot been adequately addressed is deadlocking. Currently available commercialsimulation systems provide no tools for detecting or resolving deadlocks. procedures todetect and resolve simulation deadlocks under conditions of single-unit resourcerequests, and provide implementation and computational experience with the MOR/DS(Curry et al. [4]) simulation package. Deadlock occurs in simulation systems due to thedynamic interaction of entities and resources in The course of the simulation. Use agraph formalism that represents this dynamic interaction to define deadlockcharacteristics in discrete simulation systems. The Procedure presented detects and

    resolves deadlocks under the condition that entities are restricted to single-unit resourcerequests. A distinction is made between self-resolvable and nonselfresolvabledeadlocks in simulation systems. Self-resolvable deadlocks are called transientDeadlocks, whereas non self-resolvable deadlocks are calledpermanent deadlocks there-introduction of additional resource units into the simulation can allow otherDeadlocked entities to use the freed resource and, consequently, relieve the blockagesituation in the simulation.

    Example 1. Consider a manufacturing process with a unit capacity machine (r2) thatrequires an operator (r1) for loading and unloading of jobs. Figure shows the evolutionof a simulation that leads to a deadlock. The simulation of the manufacturing process

    assumes that a part in control of either of the resources will not relinquish control of theresource it is holding until its request has been granted. In Figure 4a, job 1 (e1) hascontrol of the operator (r1) so that it can be loaded on the machine (r2), while job 2 (e2)is being processed on the machine. In Figure b, job 1 has requested the Machine ( r2),which creates a new edge from e1 to r2. In Figure c, job 2 has finished processing 6onthe machine and requests the operator to unload the machine. This event creates anedge from to e2 to r1. Since neither entity will relinquish the resource that it controls

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    24/29

    until its respective request has been granted, the simulation is deadlocked, and the twojobs will wait indefinitely.Furthermore, any other entities requesting either resource will also wait indefinitely. Thesimulation system as shown in Figure 4c is said to be in total deadlock.

    1. Transition diagram for simulation deadlock states.

    a) k k

    Deadloc

    kFree

    Transient-

    Deadlo

    ck

    Pending-

    Deadlock

    Total-Deadlock

    Deadlock

    Free State

    Self

    resolvable

    Deadlock

    Nonself-resolvable

    Deadlock States

    r ee

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    25/29

    Kresource units Entity waiting for

    Assigned to entity K resource Unit

    2. Entity-resource relationship scheme - (a) assignment edge, (b)

    request or queue edge.

    a) k

    b) k

    c)

    r

    r2r1e1

    e2

    r1 r2 e2

    r1 r2

    e1 e2

    e1

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    26/29

    3. Sequence of events in Example 1 that leads to deadlock.

    a. Definition of the enhanced seizes statement.

    Seize (e,r,k) - entity e requests kunits of resource r1. ife Vthen2. Insert (V,e);3. ifREQ[e,r] REM[ r] then4. Insert (E,(r,e,k));5. REM[r] = REM[r] - REQ [e,r];6. else7. insert(E,(e,r,k));8. if deadlock(r) 0 then9. Deadlock Detected10. Endif

    b. Definition of the enhanced release statement.

    Release (e,r,k) - entity e releases kunits of resource r1. delete(E,(r,e,k));2. Delete (USES[r], e);3. REM[r] = REM[r] + k;4. ifOWNS[e] = then5. Delete (V,e);

    6. ifQUEUE[r]

    then7. e= firstfit(r);8. ife then9. Dowhile (e )10. delete(E,(e,r,REQ[e,r]));

    11. Insert (E,(r,e,REQ[e,r]));

    12. REM[r] = REM[r] - REQ [e, r];13. e= firstfit(r);14. End while15. Else16. ifPENDING_IGNORED then

    17. if deadlock(r) = 3 then total deadlock 18. Deadlcok Detected19. Endif

    INPUT SET:

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    27/29

    OUTPUT SET:

    NOTES:

    NAME OF FACULTY:

    SIGNATURE:

    DATE:

    PROGRAM NO: - 10

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    28/29

    PROBLEM DEFINITION:

    Implementation of Bankers Algorithms for avoiding a Deadlock.

    OBJECTIVE:Implementation of Bankers Algorithms for avoiding a Deadlock.

    ALGORITHMS:

    Several data structure must be maintained to implement the bankers algorithms.

    Let n be the number of processes in the system and m be the number of resource

    types.

    *Available: - A vector of length m indicates the number of

    Available resources of each type. If Available[j] equals k, there

    Are k instances of resource type Rj available.

    *Max:- An n*m matrix defined the maximum demand of each

    Process if Max[i][j] equals k, then process Pi may request at

    Most k instances of resource type Rj.

    *Allocation: - An n*m matrix defined the maximum demand of

    Each Type currently allocated to each process. If Allocation [i][j] equals k then

    process Pi is currently allocated k instancesOf resource type Rj.

    *Need:- An n*m matrix indicates the remained resource need of each process if

    Need[i][j] equals to k then process Pi may need

    K more instances of resource type Rj to computed its task

    Safety Algorithms

    1. Let Work and Finish be vector of length m and n respectivelyWork=Available and Finish[i]=false for i=0,1,n-1.

    2. Find an i such that both

    a. Finish[i]==false

    b.Needi

  • 8/8/2019 distsys_STUDENTMANUAL_9OCT

    29/29

    3. Work =Work+Allocation

    Finish[i]=true

    Go to step 2

    4.If Finish[i] = =true for all i then the system is in a safe state.

    Resource-Request Algorithms:

    Let Requesti be the request vector for process Pi. If Requesti[j]== k then process

    Pi wants k instances of resource type Rj. When a request for resources is made by

    process Pi

    The following actions are taken:

    1.If Requesti