45
1 Exp No. 1 SEMAPHORES - MULTIPROCESSOR OPERATING SYSTEMS Date : AIM: To write a java program for multiprocessor operating systems implementing semaphores. ALGORTHIM: 1. Import the header files. 2. Declare three processor a, b, c. 3. Assign processors ‘a’, ‘b’, ‘c’ to “A”, “B”, “C” 4. Using semaphores the processors are synchronized 5. Check the following conditions: a) A B must be output before any C's can be output. b) B's and C's must alternate in the output string, that is, after the first B is output, another B cannot be output until a C is output. Similarly, once a C is output, another C cannot be output until a B is output. c) The total number of B's and C's which has been output at any given point in the output string cannot exceed the number of A's which have been output up to that point. 6. If the condition is valid, then print the result using acquire () function.

M.E Operating Systems Lab Programs

  • Upload
    sam4ets

  • View
    1.443

  • Download
    0

Embed Size (px)

DESCRIPTION

Operating System Laboratory Programs For P.G (M.E) Students - Lab Manual

Citation preview

Page 1: M.E Operating Systems Lab Programs

1

Exp No. 1

SEMAPHORES - MULTIPROCESSOR OPERATING SYSTEMS

Date :

AIM:

To write a java program for multiprocessor operating systems implementing

semaphores.

ALGORTHIM:

1. Import the header files.

2. Declare three processor a, b, c.

3. Assign processors ‘a’, ‘b’, ‘c’ to “A”, “B”, “C”

4. Using semaphores the processors are synchronized

5. Check the following conditions:

a) A B must be output before any C's can be output.

b) B's and C's must alternate in the output string, that is, after the first B is output,

another B cannot be output until a C is output.

Similarly, once a C is output, another C cannot be output until a B is output.

c) The total number of B's and C's which has been output at any given point in the

output string cannot exceed the number of A's which have been output up to that

point.

6. If the condition is valid, then print the result using acquire () function.

Page 2: M.E Operating Systems Lab Programs

2

PROGRAM:

import java.io.*;

import java.util.*;

class process

{

int count=0;

int pacount=0;

int pbccount=0;

char a[]=new char[50];

public void p1()

{

if(count==0)

{

count=count+1;

a[count]='A';

pacount=pacount+1;

System.out.print("A");

}

else

{

if(a[count]=='C' || a[count]=='A')

{

count=count+1;

a[count]='A';

pacount=pacount+1;

System.out.print("A");

}

}

}

public void p2()

{

if((a[count]=='C' || a[count]=='A')&&(pacount>pbccount))

{

count=count+1;

a[count]='B';

pbccount=pbccount+1;

System.out.print("B");

}

}

public void p3()

Page 3: M.E Operating Systems Lab Programs

3

{

int f=0;

if((a[count]=='B')&&(pacount>pbccount))

{

for(int i=1;i<count;i++)

{

if(a[i]=='A' && a[i+1]=='B')

f=1;

}

if(f==1)

{

count=count+1;

a[count]='C';

pbccount=pbccount+1;

System.out.print("C");

}

}

}

}

class firstA

{

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

{

process p=new process();

Random r=new Random();

for(int i=0;i<5;i++)

{

int r1=r.nextInt(25);

int r2=r1%3;

p.p1();

if(r2==0)

p.p1();

else if(r2==1)

p.p2();

else if(r2==2)

p.p3();

}

}

}

Page 4: M.E Operating Systems Lab Programs

4

OUTPUT:

Page 5: M.E Operating Systems Lab Programs

5

RESULT:

Thus the java program for multiprocessor operating systems implementing

semaphores was executed and the output was verified successfully.

Page 6: M.E Operating Systems Lab Programs

6

Exp No. 2

MULTITHREADING - MULTIPROCESSOR OPERATING SYSTEMS

Date :

AIM :

To write a java program for multiprocessor operating systems implementing

multithreading.

ALGORITHM :

1. Include the needed header files for the program.

2. Create the classes Table, TableCS, Agent and Smoker inside the class Cigarette.

3. Inside the main method create an instance for the class Cigarette and call the method

mainRun() .

4. This mainRun() method creates three instances (threads) for Smoker class and one

instance(thread) each for Agent class and Table class.

5. Then mainRun() method calls the run() methods inside the Agent, Smoker classes.

6. One of the Smoker threads has only paper, another has only tobacco and the third has

only matches.

7. The Agent thread has infinite supply of all the three materials. The three smoker

threads are initially blocked.

8. The agent places two randomly chosen ingredients on the table and unblocks the one

smoker who has the remaining ingredient. The agent then blocks.

9. The unblocked smoker removes the two ingredients from the table, makes a cigarette,

and smokes it for a random amount of time, unblocking the agent on completion of

smoking the cigarette.

10. The agent then puts out another random two of the three ingredients, and the cycle

repeats.

Page 7: M.E Operating Systems Lab Programs

7

PROGRAM :

import java.util.*;

public class Cigarette

{

public class Table

{

public static final int Nothing = 0;

public static final int Tobacco = 1;

public static final int Paper = 2;

public static final int Matches = 4;

public static final int Tobacco_Paper = Tobacco + Paper;

public static final int Paper_Matches = Paper + Matches;

public static final int Matches_Tobacco = Matches + Tobacco;

public static final int Everything = Tobacco + Paper + Matches;

private int contains;

public Table ()

{

contains = Nothing;

}

public synchronized void Put(int what)

{

System.out.println(Thread.currentThread().getName() +

": putting "+Contains(what));

contains = contains | what;

notifyAll();

try

{

wait();

}

catch (InterruptedException e) {}

}

public synchronized void Get(int what)

{

while ((contains & what) != what)

{

try

{

System.out.println(Thread.currentThread().getName() +

": Getting " + Contains(what) + " - No!");

wait();

}

catch (InterruptedException e) {}

}

System.out.println(Thread.currentThread().getName() +

Page 8: M.E Operating Systems Lab Programs

8

": Getting " + Contains(what) + " - Yes!");

contains = contains ^ what;

}

public synchronized void DoneSmoking()

{

notifyAll();

}

public String Contains(int what)

{

String s = "";

if ((what & Tobacco) == Tobacco)

s = s + "tobacco ";

if ((what & Paper) == Paper)

s = s + "paper ";

if ((what & Matches) == Matches)

s = s + "matches ";

return s;

}

}

public class TableCS extends Table

{

TableCS Table;

}

public class Agent extends Thread

{

private Table table;

private Random rand;

public Agent(Table tab, String name)

{

super (name);

table = tab;

rand = new Random();

}

public void run()

{

while (true)

{

switch (Math.abs(rand.nextInt()) % 3)

{

case 0:

table.Put(Table.Tobacco_Paper);

break;

case 1:

table.Put(Table.Paper_Matches);

break;

Page 9: M.E Operating Systems Lab Programs

9

case 2:

table.Put(Table.Matches_Tobacco);

break;

}

}

}

}

public class Smoker extends Thread

{

private Table table;

private Random rand;

private int needs;

public Smoker(Table tab, String name, int what)

{

super (name);

table = tab;

rand = new Random();

needs = Table.Everything ^ what;

}

public void run()

{

while (true)

{

try

{

table.Get(needs);

System.out.println(getName() + ": I got what I needed!");

System.out.println(getName() + ": Rolling.");

sleep(Math.abs(rand.nextInt()) % 1000);

System.out.println(getName() + ": Smoking.");

sleep(Math.abs(rand.nextInt()) % 1000);

System.out.println(getName() + ": Done smoking.");

table.DoneSmoking();

}

catch (InterruptedException e) {}

}

}

}

public void mainRun(String[] args)

{

Smoker smo1, smo2, smo3;

Agent agent;

Table table;

table = new Table();

agent = new Agent(table, "Agent");

smo1 = new Smoker(table, " Smoker 1", Table.Paper);

Page 10: M.E Operating Systems Lab Programs

10

smo2 = new Smoker(table, " Smoker 2", Table.Matches);

smo3 = new Smoker(table, " Smoker 3", Table.Tobacco);

agent.start();

smo1.start();

smo2.start();

smo3.start();

}

public static void main(String[] arg)

{

Cigarette a = new Cigarette();

a.mainRun(arg);

}

}

Page 11: M.E Operating Systems Lab Programs

11

OUTPUT :

Page 12: M.E Operating Systems Lab Programs

12

RESULT :

Thus the java program for multiprocessor operating systems implementing

multithreading was executed and the output was verified successfully.

Page 13: M.E Operating Systems Lab Programs

13

Exp No. 3

MULTIPLE SLEEPING BARBERS - MULTIPROCESSOR OPERATING

SYSTEMS

Date :

AIM :

To write a java program for multiprocessor operating systems implementing multiple

sleeping barbers problem.

ALGORITHM :

1. Import the header files.

2. Declare the number of chairs and barbers in the shop

3. Enter the number of customer.

4. If there is no customer to be served, the barber goes to sleep.

5. If a customer enters the barber shop whole chairs are occupied, then the customer

leaves the shop.

6. If the barber is busy, but chairs are available in waiting room then the customer sits in

one of the free chairs until the barber is idle.

7. Barber class which extends threads is used to simulate multiple sleeping barbers.

Page 14: M.E Operating Systems Lab Programs

14

PROGRAM :

import java.io.*;

import java.lang.*;

class cust

{

public int disp(int cn)

{

return(cn);

}

}

class em1 extends Thread

{

main2 m=new main2();

cust c=new cust();

public synchronized void run()

{

try

{

while(m.cnum<=m.n)

{

int t=c.disp(m.cnum++);

System.out.println("Barber2 serves Customer "+t);

Thread.sleep(2000);

}

System.out.println("Barber2 sleeps ");

}

catch(Exception e){}

}

}

public class main2

{

static int cnum=1,n,ch,n1;

public static void main(String[] args)

{

try

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

em1 e=new em1();

cust c=new cust();

int j;

System.out.println("Enter no of Chairs including two barber Chairs: ");

ch=Integer.parseInt(br.readLine());

System.out.println("Enter no of Customers : ");

n=Integer.parseInt(br.readLine());

e.start();

Page 15: M.E Operating Systems Lab Programs

15

if(ch<n)

{

n1=n-ch;

System.out.println(n1+" Customers Leaved from the Shop");

n=n-n1;

while(cnum<=n)

{

int t=c.disp(cnum++);

System.out.println("Barber1 serves " +" Customer " + t);

Thread.sleep(1000);

}

}

else

{

while(cnum<=n)

{

int t=c.disp(cnum++);

System.out.println("Barber1 serves " +" Customer " + t);

Thread.sleep(1000);

}

}

System.out.println("Barber1 sleeps ");

}

catch(Exception e){}

}

}

Page 16: M.E Operating Systems Lab Programs

16

OUTPUT :

Page 17: M.E Operating Systems Lab Programs

17

RESULT :

Thus the java program for multiprocessor operating systems implementing multiple

sleeping barbers problem was executed and output was verified.

Page 18: M.E Operating Systems Lab Programs

18

Exp No. 4

NETWORK OPERATING SYSTEMS

Date :

AIM :

To implement Network operating system in our lab.

ALGORITHM :

1. Start the Program

2. Get the IP address and the MAC address from user

3. Get the inet address using InetAddress.getByName(IP address)

4. Create a packet using DatagramPacket()

5. Create a Socket using DatagramSocket()

6. Send the packet using socket.send(packet);

7. Close the Socket using socket.close();

8. End the Program.

Page 19: M.E Operating Systems Lab Programs

19

PROGRAM :

import java.io.*;

import java.net.*;

public class WakeOnLan

{

public static final int PORT=9;

public static void main(String[ ] args)

{

if(args.length!=2)

{

System.out.println("usuage:javaWakeOnLan1<broadcast-ip><mac-address>");

System.out.println ("Example:java WakeOnLan1 172.15.169.7 00-15-58-AC-0C-20");

System.out.println ("Example:java WakeOnLan1 172.15.169.8 00-15-58-AC-0C-27");

System.exit(1);

}

String ipStr=args[0];

String macStr=args[1];

try

{

byte[ ] macBytes=getMacBytes(macStr);

byte[] bytes=new byte[6+16*macBytes.length];

for(int i=0;i<6;i++)

{

bytes[i]=(byte)0xff;

}

for(int i=6;i<bytes.length;i+=macBytes.length)

{

System.arraycopy(macBytes, 0,bytes,i,macBytes.length);

}

InetAddress address = InetAddress.getByName(ipStr);

DatagramPacket packet = new DatagramPacket(bytes,bytes.length,address,PORT);

DatagramSocket socket= new DatagramSocket();

socket.send(packet);

socket.close();

System.out.println("wake on lan packet sent");

}

catch(Exception e)

{

System.out.println("failed to send wake on lan packet:"+e);

System.exit(1);

}

}

private static byte[] getMacBytes(String macStr) throws IllegalArgumentException

{

byte[] bytes=new byte[6];

String[] hex=macStr.split("(\\:|\\-)");

Page 20: M.E Operating Systems Lab Programs

20

if(hex.length!=6)

{

throw new IllegalArgumentException("Invalid MAC address");

}

try

{

for(int i=0;i<6;i++)

{

bytes[i]=(byte)Integer.parseInt(hex[i],16);

}

}

catch(NumberFormatException e)

{

throw new IllegalArgumentException("invalid hex digit in MAC address");

}

return bytes;

}

}

Page 21: M.E Operating Systems Lab Programs

21

TO FIND MAC ADDRESS AND IP ADDRESS

C:\Users\Sam>ipconfig/all

Windows IP Configuration

Host Name . . . . . . . . . . . . : Sam-PC

Primary Dns Suffix . . . . . . . :

Node Type . . . . . . . . . . . . : Mixed

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

PPP adapter 3G Modem:

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : 3G Modem

Physical Address. . . . . . . . . :

DHCP Enabled. . . . . . . . . . . : No

Autoconfiguration Enabled . . . . : Yes

IPv4 Address. . . . . . . . . . . : 117.230.1.244(Preferred)

Subnet Mask . . . . . . . . . . . : 255.255.255.255

Default Gateway . . . . . . . . . : 0.0.0.0

DNS Servers . . . . . . . . . . . : 218.248.241.3

218.248.240.180

NetBIOS over Tcpip. . . . . . . . : Disabled

Wireless LAN adapter Wireless Network Connection:

Media State . . . . . . . . . . . : Media disconnected

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Atheros AR9285 Wireless Network Adapter

Physical Address. . . . . . . . . : B4-82-FE-DC-C4-99

DHCP Enabled. . . . . . . . . . . : Yes

Autoconfiguration Enabled . . . . : Yes

Ethernet adapter Local Area Connection:

Media State . . . . . . . . . . . : Media disconnected

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Marvell Yukon 88E8059 Family PCI-E Gigabi

t Ethernet Controller

Physical Address. . . . . . . . . : 00-24-54-7D-6E-52

DHCP Enabled. . . . . . . . . . . : Yes

Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{770C717E-3DB5-44F6-9C70-4BB9BE70A198}:

Media State . . . . . . . . . . . : Media disconnected

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Microsoft ISATAP Adapter

Page 22: M.E Operating Systems Lab Programs

22

Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

DHCP Enabled. . . . . . . . . . . : No

Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{4A6B2BFB-A001-4943-9B9A-64EB6F88819B}:

Media State . . . . . . . . . . . : Media disconnected

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2

Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

DHCP Enabled. . . . . . . . . . . : No

Autoconfiguration Enabled . . . . : Yes

Tunnel adapter isatap.{DA2C2A91-BE38-C2D6-433E-836237474E70}:

Media State . . . . . . . . . . . : Media disconnected

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3

Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

DHCP Enabled. . . . . . . . . . . : No

Autoconfiguration Enabled . . . . : Yes

Tunnel adapter Teredo Tunneling Pseudo-Interface:

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface

Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

DHCP Enabled. . . . . . . . . . . : No

Autoconfiguration Enabled . . . . : Yes

IPv6 Address. . . . . . . . . . . : 2001:0:4137:9e76:457:1c5f:8a19:fe0b(Prefe

rred)

Link-local IPv6 Address . . . . . : fe80::457:1c5f:8a19:fe0b%16(Preferred)

Default Gateway . . . . . . . . . :

NetBIOS over Tcpip. . . . . . . . : Disabled

Tunnel adapter 6TO4 Adapter:

Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Microsoft 6to4 Adapter #2

Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

DHCP Enabled. . . . . . . . . . . : No

Autoconfiguration Enabled . . . . : Yes

IPv6 Address. . . . . . . . . . . : 2002:75e6:1f4::75e6:1f4(Preferred)

Default Gateway . . . . . . . . . : 2002:c058:6301::c058:6301

DNS Servers . . . . . . . . . . . : 218.248.241.3

218.248.240.180

NetBIOS over Tcpip. . . . . . . . : Disabled

C:\Users\Sam>

Page 23: M.E Operating Systems Lab Programs

23

OUTPUT:

TO TEST LAN CONNECTION :

C:\Users\Sam>ping msec.org.in

Pinging msec.org.in [69.167.190.8] with 32 bytes of data:

Reply from 69.167.190.8: bytes=32 time=532ms TTL=114

Reply from 69.167.190.8: bytes=32 time=451ms TTL=114

Reply from 69.167.190.8: bytes=32 time=458ms TTL=114

Reply from 69.167.190.8: bytes=32 time=456ms TTL=114

Ping statistics for 69.167.190.8:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 451ms, Maximum = 532ms, Average = 474ms

C:\Users\Sam>

Page 24: M.E Operating Systems Lab Programs

24

RESULT :

Thus the Network operating system was implemented in our lab and the output was

verified.

Page 25: M.E Operating Systems Lab Programs

25

Exp No. 5

REAL TIME OPERATING SYSTEMS

Date :

AIM :

To write a C program using Real time operating system for implementing an alarm

clock.

ALGORITHM :

1. Start the program.

2. Display init is used for initialization and shall be called from the main function of the

program before the processes are created.

3. Display alarm time a shows the current time and shall be called when a new alarm

time is set.

4. Display time is used to display the current time and shall be called by the clock

process.

5. Erase the alarm time, erases the displayed alarm time and shall be called when the

user acknowledges an alarm.

6. Display alarm text is used to show an alarm activation and the user is informed that

the alarm has been activated.

7. when the alarm is activated the first time and when the alarm is activated repeatedly.

8. Erase alarm text,erase the information displayed by displays the alarm text.

9. Stop the program.

Page 26: M.E Operating Systems Lab Programs

26

PROGRAM :

#include<stdio.h>

#include<conio.h>

#include<dos.h>

struct clk

{

int hh,mm,ss;

}c1,c2;

void clock(int *h1,int *m1,int *s1)

{

*s1=*s1+1;

if(*s1==60)

{

*s1=0;

*m1=*m1+1;

if(*m1==60)

{

*m1=0;

*h1=*h1+1;

if(*h1==24)

*h1=0;

}

}

}

void timer(int *h,int *m,int *s)

{

if((*s)!=0)

{

*s=*s-1;

}

else if((*s)==0)

{

if(*m!=0)

{

*s=59;*m=*m-1;

}

else if(*m==0)

{

if(*h!=0)

{

*m=59;*h=*h-1;

}

}

}

}

void alarm()

Page 27: M.E Operating Systems Lab Programs

27

{

while(!kbhit())

printf("\a");

}

void main()

{

char ch;

struct time t;

clrscr();

printf("\nPress:-\n\tA: for alarm Clock\n\tT: for Timer\n");

printf("\Enter your Choice:");

ch=getche();

switch (ch)

{

case 'A':

case 'a':

{

printf("\n\n\n24 hr Format(HH:MM:SS)");

gettime(&t);

c1.hh=t.ti_hour; c1.mm=t.ti_min; c1.ss=t.ti_sec;

printf("\nEnter alarm time : ");

scanf("%d:%d:%d",&c2.hh,&c2.mm,&c2.ss);

if(c2.hh>24||c2.mm>60||c2.ss>60)

{

printf("\n\n\tERROR: Invalid time.\n\tRestart the program.");

delay(2500);exit(0);

}

while((c1.ss!=c2.ss)||(c1.hh!=c2.hh)||(c1.mm!=c2.mm))

{

clrscr();

printf("\n\nAlarm time:

%02d:%02d:%02d\n",c2.hh,c2.mm,c2.ss);

printf("\nCurrent Time:

%02d:%02d:%02d",c1.hh,c1.mm,c1.ss);

clock(&c1.hh,&c1.mm,&c1.ss);

delay(1000);

};

clrscr();

printf("\n\n\n\n\t\t\t\tAlarm time reached\n\n\t\t\t\tPress any to Exit.");

alarm();

exit(0);

}

break;

case 'T':

case 't':

{

printf("\n\n\nEnter time for timer (HH:MM:SS): ");

scanf("%d:%d:%d",&c1.hh,&c1.mm,&c1.ss);

while(c1.hh>0||c1.mm>0||c1.ss>0)

Page 28: M.E Operating Systems Lab Programs

28

{

clrscr();

printf("The Current Time:\n");

printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t");

printf("%02d:%02d:%02d",c1.hh,c1.mm,c1.ss);

timer(&c1.hh,&c1.mm,&c1.ss);

delay(1000);

}

clrscr();

printf("Program Written by: Cyber Criminalzz\n");

printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t");

printf("00:00:00");

alarm();

exit(0);

}

break;

default:

{

printf("\n\tInvalid Input\n\n\tPlease restart the program");

delay(2500);exit(0);

}

}

}

Page 29: M.E Operating Systems Lab Programs

29

OUTPUT :

Page 30: M.E Operating Systems Lab Programs

30

Page 31: M.E Operating Systems Lab Programs

31

RESULT :

Thus the C program using Real time operating system for implementing an alarm

clock was executed and the output was verified.

Page 32: M.E Operating Systems Lab Programs

32

Exp No. 6

TRANSACTIONS AND CONCURRENCY -DATABASE OPERATING

SYSTEMS

Date :

AIM :

To implement a college admission system application using database operating

system.

ALGORITHM :

1. Start the Program

2. Implement Distributed Operating System by implementing following things

2.1 Start the Application Transaction.

2.2 Establish the Database Connection by following steps

Connection con=null;

Statement st=null;

ResultSet rs=null;

2.3 Get the new student Details like name, age, branch, gender and address

2.4 Using jdbc Connection in java add all the details about customer into the

database

2.5 Method Invocation: as a part of te given transaction the object will be locked

in read or write mode and commit/ abort of the transaction

2.6 Retrieve the Relevant details when client queries the Data

2.7 Display to the user

3. Stop the program

Page 33: M.E Operating Systems Lab Programs

33

PROGRAM :

import java.sql.*;

import java.io.*;

public class jdbc

{

public static void main(String[]args)

{

PreparedStatement pstm;

ResultSet rs;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

try

{

System.out.println("Enter Regno");

String regno=br.readLine();

System.out.println("Enter name");

String nam=br.readLine();

System.out.println("Enter age");

String age=br.readLine();

System.out.println("Enter branch");

String branch=br.readLine();

System.out.println("Enter gender");

String gender=br.readLine();

System.out.println("Enter address");

String address=br.readLine();

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

java.util.Date d=new java.util.Date();

System.out.println("The time of starting the transaction is"+d);

Connection connect =DriverManager.getConnection("jdbc:odbc:samp");

pstm=connect.prepareStatement("insert into amu values(?,?,?,?,?,?)");

pstm.setString(1,regno);

pstm.setString(2,nam);

pstm.setString(3,age);

pstm.setString(4,branch);

pstm.setString(5,gender);

pstm.setString(6,address);

pstm.executeUpdate();

System.out.println("Data is inserted into MS Access database");

pstm.close();

System.out.println("Enter the name of the customer u want to see the details");

String n=br.readLine();

pstm = connect.prepareStatement("select * from amu where name='"+n+"'");

rs = pstm.executeQuery();

Page 34: M.E Operating Systems Lab Programs

34

while (rs.next())

{

System.out.print(rs.getString(1) + "\t");

System.out.print(rs.getString(2) + "\t");

System.out.print(rs.getString(3) + "\t");

System.out.print(rs.getString(4) + "\t");

System.out.print(rs.getString(5) + "\t");

System.out.print(rs.getString(6) + "\t");

}

rs.close();

pstm.close();

connect.close();

}

catch(Exception ex)

{

System.out.println(ex);

}

}

}

Page 35: M.E Operating Systems Lab Programs

35

OUTPUT :

Before Adding into Table

Output

Page 36: M.E Operating Systems Lab Programs

36

After added into the table

Page 37: M.E Operating Systems Lab Programs

37

RESULT :

Thus the college admission system application using database operating system was

implemented and the output was verified.

Page 38: M.E Operating Systems Lab Programs

38

Exp No. 7

DISTRIBUTED OPERATING SYSTEMS

Date :

AIM :

To implement a RMI Lottery application using distributed operating system.

ALGORITHM :

Server Algorithm:

1. Import header files.

2. Class RmiServer which implements ReceiveMessageInterface

3. Provide RMI registry for lookup the remote objects.

4. Read the message from client and calculate the values using receiveMessage( ).

5. Print the Server system address and Port number using RmiServer( ).

Client Algorithm:

1. Import header files.

2. Provide the message along with the server address and port number.

3. The server is invoked using ReceiveMessageInterface interface..

4. The RMI registry is used for lookup the remote objects.

5. The x [] array is declared to store the values which are return from server.

6. The values of x [] array will be retrieved using for loop.

7. Displays the result.

Page 39: M.E Operating Systems Lab Programs

39

PROGRAM :

ReceiveMessageInterface.java

import java.rmi.*;

public interface ReceiveMessageInterface extends Remote

{

public int [] receiveMessage(int x) throws RemoteException;

}

RmiClient.java

import java.io.*;

import java.rmi.*;

import java.rmi.registry.*;

import java.net.*;

public class RmiClient

{

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

{

ReceiveMessageInterface rmiServer;

Registry registry;

String serverAddress=args[0];

String serverPort=args[1];

int no;

no=Integer.parseInt(args[2]);

int rval[]=new int[no];

System.out.println("sending "+no+" to "+serverAddress+":"+serverPort);

try{

registry=LocateRegistry.getRegistry(serverAddress,(new Integer(serverPort)).intValue());

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

rval=rmiServer.receiveMessage(no);

for(int i=0;i<no;i++)

System.out.println(rval[i]);

}

catch(RemoteException e)

{

e.printStackTrace();

}

catch(NotBoundException e)

{

e.printStackTrace();

}

}

}

Page 40: M.E Operating Systems Lab Programs

40

RmiServer.java

import java.util.*;

import java.rmi.*;

import java.rmi.registry.*;

import java.rmi.server.*;

import java.net.*;

public class RmiServer extends java.rmi.server.UnicastRemoteObject

implements ReceiveMessageInterface

{

int thisPort;

String thisAddress;

Registry registry;

public int[] receiveMessage(int x) throws RemoteException

{

System.out.println(x);

Random r=new Random();

int val[] = new int[x];

for(int i=0;i<x;i++)

{

val[i]=r.nextInt(25);

}

return val;

}

public RmiServer() throws RemoteException

{

try

{

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

}

catch(Exception e)

{

throw new RemoteException("can't get inet address.");

}

thisPort=3232;

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

try

{

registry = LocateRegistry.createRegistry( thisPort );

registry.rebind("rmiServer", this);

}

catch(RemoteException e)

{

throw e;

}

}

static public void main(String args[])

{

Page 41: M.E Operating Systems Lab Programs

41

try

{

RmiServer s=new RmiServer();

}

catch (Exception e)

{

e.printStackTrace();

System.exit(1);

}

}

}

Page 42: M.E Operating Systems Lab Programs

42

OUTPUT :

Page 43: M.E Operating Systems Lab Programs

43

Page 44: M.E Operating Systems Lab Programs

44

Page 45: M.E Operating Systems Lab Programs

45

RESULT :

Thus the RMI Lottery application using distributed operating system was

implemented and executed successfully.