Operating System Record
Operating System Record
: 1(a)
Date :
Steps :
1. Grounding oneself can be done by using an antistatic wrist- strap cable to prevent electrostatic
discharge (ESD) which can be deadly to computer electronics. Alternatively, a large metal
body like a radiator can also be touched to discharge oneself.
Install the power supply. Some cases come with the power supply already installed, while others will require to
a. The power supply will usually go near the top or the bottom rear of the case. Can determine where the po
Add components to the motherboard. This is usually easiest to do before installing the motherboard, as the c
wire components:
a. Attach the processor to the motherboard by finding the processor port on the
motherboard's surface. An indicator on CPU and motherboard will show the
correct orientation.
b. Attach RAM to the motherboard by finding the RAM slots and inserting the
RAM appropriately.
c. Attach power supply to the motherboard's power connectors.
d. Locate (but do not attach) the motherboard's hard drive SATA port. Can use
this to connect the hard drive to the motherboard later.
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.
11. 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.
12. 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 of the 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.
Result :
Aim :
Windows 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
9. This brings back to the confirmation page. Click Finish this time.
10
10. Will probably be prompted to download VMware Tools for Linux. Click “Download
and Install” to continue.
13. When all is done will be presented with the Ubuntu login screen. Enter the
password
11
14. Click the clock in the top right to set your time and date settings
15. Once it is set that up, system is up and running with Ubuntu in VMware Player on
the Windows machine.
Result ;
Aim
Scheduling
➢ Gantt chart provides a way of visualizing CPU scheduling and enables to understand better.
➢ Can result in starvation, if processes at beginning of the queue have long bursts.
Algorithm
1. Define an array of structure process with members pid, btime, wtime & ttime.
6. Compute average waiting time awat and average turnaround time atur
10. Stop
PROGRAM:
#include<stdio.h> int
main()
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
printf("P[%d]:",i+1);
scanf("%d",&bt[i]);
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
for(i=0;i<n;i++)
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("nP[%d]tt%dtt%dtt%d",i+1,bt[i],wt[i],tat[i]);
avwt/=i;
avtat/=i;
Turnaround Time:%d",avtat);
return 0;
}
OUTPUT:
RESULT :
Hence the program for cpu scheduling process in first come first serve is implemented and verified
successfully.
EXP 2(B)
FIRST
Aim
To Implement cpu scheduling processes queued according to SJF scheduling Shortest Job
First (SJF)
➢ Process that requires smallest burst time is processed first. ➢ SJF can be
preemptive or non–preemptive
➢ When two processes require same amount of CPU utilization, FCFS is used to break the tie.
➢ Can result in starvation, since long critical processes may not be processed.
Algorithm
1. Define an array of structure process with members pid, btime, wtime & ttime.
4. Sort the processes according to their btime in ascending order. a. If two process have
same btime, then FCFS is used to resolve the tie.
6. Compute wtime and ttime for each process as: a. wtimei+1 = wtimei + btimei b. ttimei
= wtimei + btimei
7. Compute average waiting time awat and average turn around time atur.
11. Stop
PROGRAM:
#include<stdio.h> int
main()
avg_wt,avg_tat;
scanf("%d",&n);
for(i=0;i<n;i++)
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1;
for(i=0;i<n;i++)
pos=i;
for(j=i+1;j<n;j++)
if(bt[j]<bt[pos])
pos=j;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
wt[0]=0;
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;
total=0;
for(i=0;i<n;i++)
tat[i]=bt[i]+wt[i];
total+=tat[i];
avg_tat=(float)total/n;
}
Output:
RESULT:
Hence the program for cpu scheduling process in SHORTEST JOB FIRST is implemented
and verified successfully
EXP 2(C)
Aim
Round Robin
➢ All processes are processed one by one as they have arrived, but in rounds.
➢ Each process cannot take more than the time slice per round.
➢ A process that is yet to complete in a round is preempted after the time slice and put at the
end of the queue.
6. If Bi > TS then process takes more than one round. Therefore turnaround and waiting time
should include the time spent for other remaining processes in the same round.
8. Display the GANTT chart that includes a. order in which the processes were
processed in progression of rounds b. Turnaround time Ti for each process in
progression of rounds.
9. Display the burst time, turnaround time and wait time for each process (in order of
11. Stop
PROGRAM:
#include<stdio.h>
int main()
average_wait_time, average_turnaround_time;
&limit);
x = limit;
printf("Arrival Time:t");
scanf("%d", &arrival_time[i]);
printf("Burst Time:t");
scanf("%d", &burst_time[i]);
temp[i] = burst_time[i];
scanf("%d", &time_quantum);
i = 0; x != 0;)
temp[i] = 0;
counter = 1;
= total + time_quantum;
x--;
printf("nProcess[%d]tt%dtt %dttt %d", i + 1, burst_time[i], total - arrival_time[i],
counter = 0;
if(i == limit - 1)
i = 0;
i++;
else
i = 0;
average_turnaround_time); return 0;
}
OUTPUT:
RESULT:
Hence the program for cpu scheduling process in ROUND ROBBIN is implemented and verified
successfully
EXP 2(D)
Date :
PRIORITY SCHEDULING
Aim
Priority Scheduling:
➢ When two processes have same priority, FCFS is used to break the tie.
➢ Can result in starvation, since low priority processes may not be processed.
Algorithm
1. Define an array of structure process with members pid, btime, pri, wtime & ttime.
4. Sort the processes according to their pri in ascending order. a. If two process have same pri,
then FCFS is used to resolve the tie
6. Compute wtime and ttime for each process as: a. wtimei+1 = wtimei + btimei b. ttimei =
wtimei + btimei
7. Compute average waiting time awat and average turn around time atur
8. Display the btime, pri, ttime and wtime for each process.
11. Stop
PROGRAM
#include<stdio.h> int
main()
scanf("%d",&n);
+)
printf("\nP[%d]\n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
//sorting burst time, priority and process number in ascending order using selection sort
for(i=0;i<n;i++)
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
for(i=1;i<n;i++)
wt[i]=0;
for(j=0;j<i;j++) wt[i]
+=bt[j];
total+=wt[i];
OUTPUT
RESULT:
Hence the program for cpu scheduling process in PRIORITY SCHEDULING is implemented
and verified successfully
Ex.no : 3 A INTER PROCESS COMMUNICATIONS
Date :
Aim:
Program:
#include <stdio.h>
int main()
{ int fd[2],child; char a[10];
printf("\n Enter the
string:"); scanf("%s",a);
pipe(fd); child=fork();
if(!child)
{
close(fd[0]);
write(fd[1],a,5); wait(0);
}
else
{
close(fd[1]);
read(fd[0],a,5); printf("The string received
from pipe is: %s",a);
} return
0;
}
18
Output:
Result:
19
SYSTEMCALLS
(READ & WRITE, CREATE &FORK, OPEN &CLOSE)
Ex: 3 B
Date:
Aim:
Write a 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. 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. 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 close: Tells the
operating system you are done with a file descriptor and Close the file which pointed by fd.
Syntax: int
close(intfd); fd :file descriptor
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 the
file.
Syntax: int read(int fd, char *buf, int
size); fd: file descripter
buf: buffer to read data from cnt: length of buffer write: Writes cnt bytes from buf to the file or
socket associated with fd. cnt should not be greater than INT_MAX (defined in the limits.h
header file). If cnt is zero, write() simply returns 0 without 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:
20
4. The string [] array is write into a file close it.
5. Then the first is opened for read only mode and read the characters and displayed
it and close the file.
6. Use Fork().
7. Stop the program.
21
Program:
#include<fcntl.h>
#include<sys/types.h>
int main() {
f1,f2; char
c,strin[100];
f1=open("data",O_RDWR|O_CREAT|O_TRUNC); while((c=getchar())!='\n')
strin[i++]=c;
fork();
return 0;
}
Output:
22
Result;
Thus, open, read, write, close , create , fork() system calls implemented successfully using c
program.
23
EXP 3(C) BANKER’S ALGORITHM
Date:
Aim:
Description:
The banker’s algorithm is a resource allocation and deadlock avoidance algorithm that tests for safety
by simulating the allocation for predetermined maximum possible amounts of all resources, then makes an “s-
state” check to test for possible activities, before deciding whether allocation should be allowed to continue.
Algorithm:
Program:
#include <stdio.h>
#include <stdlib.h>
void final_output(int k[][10], int n, int p)
{
int i, j;
for (i = 0; i < n; i++)
{
printf("\n");
for (j = 0; j < p; j++)
{
printf("%d\t", k[i][j]);
}
}
}
//Banker's Algorithm
void Banker(int A[][10], int N[][10],
int M[10][10], int W[1][10], int *n, int *m)
{
int i, j;
printf("\n Enter total number of processes : ");
scanf("%d", n);
printf("\n Enter total number of resources : ");
scanf("%d", m);
24
for (i = 0; i < *n; i++)
{
printf("\n Process %d\n", i + 1);
for (j = 0; j < *m; j++)
{
printf(" Allocation for resource %d : ", j + 1);
scanf("%d", &A[i][j]);
printf(" Maximum for resource %d : ", j + 1);
scanf("%d", &M[i][j]);
}
}
printf("\n Available resources : \n");
for (i = 0; i < *m; i++)
{
printf(" Resource %d : ", i + 1);
scanf("%d", &W[0][i]);
}
int i, j, k, x = 0, f1 = 0, f2 = 0;
int F[10], W[1][10];
for (i = 0; i < n; i++)
F[i] = 0;
for (i = 0; i < m; i++)
W[0][i] = B[0][i];
25
{
for (j = 0; j < m; j++)
W[0][j] += A[i][j];
F[i] = 1;
f1++;
a[x++] = i;
}
}
}
if (f1 == n)
return 1;
}
return 0;
}
//Resource Request algorithm
void request(int A[10][10], int N[10][10]
, int B[10][10], int pid, int K)
{
int rmat[1][10];
int i;
printf("\n Enter additional request : \n");
for (i = 0; i < K; i++)
{
printf(" Request for resource %d : ", i + 1);
scanf("%d", &rmat[0][i]);
}
26
printf("\n\n");
printf("\n A safety sequence has been "
"detected.\n");
for (i = 0; i < n; i++)
printf(" P%d ", a[i]);
printf("\n");
return 1;
}
else
{
printf("\n Deadlock has occured.\n");
return 0;
}
}
int main()
{
int All[10][10], Max[10][10], Need[10][10]
, W[1][10];
int n, m, pid, c, r;
printf("\n *********DEADLOCK AVOIDANCE USING"
"BANKER'S ALGORITHM***********\n");
Banker(All, Need, Max, W, &n, &m);
r = banker(All, Need, W, n, m);
if (r != 0)
{
printf("\n Do you want make an additional"
"request for any of the process ? (1=Yes|0=No)");
scanf("%d", &c);
if (c == 1)
{
printf("\n Enter process number : ");
scanf("%d", &pid);
request(All, Need, W, pid - 1, m);
r = banker(All, Need, W, n, m);
if (r == 0)
{
exit(0);
}
}
}
else
exit(0);
return 0;
}
Output:
27
28
Result;
Thus , the banker’s algorithm for deadlock avoidance is implemented successfully using C program.
Description:
In an operating system that uses paging for memory management, a page replacement algorithm is
needed to decide which page needs to be replaced when new page comes in.
Page Fault – A page fault happens when a running program accesses a memory page that is mapped into the
virtual address space, but not loaded in physical memory.
Since actual physical memory is much smaller than virtual memory, page faults happen. In case of page
fault, Operating System might have to replace one of the existing pages with the newly needed page. Different
page replacement algorithms suggest different ways to decide which page to replace. The target for all
algorithms is to reduce the number of page faults.
Algorithm:
Program:
#include<stdio.h>
#define MAX 50
int main()
{
int page[MAX],i,n,f,ps,off,pno;
int choice=0;
printf("\nEnter the no of peges in memory: ");
scanf("%d",&n);
printf("\nEnter page size: ");
scanf("%d",&ps);
printf("\nEnter no of frames: ");
scanf("%d",&f);
for(i=0;i<n;i++)
page[i]=-1;
printf("\nEnter the page table\n");
printf("(Enter frame no as -1 if that page is not present in any frame)\n\n");
printf("\npageno\tframeno\n-------\t-------");
for(i=0;i<n;i++)
{
30
printf("\n\n%d\t\t",i);
scanf("%d",&page[i]);
}
do
{
printf("\n\nEnter the logical address(i.e,page no & offset):");
scanf("%d%d",&pno,&off);
if(page[pno]==-1)
printf("\n\nThe required page is not available in any of frames");
else
printf("\n\nPhysical address(i.e,frame no & offset):%d,%d",page[pno],off);
printf("\nDo you want to continue(1/0)?:");
scanf("%d",&choice);
}while(choice==1);
return 1;
}
Output :
31
Result :
32
EXP 4(B) PAGE REPLACEMENT ALGORITHM
FIFO
Aim:
Algorithm:
1. Get the number of pages and their sequence from theuser
2. Get the number of available page frames from theuser.
3. In FIFO, on the basics of first in first out, replace the pages respectively, then
find number of page faults occurred.
4. Compare all frames with incomingpage-
5. If the incoming page is already available in page frame, set the match flag to
indicate ‘no need of pagereplacement’.
6. 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
incomingpage.
7. Increment the ‘number of Page faults’counter
8. Print the number of pagefaults.
9. Stop theprogram
PROGRAM
main()
number of Pages:\t");
scanf("%d", &pages);
scanf("%d", &referenceString[m]);
scanf("%d", &frames);
int temp[frames];
temp[m] = -1;
s = 0;
if(referenceString[m] == temp[n])
s++;
pageFaults--;
pageFaults++;
temp[m] = referenceString[m];
else if(s == 0)
printf("\n");
printf("%d\t", temp[n]);
}
printf("\nTotal Page Faults:\t%d\n", pageFaults);
return 0;
OUTPUT:
RESULT:
Thus the C program to implement page replacement for first come first serve is
implemented and verified successfully.
EXP 4(C) PAGE REPLACEMENT ALGORITHM
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 the
longest 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. Get the number of pages and their sequence from theuser
2. Get the number of available page frames from theuser.
3. In LRU replace the page that has not been used for the longest period oftime.
4. Compare all frames with incomingpage-
5. If the incoming page is already available in page frame, set the match flag to
indicate ‘no need of pagereplacement’.
6. If the incoming page is not available in all frames, then remove the page which
has not been used for the longest period oftime.
7. Increment the ‘number of Page faults’counter
8. Print the number of pagefaults.
9. Stop theprogram
PROGRAM:
#include<stdio.h>
minimum = time[i];
pos = i;
}
return pos;
int main()
int no_of_frames, no_of_pages, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j, pos,
faults = 0;
scanf("%d", &no_of_frames);
scanf("%d", &no_of_pages);
scanf("%d", &pages[i]);
frames[i] = -1;
if(frames[j] == pages[i]){
counter++; time[j]
= counter;
flag1 = flag2 = 1;
break;
if(flag1 == 0){
if(frames[j] == -1){
counter++;
faults++;
frames[j] = pages[i];
time[j] = counter;
flag2 = 1;
break;
if(flag2 == 0){
counter++;
faults++;
frames[pos] = pages[i];
time[pos] = counter;
printf("\n");
printf("%d\t", frames[j]);
return 0;
OUTPUT:
RESULT:
Thus the C program to implement page replacement for Least recently used is
implemented and verified successfully.
EXP 4(D) PAGE REPLACEMENT ALGORITHM
Aim:
2. Look for the page allocated is present in near future, if no then replace that
page in the memory with new page,
PROGRAM
#include<stdio.h>
int main()
frames_number); printf("Enter
&pages_number); printf("Enter
scanf("%d", &pages[i]);
flag1 = flag2 =
1; break;
if(flag1 == 0){
faults++;
frames[j] =
pages[i]; flag2 = 1;
break;
if(flag2 == 0){
flag3 =0;
if(frames[j] == pages[k]){
temp[j] =
k; break;
pos = j;
flag3 = 1;
break;
if(flag3 ==0){
max = temp[0];
pos = 0;
pos = j;
}
}
frames[pos] =
pages[i]; miss++;
printf("\n");
++j){ printf("%d\t",
frames[j]);
return 0;
OUTPUT
RESULT:
Thus the C program to implement page replacement for Least recently used is
implemented and verified successfully.
EXP 5(A)
DISC SCHEDULING
FIRST COME FIRST SERVE
Date:
AIM:
To Write a C program to perform disc scheduling by first come first serve Method
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.
ALGORITHM:
1. Input the maximum number of work queue and its head starting position.
2. First Come First Serve Scheduling (FCFS) algorithm – The operations are
performed in order requested.
3. There is no reordering of work queue.
4. Every request is serviced, so there is no starvation.
5. The seek time is calculated.
PROGRAM:
#include<stdio.h
>
#include<stdlib.h
int
RQ[100],i,n,TotalHeadMoment=0,initia
Requests\n"); scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scheduling for(i=0;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
initial); initial=RQ[i];
%d",TotalHeadMoment); return 0;
OUTPU
T:
RESULT:
Hence The C program to process disc scheduling by first come first serve process is
implemented and verified successfully.
EXP 5(B)
DISC SCHEDULING
Date:
SHORTEST SEEK TIME FIRST
AIM:
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.
ALGORITHM:
1. Input the maximum number of work queue and its head starting position.
2.Shortest seek time first(sstf)– The operations are performed in order
requested.
3. There is no reordering of work queue.
4. Every request is serviced, so there is no starvation.
5. The seek time is calculated.
PROGRAM:
#include<stdio.h
>
#include<stdlib.h
int
RQ[100],i,n,TotalHeadMoment=0,initial,count=
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
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+mi
n; initial=RQ[index];
number
RQ[index]=1000;
count++;
%d",TotalHeadMoment); return 0;
}
OUTPUT:
RESULT:
Hence The C program to process disc scheduling by first come Shortest seek
time first is written and verified successfully.
EXP 5(C)
DISC SCHEDULING
Date:
SCAN METHOD
AIM:
method 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.
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.
ALGORITHM:
1. Input the maximum number of work queue and its head starting position.
PROGRAM:
#include<stdio.h
>
#include<stdlib.h
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);
array */ 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;
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
initial); initial=RQ[i];
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];
value else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
initial); initial=RQ[i];
}
// last movement for min size
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+
1]-0);
initial =0;
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
initial); initial=RQ[i];
%d",TotalHeadMoment); return 0;
OUTPUT:
RESULT:
Hence The C program to process disc scheduling by SCAN is written and verified
successfully.
EXP 5(D)
DISC SCHEDULING
AIM:
method 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.
ALGORITHM:
1. Input the maximum number of work queue and its head starting
position. 2.LOOK– The operations are performed in order requested.
3. There is no reordering of work queue.
4. Every request is serviced, so there is no starvation.
5. The seek time is calculated.
PROGRAM:
#include<stdio.h
>
#include<stdlib.h
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;
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];
value 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];
}
%d",TotalHeadMoment); return 0;
OUTPUT:
RESULT:
AIM:
DESCRIPTION:
In this allocation strategy, each file occupies a set of contiguously blocks on the disk. This
strategy is best suited. For sequential files, the file allocation table consists of a single entry for
each file. It shows the filenames, starting block of the file and size of the file. The main problem
with this strategy is, it is difficult to find the contiguous free blocks in the disk and some free
blocks could happen between two files
ALGORITHM:
PROGRAM:
#include <stdio.h>
#include <conio.h>
recurse(int files[]){
printf("Enter the starting block and the length of the files: "); scanf("%d
if (files[j] == 0)
flag++;
if(len == flag){
(files[k] == 0){
files[k] = 1; printf("%d\t%d\n",
k, files[k]);
}
}
if (k != (startBlock+len-1))
else
scanf("%d", &ch);
if (ch == 1)
recurse(files);
else
exit(0); return;
int main()
int files[50];
for(int i=0;i<50;i++)
files[i]=0;
printf("Files Allocated are :\n");
recurse(files);
getch();
return 0;
}
OUTPUT:
RESULT:
Hence the C program to implement sequential file allocation is written and
implemented successfully.
EX NO: 6(B)
AIM:
DESCRIPTION:
Indexed allocation supports both sequential and direct access files. The file indexes are not
physically stored as a part of the file allocation table. Whenever the file size increases, we can
easily add some more blocks to the index. In this strategy, the file allocation table contains a
single entry for each file. The entry consisting of one index block, the index blocks having the
pointers to the other blocks. No external fragmentation.
ALGORITHM:
PROGRAM
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void recurse1();
void recurse2();
void recurse1(){
scanf("%d", &indBlock);
if (files[indBlock] != 1){
printf("Enter the number of blocks and the number of files needed for the index %d on the
disk: ", indBlock);
scanf("%d", &n);
else{
recurse2();
void recurse2(){
int ch;
int flag = 0;
scanf("%d", &indexBlock[i]);
if (files[indexBlock[i]] == 0)
flag++;
if (flag == n){
files[indexBlock[j]] = 1;
printf("Allocated\n");
printf("File Indexed\n");
else{
recurse2();
scanf("%d", &ch);
if (ch == 1)
recurse1();
else
exit(0);
return;
int main()
for(int i=0;i<50;i++)
files[i]=0;
recurse1();
return 0;
}
OUTPUT:
RESULT:
Hence the C program to implement indexed file allocation is written and implemented
successfully.
EX NO: 6(C)
INDEXED ALLOCATION
Date:
AIM:
DESCRIPTION:
It is easy to allocate the files because allocation is on an individual block basis. Each
block contains a pointer to the next free block in the chain. Here also the file allocation table
consisting of a single entry for each file. Using this strategy any free block can be added to a
chain very easily. There is a link between one block to another block, that’s why it is said to be
linked allocation. We can avoid the external fragmentation
ALGORITHM:
PROGRAM:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
printf("Enter the index of the starting block and its length: "); scanf("%d
k = len;
if (pages[st] == 0){
if (pages[j] == 0){
pages[j] = 1;
printf("%d----->%d\n", j, pages[j]);
else {
k++;
else
&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;
&p);
scanf("%d", &a);
pages[a] = 1;
recursivePart(pages); getch();
return 0;
}
OUTPUT:
RESULT:
Hence the C program to implement Linked file allocation is written and implemented
successfully.