Ilovepdf Merged 2
Ilovepdf Merged 2
Date :
Steps:
3. Install the power supply. Some cases come with the power supply
already installed, while others will require to purchase the power
supply separately and install it ourself. Have to make sure that
the power supply is installed in the correct orientation,and that
nothing is blocking the power supply's fan.
a. The power supply will usually go near the top or the
bottom rear of the case. Can determine where the power
supply is supposed to sit by looking for a missing section
on the back of the case.
5. Apply thermal paste to the processor if necessary. Put a small dot (around the size of a grain of
rice or a pea) of thermal paste on the CPU. Adding too much thermal paste will create a mess,
such as getting paste into the motherboard socket, which may short circuit components and
decrease the motherboard's value if planning to sell it later.
10. Install the hard drive. This process will vary slightly depending on your case, but should
typically go as follows:
a. Remove any front panels on the case.
b. Insert the hard drive into its slot (usually
near the top of the case).
c. Tighten any screws needed to hold the
drive-in place.
d. Plug the hard drive's SATA cable into the
SATA slot on the motherboard.
11. Connect the power supply to any necessary components. If the power supply is not connected
to components which need power, make sure that it is
connected to the following locations:
a. Motherboard
b. Graphics card(s)
c. Hard drive(s)
1. Attach the computer to an outlet. Using the power source's power cable, plug the computer
into a wall outlet or power strip.
a. May first have to attach the electrical cable to the power source input on the back of
the computer's case.
2. Plug a monitor into the computer. Typically use the graphics card output that is near the bottom
of the case, though some motherboards may have this port on the right or left side ofthe case.
a. The output here is usually a DisplayPort or HDMI port.
3. Turn on the computer. Press the computer's Power button on the front or back of the case. If
everything's properly connected, the computer should start up.
4. Install Windows or Linux. Windows is compatible with all PCs and will make full use of their
various features (e.g., Bluetooth), but will have to purchase a copy of Windows if not having a
product key. Linux is free but may not be able to use all the computer's hardware.
a. If not having an installation USB drive, need to create one on another computer before
can install the operating system.
5. Install the drivers. Once the operating system is installed, need to install the drivers. Almost all
the hardware that was purchased should come with discs that contain the driver software needed
for the hardware to work.
Modern versions of Windows and Linux will install most drivers automatically when
connected to the Internet.
Aim :
Steps :
1. Download the Ubuntu iso (desktop not server) and the free VMware Player.
2. Install VMware Player and run it, can see something like this:
4. Select “Installer disc image file” and browse to the Ubuntu iso downloaded.
Click next
7|Page
5. Enter full name, username and password and hit next
6. Select the maximum disk size and type. Unless planning on some really CPU intensive work inside
the VM, select the “Split virtual disk into multiple files” option. Hit next when comfortable with
the settings.
9. This brings back to the confirmation page. Click Finish this time.
10. Will probably be prompted to download VMware Tools for Linux. Click “Download and
Install” to continue.
15. Once it is set that up, system is up and running with Ubuntu in VMware Player on the
Windows machine.
Result ;
Algorithm:
1. Start the process
2. Get the number of processes to be inserted
3. Get the value for burst time of each process from the user
4. Having allocated the burst time(bt) for individual processes , Start with the first
process from its initial position let other process to be in queue
5. Calculate the waiting time(wt) and turnaround time(tat) as
6. Wt(pi) = wt(pi-1) + tat(pi-1) (i.e. wt of current process = wt of previous process + tat of
previous process)
7. tat(pi) = wt(pi) + bt(pi) (i.e. tat of current process = wt of current process + bt of
current process)
8. Calculate the total and average waiting time and turnaround time
9. Display the values
10. Stop the process
Program:
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp; float
avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
printf("\nEnter Burst Time:\n");
for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1; //contains process number
}
wt[0]=0; //waiting time for first process will be zero
//calculate waiting time
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=(float)total/n; //average waiting time
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\np%d\t\t%d\t\t%d\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n; //average turnaround time
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}
Output:
Result:
Thus, the first come first serve scheduling algorithm is implemented successfully.
Exp.No. 2(B) CPU SCHEDULING ALGORITHMS
Date IMPLEMENTATION OF SHORTEST JOB FIRST SCHEDULING
Aim:
To implement the Shortest Job First scheduling algorithm
Description:
This algorithm associates with each process the length of the latter's next CPU burst.
When the CPU is available, it is assigned to the process that has the smallest next CPU burst.
If two processes have the same length next CPU burst, FCFS scheduling is used to break the
tie.
Example
Process Burst Time
P1 6
P2 8
P3 7
P4 3
Gantt Chart
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
Result:
AWT = 8.2 ms
It can be either preemptive or non-preemptive. Problem with priority scheduling algorithms is
indefinite blocking or starvation. A solution to the problem of indefinite blockage of low priority
process is aging. Aging is a technique of gradually increasing the priority of processes that wait in
the system for a long time. For example, if priorities range from 0 (low) to 127 (high), we could
increment the priority of a waiting process by 1 every 15 mins.
Algorithm:
1. Start the process
2. Get the number of processes to be inserted
3. Get the corresponding priority of processes
4. Sort the processes according to the priority and allocate the one with highest priority
to execute first
5. If two process have same priority then FCFS scheduling algorithm is used
6. Calculate the total and average waiting time and turnaround time
7. Display the values
8. Stop the process
Program:
#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pri[20],i,j,k,n,total=0,pos,temp;
float avg_wt,avg_tat;
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pri[j] < pri[pos])
pos=j;
}
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=pri[i];
pri[i]=pri[pos];
pri[pos]=temp;
}
return 0;
Output:
Result:
Thus, priority scheduling algorithm is implemented successfully.
Exp.No. 2(D) CPU SCHEDULING ALGORITHMS
Date IMPLEMENTATION OF ROUND-ROBIN SCHEDULING
Aim:
To implement round robin scheduling algorithm
Description:
The round-robin (RR) scheduling algorithm is designed especially for timesharing systems. It is
similar to FCFS scheduling, but preemption is added to switch between processes. A small unit of
time, called a time quantum (or time slice), is defined. The ready queue is treated as a circular queue.
Process Burst Time Quantum Time = 4 ms
P1 24
P2 3
P3 3
Gantt chart
#include<stdio.h>
int main()
{
int st[10], bt[10], wt[10], tat[10], n, tq;
int i, count=0, swt=0, stat=0, temp, sq=0;
float awt, atat;
while(1)
{
for(i=0, count=0; i<n; i++)
{
temp=tq;
if(st[i]==0)
{
count++;
continue;
}
if(st[i]>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
{
temp=st[i];
st[i]=0;
}
sq=sq+temp;
tat[i]=sq;
}
if(n==count)
break;
}
awt=(float)swt/n;
atat=(float)stat/n;
printf("Average Wait Time = %f, Average Turnaround Time = %f", awt, atat);
return 0;
}
Output:
Result:
PROGRAM:
#include <stdio.h>
#include <unistd.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
int fd[2], child;
char a[10];
pipe(fd);
child = fork();
if (!child) {
close(fd[0]);
write(fd[1], a, sizeof(a));
close(fd[1]);
exit(0);
} else {
close(fd[1]);
read(fd[0], a, sizeof(a));
close(fd[0]);
printf("The string received from pipe is: %s", a);
}
return 0;
}
OUTPUT:
Result: Thus, IPC using pipes mechanisms is illustrated using c program successfully.
EX.no:3b)
SYSTEM CALLS
DATE:
(READ & WRITE, CREATE &FORK, OPEN
&CLOSE)
Aim: C program using open, read, write, close , create , fork() system calls.
Theory:
There are 5 basic system calls that Unix provides for file I/O.
1. Create: Used to Create a new empty file
Syntax :int creat(char *filename, mode_t mode)
filename : name of the file which you want to create
mode : indicates permissions of new file.
2. open: Used to Open the file for reading, writing or both.
Syntax: int open(char *path, int flags [ , int mode ] );
Path : path to file which you want to use
flags : How you like to use
O_RDONLY: read only, O_WRONLY: write only, O_RDWR: read and write, O_CREAT: create
file if it doesn’t exist, O_EXCL: prevent creation if it already exists
3. close: Tells the operating system you are done with a file descriptor and Close the file which
pointed by fd.
Syntax: int close(int fd); fd :file
descriptor
4. read: From the file indicated by the file descriptor fd, the read() function reads cnt bytes of input
into the memory area indicated by buf. A successful read() updates the access time for thefile.
Syntax: int read(int fd, char *buf, int size);
fd: file descripter
buf: buffer to read data from
cnt: length of buffer
5. write: Writes cnt bytes from buf to the file or socket associated with fd. cnt should not begreater
than INT_MAX (defined in the limits.h header file). If cnt is zero, write() simply returns 0without
attempting any other action.
Syntax: int write(int fd, char *buf, int size);fd: file
descripter
buf: buffer to write data to
cnt: length of buffer
*File descriptor is integer that uniquely identifies an open file of the process.
Algorithm:
Program:
#include<sys/stat.h>
#include<stdio.h>
#include<fcntl.h>
#include<sys/types.h>
#include<unistd.h>
int main()
{
int n,i=0;
int f1,f2;
char c,strin[100];
f1=open("data",O_RDWR|O_CREAT|O_TRUNC);
while((c=getchar())!='\n')
{
strin[i++]=c;
}
strin[i]='\0';
write(f1,strin,i);
close(f1);
f2=open("data",O_RDONLY);
read(f2,strin,0);
printf("\n%s\n",strin);
close(f2);
fork();
return 0;
}
Output:
RESULT:
Thus, open, read, write, close , create , fork() system calls implemented successfully using c
program.
EX.no:
3(C)
DATE: IMPLEMENT BANKERS’ ALGORITHM FOR DEAD
LOCKAVOIDANCE
AIM:
To write a C program to implement Bankers Algorithm to avoid Deadlock.
PROBLEM DESCRIPTION:
There are possibilities of side effects of preventing deadlocks and low device
utilization reduced system throughput. When a new process enters the system, it must declare
the maximum number of instances of each resource type that it may need. This number may
not exceed the total number of resources in the system.
When a user requests a set of resources, the system must determine whether the
allocation of these resources will leave the system in a safe state. It will, the resource are
allocated, otherwise the process must wait until some other process releases enough resources.
ALGORITHM:
#include<stdio.h>
int main ()
{
int allocated[15][15], max[15][15], need[15][15],
avail[15], tres[15], work[15], flag[15];
int pno, rno, i, j, prc,
count, t, total; count =
0;
do
{
prc = 0;
for (i = 1; i <= pno; i++)
{
if (flag[i] == 0)
{
prc = i;
for (j = 1; j <= rno; j++)
{
if (work[j] < need[i][j])
{
break;
}
}
if (prc != 0)
{
break;
}
}
}
if (prc != 0)
{
printf ("\n Process %d completed", prc);
count++;
printf ("\n Available matrix:");
for (j = 1; j <= rno; j++)
{
work[j] += allocated[prc][j];
avail[j] -= allocated[prc][j];
printf ("\n%4d", avail[j]);
}
printf ("\n Working matrix:");
for (j = 1; j <= rno; j++)
{
printf ("\n%4d", work[j]);
}
flag[prc] = 1;
}
t = 0;
for (i = 1; i <= pno; i++)
{
if (flag[i] == 0)
{
t = 1;
break;
}
}
} while (t != 0);
if (count == pno)
{
printf ("\n All processes completed");
}
else
{
printf ("\n There are remaining processes");
}
return 0;
}
Output:
Result:
Date:
AIM:
DESCRIPTION:
Paging is a memory management scheme which permits the physical address space of aprocess
to be noncontiguous. In this scheme physical memory is broken into fixed sizedblocks called
FRAMES. The logical memory is broken into blocks of same size calledPAGES. When a process
is to be executed, its pages are loaded into any available memoryframes from the backing
store.Every address generated by the CPU is divided into two parts
page number( p )
page offset (d )
The size of a page is power of 2 . The selection of power of 2 as the page size makes thetranslation
of logical address into a page number and page offset easy. The size of a page is 2lies between 512
bytes and 16mb per page depending on the computer architecture.When weuse the paging scheme,
we have no external fragmentation.
ALGORITHM:
PROGRAM:
#include<stdio.h>
int main()
{
int ms, ps, nop, np, rempages, i, j, x, y, pa, offset;
int s[10], fno[10][20];
printf("\nEnter the memory size -- ");
scanf("%d",&ms);
printf("\nEnter the page size -- ");
scanf("%d",&ps);
nop = ms/ps;
printf("\nThe no. of pages available in memory are -- %d ",nop);
printf("\nEnter number of processes -- ");
scanf("%d",&np);
rempages = nop;
for(i=1;i<=np;i++)
{
printf("\nEnter no. of pages required for p[%d]-- ",i);
scanf("%d",&s[i]);
if(s[i] >rempages)
{
printf("\nMemory is Full");
break;
}
rempages = rempages - s[i];
printf("\nEnter pagetable for p[%d] --- ",i);
for(j=0;j<s[i];j++)
scanf("%d",&fno[i][j]);
}
printf("\nEnter Logical Address to find Physical Address ");
printf("\nEnter process no. and page number and offset -- ");
scanf("%d %d %d",&x,&y, &offset);
if(x>np || y>=s[x] || offset>=ps)
printf("\nInvalid Process or Page Number or offset");
else
{ pa=fno[x][y]*ps+offset;
printf("\nThe Physical Address is -- %d",pa);
}
}
OUTPUT:
RESULT:
Thus the implementation of paging technique for memory management is executed successfully.
Ex: 4(b)
PAGE REPLACEMENT ALGORITHM
Date: (FIFO)
AIM:
To write a C program to implement Page Replacement technique using FIFO
DESCRIPTION:
FIFO Page Replacement – replaces the oldest page in the memory. The page loaded
first is removed first. FIFO Page replacement algorithm can be implemented using a
FIFO queue. When a page is brought into the memory, we insert it at the tail of the
queue. We replace the page at the head of the queue
ALGORITHM:
1. Start the program.
2. Get the number of pages and their sequence from the user
3. Get the number of available page frames from the user.
4. In FIFO, on the basics of first in first out, replace the pages respectively, then
find number of page faults occurred.
5. Compare all frames with incoming page-
6. If the incoming page is already available in page frame, set the match flag to
indicate ‘no need of page replacement’.
7. If the incoming page is not available in all frames, then remove the page
which is loaded into the memory long back and give space for new incoming
page.
8. Increment the ‘number of Page faults counter
9. Print the number of page faults.
10. Stop the program.
PROGRAM:
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tRef string\t Page Frames\n");
for(i=0;i<n;i++)
{
printf("%d\t\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("\nPage Fault Is %d",count);
return 0;
}
OUTPUT:
RESULT:
Date: (LRU)
AIM:
To write a C program to implement Page Replacement technique using LRU
DESCRIPTION:
LRU page replacement - If we use the recent past as an approximation of the near future,
then we will replace the page that has not been used for the longest period of time. This
approach is the least-recently-used (LRU) algorithm.
LRU replacement associates with each page the time of that page's last use. When a
page must be replaced, LRU chooses that page that has not been used for thelongest
period of time. This strategy is the optimal page-replacement algorithm looking
backward in time, rather thanforward.
The result of applying LRU replacement to our example reference string produces
12 faults. The first faults are the same as the optimal replacement. When the reference
to page 4 occurs, however, LRU replacement sees that, of the three frames in
memory, page 2 was used leastrecently.
The most recently used page is page 0, and just before that page 3 was used. Thus,
the LRU algorithm replaces page 2, not knowing that page 2 is about to be used.
When it then faults for page 2, the LRU algorithm replaces page 3 since, of the
three pages in memory {0, 3, 4}, page 3 is the least recently used. Despite these
problems, LRU replacement with 12 faults is still much better than FIFO replacement
with15.
The LRU policy is often used as a page-replacement algorithm and is considered to
be good. The major problem is how to implement LRUreplacement.
An LRU page-replacement algorithm may require substantial hardware assistance.
The problem is to determine an order for the frames defined by the time of lastuse.
ALGORITHM:.
1. Start the program
2. Get the number of pages and their sequence from theuser
3. Get the number of available page frames from theuser.
4. In LRU replace the page that has not been used for the longest period oftime.
5. Compare all frames with incoming page-
6. If the incoming page is already available in page frame, set the match flag to
indicate ‘no need of page replacement’.
7. If the incoming page is not available in all frames, then remove the page which
has not been used for the longest period oftime.
8. Increment the ‘number of Page faults’ counter
9. Print the number of page faults.
10. Stop the program.
PROGRAM:
#include<stdio.h>
int main()
{
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages: \n");
scanf("%d",&n);
printf("Enter the reference string: \n");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames: \n");
scanf("%d",&f);
q[k]=p[k];
printf("\t\n\t %d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}
if(c1==f)
{
c++;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("\t%d",q[j]);
printf("\n");
}
else
{
for(r=0;r<f;r++)
{
c2[r]=0;
for(j=i-1;j<n;j--)
{
if(q[r]!=p[j])
c2[r]++;
else
break;
}
}
for(r=0;r<f;r++)
b[r]=c2[r];
for(r=0;r<f;r++)
{
for(j=r;j<f;j++)
{
if(b[r]<b[j])
{
t=b[r];
b[r]=b[j];
b[j]=t;
}
}
}
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
}
}
}
printf("\nThe no of page faults is %d",c);
return 0;
}
OUTPUT:
RESULT:
Date: (OPR)
AIM:
To write a C program to implement Page Replacement technique using OPR
DESCRIPTION:
Optimal Replacement- In optimal we do opposite and look for right further most. Now, this is
done so that there are lesser page faults as the element will not use for the longest duration of
time in the future.
The result of the discovery of Belady’sAnamoly
Lowest page fault rate of all algorithm’s and will never suffer from belady’s Anamoly.
Simply it replaces the pages that won’t be used for longest period of time.
Optimal page replacement is perfect, but not possible in practice as operating system
cannot know future requests.
The use of Optimal Page replacement is to set up a benchmark so that other replacement
algorithms can be analyzed against it.
ALGORITHM:
1. Start the program.
2. Take the input of pages as an array.
3. Look for the page allocated is present in near future, if no then replace that page
in the memory with new page,
4. If page already present increment hit, else increment miss.
5. Repeat till we reach the last element of the array.
6. Print the number of hits and misses.
#include<stdio.h>
int main()
{
int i, j, n, a[50], frame[10], no, k, avail, count = 0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d", &n);
printf("\n ENTER THE PAGE NUMBER :\n");
for (i = 1; i <= n; i++)
scanf("%d", &a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d", &no);
for (i = 0; i < no; i++)
frame[i] = -1;
j = 0;
printf("\tref string\t page frames\n");
for (i = 1; i <= n; i++)
{
printf("%d\t\t", a[i]);
avail = 0;
for (k = 0; k < no; k++)
if (frame[k] == a[i])
avail = 1;
if (avail == 0)
{
frame[j] = a[i];
j = (j + 1) % no;
count++;
for (k = 0; k < no; k++)
printf("%d\t", frame[k]);
}
printf("\n");
}
printf("Page Fault Is %d", count);
return 0;
}
OUTPUT:
RESULT:
AIM:
To write a program for the first come first serve method of disc scheduling.
DESCRIPTION:
Disk scheduling is schedule I/O requests arriving for the disk.
It is important because: -
Multiple I/O requests may arrive by different processes and only one I/O request can be served at a time
by the disk controller. Thus other I/O requests need to wait in the waiting queue and need to be
scheduled.
Two or more request may be far from each other so can result in greater disk head movement.
Hard drives are one of the slowest parts of the computer system and thus need to be accessed in an
efficient manner
FCFS is the simplest of all the Disk Scheduling Algorithms. In FCFS, the requests are addressed in the
order they arrive in the disk queue.
Example: Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head
initially at the track 50 and the tail track being at 199.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf ("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
printf("Total head moment is %d",TotalHeadMoment);
return 0;
}
OUTPUT:
RESULT:
Thus the implementation of the program for first come first serve disc scheduling has been
successfully executed.
EX. 5b) DISK SCHEDULING
Date: SHORTEST SEEK TIME FIRST
AIM:
To write a program for the first come first serve method of disc scheduling.
DESCRIPTION:
Shortest seek time first (SSTF) algorithm
Shortest seek time first (SSTF) algorithm selects the disk I/O request which requires the least disk arm
movement from its current position regardless of the direction. It reduces the total seek time as compared
to FCFS.
Example:-: Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head
initially at the track 50 and the tail track being at 199.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
while(count!=n)
{
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{
min=d;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
RQ[index]=1000;
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
OUTPUT:
RESULT:
Thus the implementation of the program for shortest seek time first disc scheduling has beensuccessfully
executed.
EX. 5c) DISK SCHEDULING
Date: SCAN
AIM:
To write a program for the first come first serve method of disc scheduling.
DESCRIPTION:
SCAN
It is also called as Elevator Algorithm. In this algorithm, the disk arm moves into a particular direction
till the end, satisfying all the requests coming in its path, and then it turns backend moves in the reverse
direction satisfying requests coming in its path.
It works in the way an elevator works, elevator moves in a direction completely till the last floor of that
direction and then turns back.
Example:- Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head
initially at the track 50 and the tail track being at 199. head movement is towards low value.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(RQ[j]>RQ[j+1])
{
int temp;
temp=RQ[j];
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
}
}
}
int index;
for(i=0;i<n;i++)
{
if(initial<RQ[i])
{
index=i;
break;
}
}
if(move==1)
{
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
// last movement for max size
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1);
initial = size-1;
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}
else
{
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
initial =0;
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
OUTPUT:
RESULT:
Thus the implementation of the program for SCAN disc scheduling has been successfully executed.
EX. 5d) DISK SCHEDULING
Date: LOOK
AIM:
To write a program for the first come first serve method of disc scheduling.
DESCRIPTION
Look
It is similar to the SCAN disk scheduling algorithm except for the difference that the disk arm in spite of
going to the end of the disk goes only to the last request to be serviced in front of the head and then
reverses its direction from there only. Thus, it prevents the extra delay which occurred due to unnecessary
traversal to the end of the disk.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if(RQ[j]>RQ[j+1])
int temp;
temp=RQ[j];
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
int index;
for(i=0;i<n;i++)
if(initial<RQ[i])
index=i;
break;
}
if(move==1)
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
}
OUTPUT:
RESULT:
Thus the implementation of the program for LOOK disc scheduling has been successfully executed.
EX. 6a)
FILE MANAGEMENT USING SEQUENTIAL ALLOCATION
Date:
AIM:
To implement file management using sequential list.
ALGORITHM:
PROGRAM:
include <stdio.h>
int main() {
int f[50], i, st, len, j, c, k, count = 0;
printf("Do you want to enter more files (Yes - 1/No - 0): ");
scanf("%d", &c);
if (c == 1)
goto x;
return 0;
}
OUTPUT:
RESULT:
Aim:
Description:
Indexed allocation brings all the block pointers together into onelocation: called the
index block.
Each file has its own index block, which is an array of disk-block addresses. The
ith entry in the index block points to the ith block of thefile.
The directory contains the address of the index block (Figure5.8).
To read the ith block, we use the pointer in the ith index-block entry to find and read
the desiredblock.
When the file is created, all pointers in the index block are set to nil. When the ith
block is first written, a block is obtained from the free-space manager, and its address
is put in the ith index-blockentry.
Indexed allocation supports direct access, without suffering from external
fragmentation, because any free block on the disk may satisfy a request for more
space.
If the index block is too small, however, it will not be able to hold enough pointers
for a large file, and a mechanism will have to be available to deal with thisissue:
Linked scheme: An index block is normally one disk block. Thus, it can be read and
written directly by itself. To allow for large files, we may link together several
index blocks.
Multilevel index: A variant of the linked representation is to use a first level index
block to point to a set of second-level index blocks, which in turn point to the file
blocks. To access a block, the operating system uses the first-level index to find
a second-level index block, and that block to find the desired data block. This
approach could be continued to a third or fourth level, depending on the desired
maximum file size.
Program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int f[50], index[50],i, n, st, len, j, c, k, ind,count=0;
for(i=0;i<50;i++)
f[i]=0;
x:printf("Enter the index block: ");
scanf("%d",&ind);
if(f[ind]!=1)
{
printf("Enter no of blocks needed and no of files for the index %d on the disk : \n", ind);
scanf("%d",&n);
}
else
{
printf("%d index is already allocated \n",ind);
goto x;
}
y: count=0;
for(i=0;i<n;i++)
{
scanf("%d", &index[i]);
if(f[index[i]]==0)
count++;
}
if(count==n)
{
for(j=0;j<n;j++)
f[index[j]]=1;
printf("Allocated\n");
printf("File Indexed\n");
for(k=0;k<n;k++)
printf("%d ------- >%d : %d\n",ind,index[k],f[index[k]]);
}
else
{
printf("File in the index is already allocated \n");
printf("Enter another file indexed");
goto y;
}
printf("Do you want to enter more file(Yes - 1/No - 0)");
scanf("%d", &c);
if(c==1)
goto x;
else
exit(0);
return 0;
}
OUTPUT:
RESULT: Thus, file management using Indexed list is implemented successfully.
EX. 6c)
FILE MANAGEMENT USING LINKED ALLOCATION
Date:
Aim:
Description:
Linked allocation solves all problems of contiguous allocation. With linked
allocation, each file is a linked list of disk blocks; the disk blocks may be scattered
anywhere on the disk. The directory contains a pointer to the first and last blocks of
the file.
Each block contains a pointer to the next block. These pointers are not made available
to the user. Thus, if each block is 512 bytes, and a disk address (the pointer) requires
4 bytes, then the user sees blocks of 508bytes.
To create a new file, we simply create a new entry in the directory. With linked
allocation, each directory entry has a pointer to the first disk block of thefile.
This pointer is initialized to nil (the end-of-list pointer value) to signify an empty
file. The size field is also set to 0. A write to the file causes a free block to be found
via the free-space-management system, and this new block is then written to, and is
linked to the end of thefile.
To read a file, we simply read blocks by following the pointers from block to block.
There is no external fragmentation with linked allocation, and any free blockon the
free-space list can be used to satisfy arequest.
The size of a file does not need to be declared when that file is created. A file can
continue to grow as long as free blocks areavailable.
Consequently, it is never necessary to compact diskspace.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
void recursivePart(int pages[]){
int st, len, k, c, j;
printf("Enter the index of the starting block and its length: ");
scanf("%d%d", &st, &len);
k = len;
if (pages[st] == 0){
for (j = st; j < (st + k); j++){
if (pages[j] == 0){
pages[j] = 1;
printf("%d ----- >%d\n", j, pages[j]);
}
else {
printf("The block %d is already allocated \n", j);
k++;
}
}
}
else
printf("The block %d is already allocated \n", st);
printf("Do you want to enter more files? \n");
printf("Enter 1 for Yes, Enter 0 for No: ");
scanf("%d", &c);
if (c==1)
recursivePart(pages);
else
exit(0);
return;
}
int main(){
int pages[50], p, a;
for (int i = 0; i < 50; i++)
pages[i] = 0;
printf("Enter the number of blocks already allocated: ");
scanf("%d", &p);
printf("Enter the blocks already allocated: ");
for (int i = 0; i < p; i++){
scanf("%d", &a);
pages[a] = 1;
}
recursivePart(pages);
return 0;
}
OUTPUT: