Professional Documents
Culture Documents
S.I.E.S College of Arts, Science and Commerce, Sion (W), Mumbai - 400 022
S.I.E.S College of Arts, Science and Commerce, Sion (W), Mumbai - 400 022
CERTIFICATE
This is to certify that Mr./ Miss. Rohit Sarvjeet Yadav has successfully completed
Operating System during the academic year 2020 – 2021 complying with the
Science [Semester-III ]
Date: 11/12/2020
College Seal
Sr. Practica Aim Date Page
No. l number
Number
1 1 Write a program to implement the 04/09/2020 03
concept of Remote Method
Invocation(RMI)
2 2 Programs to implement the concept 11/09/2020 05
of Multithreading
a. Program to display Summation of
numbers using thread
3 2 b. Program to display the prime 11/09/2020 07
numbers using thread
4 2 c. Program to display the Fibonacci 11/09/2020 08
series using thread
5 3 Write a program to implement 18/09/2020 09
Bounded Buffer to solve Producer
-Consumer problem with and without
Semaphore.
6 4 Write a program to simulate FCFS 09/10/2020 12
algorithm and calculate average
waiting time and average turnaround
time
7 5 Write a program to simulate SJF 16/10/2020 14
algorithm (Non pre-emptive) and
calculate average waiting time and
average turnaround time
8 6 Write a program to solve readers- 23/10/2020 16
writers problem.
9 7 Write a Python program that 06/11/2020 19
implements the banker’s algorithm.
PRACTICAL NO-1
The Remote Method Invocation mechanism lets you do something that sounds simple. If
you have access to an object on a different machine, you can call methods of the remote
object. Of course, the method parameters must somehow be shipped to the other
machine, the object must be informed to execute the method, and the return value must
be shipped back. In RMI terminology, the object whose method makes the remote call is
called the client object. The remote object is called the server object. It is important to
remember that the client/server terminology applies only to a single method call. The
computer running the code in the Java programming language that calls the remote method
is the client for that call, and the computer hosting the object that processes the call is
the server for that call. It is entirely possible that the roles are reversed somewhere
down the road. The server of a previous call can itself become the client when it invokes a
remote method on an object residing on another computer.
import java.rmi.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
Methodimpl
return Math.sqrt(dbl);
try
Naming.rebind("//localhost/call1", server);
exec.printStackTrace();
import java.rmi.*;
import java.rmi.registry.*;
class RMIClient
try
Methodimpl mthdIp =
(Methodimpl)Naming.lookup("//localhost/call1");
System.out.println("SQRT:" + dbl);
exce.printStackTrace();
Output:
Practical no:-2
Aim:
Code:
import threading
import logging
def summation(number,name):
logging.info (f'Thread{name} : starting')
sum=0
for i in range(1,number+1):
sum+=i
print(f'sum of {number} is {sum}')
logging.info(f'Thread{name} : stopping')
format="%(asctime)s:%(message)s"
logging.basicConfig(format=format,level=logging.INFO,datefmt="%H:
%M: %S")
logging.info("main: before creating thread")
x=threading.Thread(target= summation, args=(30,1))
logging.info("main: before running thread")
x.start()
logging.info("main: waiting for the thread to finish")
x.join()
logging.info("main: all done")
Output:
Practical:2
Aim:
Code:
import threading
import logging
def prime(n,name):
logging.info(f' Thread{name} started')
print(f'The prime numbers are upto {n} are')
for i in range(1,n):
if i>1:
for j in range(2,i):
if(i % j==0):
break
else:
print(i)
logging.info(f'Thread{name} stopping')
format=("%(asctime)s:%(message)s")
logging.basicConfig(format=format,level=logging.INFO,datefm
t="%H:%M:%S")
logging.info("Main: before creating thread")
x=threading.Thread(target=prime,args=(25,1))
logging.info("Main: before starting thread")
x.start()
logging.info("Main: waiting thread to finish")
x.join()
logging.info("Main: All done")
Output:
Practical no: 2
Aim:
Code:
import threading
import logging
def febonacci(num,name):
logging.info(f'the thread{name} has started')
i=3
a=0
b=1
print(f'The {num} Fibonacci series generated are')
print(a)
print(b)
for i in range(i,num+1):
c=b
b=a+b
a=c
print(b)
logging.info(f'the thread{name} has stopped')
format="%(asctime)s:%(message)s"
logging.basicConfig(format=format,level=logging.INFO,datefmt="%H:%M:%S")
logging.info("Main: before creating thread ")
feb=threading.Thread(target=febonacci,args=(7,1))
logging.info("Main : before running the thread")
feb.start()
logging.info("main: waiting for the thread to finish")
feb.join()
logging.info("main: all done")
Output:
Practical No: 3
Code:
import threading
import time
N=4
buf=[None]*N
item=0
counter=0
def produce():
global item
item+=1
print(f"{item}Produced!\n")
return item
def producer():
front=0
global counter
x=produce()
counter+=1
buf[front]=x
front=(front+1)%N
time.sleep(2)
def consume(y):
print(f"{item}consumed\n")
def consumer():
rear=0
global counter
while counter!=0:
y=buf[rear]
counter-=1
consume(y)
rear=(rear+1)%N
time.sleep(5)
producer_thread=threading.Thread(target=producer)
consumer_thread=threading.Thread(target=consumer)
consumer_thread.start()
producer_thread.start()
Output:
Aim: program to implement a counted buffer Produced-
Consumer problem with Semaphore.
Code:
import threading
import time
N=4
buf=[None]*N
item=0
fill_count=threading.Semaphore(0)
empty_count=threading.Semaphore(N)
def produce():
global item
item+=1
print(f"{item}Produced!\n")
return item
def producer():
front=0
while True:
x=produce()
empty_count.acquire()
buf[front]=x
fill_count.release()
front=(front+1)%N
time.sleep(2)
def consume(y):
print(f"{item}consumed\n")
def consumer():
rear=0
while True:
fill_count.acquire()
y=buf[rear]
empty_count.release()
consume(y)
rear=(rear+1)%N
time.sleep(10)
producer_thread=threading.Thread(target=producer)
consumer_thread=threading.Thread(target=consumer)
consumer_thread.start()
producer_thread.start()
0utput:
Practical No: 4
Output:
Practical No:5
Code:
finallist=[]
def getwt(n,plist):
runtime=[0]*n
for i in range(1,n):
finallist.append(plist[0])
prevbt=plist[0][2]
plist.pop(0)
runtime[i]=runtime[i-1]+prevbt
plist=sorted(plist,key=lambda x:(x[2],x[1]))
if runtime[i]<plist[0][1]:
plist=sorted(plist,key=lambda x:(x[1],x[2]))
plist[0][3]=runtime[i]-plist[0][1]
if plist[0][3]<0:
plist[0][3]=0
finallist.append(plist[0])
def gettat(n,plist):
for i in range(n):
plist[i][4]=plist[i][3]+plist[i][2]
def getaveragetime(n,plist):
getwt(n,plist)
plist=finallist
gettat(n,plist)
total_wt=0
total_tat=0
for i in range(n):
total_wt+=plist[i][3]
total_tat+=plist[i][4]
print(f"P{plist[i][0]}\t{plist[i][2]}\t{plist[i][1]}\t{plist[i]
[3]}\t{plist[i][4]}")
avgwt=total_wt/n
avgtat=total_tat/n
process_list=[]
for i in range(n):
process=list(map(int,input(f"Enter process no Arrival time and Burst
time separated by space").split(' ')))
process.extend([0,0])
process_list.append(process)
process_list=sorted(process_list,key=lambda x:(x[1],x[2]))
print(process_list)
getaveragetime(n,process_list)
Output:
Practical No: 6
Output:
Practical No: 7
Aim: Write a Python program that implements the banker’s
algorithm.
Code:
Allocation=[]
Max=[]
Need=[]
for i in range(n):
theinputs=[]
for j in range(m):
x=int(input())
theinputs.append(x)
Allocation.append(theinputs)
for i in range(n):
theinputs=[]
for j in range(m):
x=int(input())
theinputs.append(x)
Max.append(theinputs)
for i in range(n):
theinputs=[]
for j in range(3):
x=Max[i][j]-Allocation[i][j]
theinputs.append(x)
Need.append(theinputs)
print(Need)
Resources=[]
for i in range(m):
x=int(input())
Resources.append(x)
print(Resources)
Available=[]
for j in range(m):
x=0
for i in range(n):
x+=Allocation[i][j]
x=Resources[j]-x
Available.append(x)
print(Available)
Work=Available.copy()
Finish=[0]*n
Sequence=[]
alldone=False
attempt=0
while alldone==False:
attempt+=1
for i in range(n):
for k in range(m):
Work[k]+=Allocation[i][k]
Finish[i]=1
Sequence.append(i)
for i in range(n):
if(Finish[i]==0):
break
else:
alldone=True
if attempt>2:
break
if(alldone==True):
print("Granted!")
print(Sequence)
else:
print("Not Granted!")
Output: