Monday, 26 December 2016
SJF-SHORTEST JOB FIRST
SHORTEST JOB FIRST
import
java.util.*;
class SJF {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n, BT[], WT[], TAT[];
System.out.println("Enter no of
process");
n = sc.nextInt();
BT = new int[n + 1];
WT = new int[n + 1];
TAT = new int[n + 1];
float AWT = 0;
System.out.println("Enter Burst time for
each process");
for (int i = 0; i < n; i++) {
System.out.println("Enter BT for
process " + (i + 1));
BT[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
WT[i] = 0;
TAT[i] = 0;
}
int temp;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
if (BT[j] > BT[j + 1]) {
temp = BT[j];
BT[j] = BT[j + 1];
BT[j + 1] = temp;
temp = WT[j];
WT[j] = WT[j + 1];
WT[j + 1] = temp;
}
}
}
for (int i = 0; i < n; i++) {
TAT[i] = BT[i] + WT[i];
WT[i + 1] = TAT[i];
}
TAT[n] = WT[n] + BT[n];
System.out.println(" PROCESS BT WT TAT
");
for (int i = 0; i < n; i++)
System.out.println(" " + i +
" " + BT[i] + " " + WT[i] + " " + TAT[i]);
for (int j = 0; j < n; j++)
AWT += WT[j];
AWT = AWT / n;
System.out.println("***********************************************");
System.out.println("Avg waiting
time=" + AWT +
"\n***********************************************");
}
}
OUTPUT:
FCFS- FIRST COME FIRST SERVE
First Come First Serve (FCFS)
- Jobs are executed on first come, first serve basis.
- It is a non-preemptive, pre-emptive scheduling algorithm.
- Easy to understand and implement.
- Its implementation is based on FIFO queue.
- Poor in performance as average wait time is high.
FIRST COME
FIRST SERVE PROGRAM
import java.util.*;
class
FCFS
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int p;
float t1=0,t2=0;
System.out.println("Enter number of
processes");
p=in.nextInt();
int bt[]=new int[p];
System.out.println("Enter burst
time");
for(int i=0;i<p;i++)
{
System.out.println("Burst time for
P"+(i+1)+"=");
bt[i]=in.nextInt();
}
int wt[]=new int[p];
wt[0]=0;
for(int i=1;i<p;i++)
{
wt[i]=bt[i-1]+wt[i-1];
t1+=wt[i];
}
int tat[]=new int[p];
for(int i=0;i<p;i++)
{
tat[i]=bt[i]+wt[i];
t2+=tat[i];
}
System.out.println("Process\tBurst
time\tWaiting time\tTurn Around time");
for(int i=0;i<p;i++)
{
System.out.println("P"+(i+1)+"\t\t"+bt[i]+"\t\t"+wt[i]+"\t\t"+tat[i]);
}
float awt,atat;
System.out.println("Average Waiting
time="+t1/p);
System.out.println("Average Turn
Around time="+t2/p);
}
OUTPUT
:
IF ANY ERRORS COMMENTS :)
Sunday, 4 December 2016
Q1) Describe the OSI Reference Model with a neat diagram
Ans:
1. The users of a computer network are located all over the world. 2. Therefore International group of standards has been developed to ensure that nationwide and worldwide data communication systems can be developed and are compatible to each other. 3. This standards will fit into a framework which has been developed by the “International Organization of Standardization (ISO)”. 4. This framework is called as OSI Model. 5. OSI Model Stands for Open Systems Interconnection Model. 6. OSI Model has 7 Layers.
OSI Reference Model:
Figure 1.1: OSI Reference Model.
I) Physical Layer:
It is the bottom layer of OSI Model. It is responsible for the actual physical connection between the devices. Such physical connection may be made by using twisted pair cable. It is concerned with transmitting bits over a communication channel.
Functions of Physical Layer: It defines the transmission rate. Transforming bits into signals. Provides synchronization of bits by a clock. It defines the way in which the devices are connected to the medium. It can use different techniques of multiplexing.
II) Data Link Layer:
It is responsible for node-to-node delivery of data. It receives the data from network layer and creates FRAMES, add physical address to these frames & pass them to physical layer. It consist of 2 layers: Logical Link Layer (LLC). Medium Access Control (MAC).
Functions of Data Link Layer:
It is used for synchronization and error control for the information. It divides the bits received from Network layer into frames. It provides Flow Control. To enable the error detection, it adds error detection bits to the data which is to be transmitted.
III) Network Layer:
It is responsible for the source to destination delivery of a packet across multiple networks. If two systems are attached to different networks with devices like routers, then Network layer is used. Thus Data Link Layer overseas the delivery of the packet between the two systems on same network and the network layer ensures that the packet gets its point of origin to its final destination.
Functions of Network Layer:
It provides Internetworking. Network Layer route the signals through various channels to the other end. It is used in Logical Addressing. It acts as a network controller for routing data.
IV) Transport Layer:
It is responsible for process-to-process delivery of the entire message. Transport Layer looks after the delivery of entire message considering all its packets & make sure that all packets are in order. At the receiver side, Transport Layer provides services to application layer & takes services form network layer. At the source side, Transport Layer receives message from upper layer into packets and reassembles these packets again into message at the destination.
Functions of Transport Layer:
It provides Connection Less & Connection Oriented Transmission. It does the functions such as multiplexing, splitting or segmentation on the data. It provides Error Control & Flow Control. It is used for Port Addressing.
V) Session Layer:
Session layer is the fifth layer of OSI Model. It has the responsibility of beginning, maintaining and ending the communication between two devices, called session. It also provides for orderly communication between devices by regulating the flow of data.
Functions of Session Layer:
It manages & synchronizes the conversations between two different applications. It controls logging on and off. It is used for billing, user identification & session management. It provides dialog control & dialog separation.
VI) Presentation Layer:
Presentation layer is the sixth layer of OSI Model. It is concerned with the syntax & semantics of the information exchanged between the two devices. It works as translating layer.
Functions of Presentation Layer:
It is used for data encryption, decryption and compression. It ensures that the information delivered at receiver end is understandable & usable. It is used for data presentation or translation of form and syntax. Example: ASCII to EBCDIC and vice versa.
VII) Application Layer:
It is the topmost i.e. seventh layer of OSI Model. It enables the user to access the network. It provides user interface & supports for services such as e-mail, file transfer, access to the World Wide Web. So it provides services to different user applications.
Functions of Application Layer:
Application Layer provides various E-mail Services. It allows users to access files in a remote host, to retrieve files from remote computer for use etc. It is provides Remote Login.
Subscribe to:
Posts (Atom)