0% found this document useful (0 votes)
28 views90 pages

Operating System Record

The document describes how to install Ubuntu in VMware Player on a Windows system. It provides steps to download Ubuntu ISO and VMware Player, create a new virtual machine using the ISO, customize hardware settings, install VMware tools, and set the time and date in Ubuntu. Once complete, Ubuntu will be running in a VM on Windows.

Uploaded by

yokheshkumar97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views90 pages

Operating System Record

The document describes how to install Ubuntu in VMware Player on a Windows system. It provides steps to download Ubuntu ISO and VMware Player, create a new virtual machine using the ISO, customize hardware settings, install VMware tools, and set the time and date in Ubuntu. Once complete, Ubuntu will be running in a VM on Windows.

Uploaded by

yokheshkumar97
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 90

Ex.

: 1(a)

ASSEMBLING THE COMPUTER SYSTEM

Date :

Aim :To Assemble the Computer System

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.

2. To Open the case. Unscrew the side


panel (or slide it toward the back of the
case) to do so.

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.

Tip: Some processors that come with heat


sinks do not need thermal paste because
the heat sink already has thermal paste
applied by the factory. Check the bottom
of the heat sink unit before applying paste

6. Attach the heat sink. This varies


from heat sink to heat sink, so
read the instructions for the
processor.
a. Most stock coolers attach
directly over the processor
and clip into the
motherboard.
b. Aftermarket heat sinks may
have brackets that need to
be attached underneath the
motherboard.
c. Skip this step if processor
has an installed heat sink.

7. Prepare the case needs to knock the


plates out of the back of the case in
order to fit the components into the
correct positions.
a. If the case has separate shelving
units to hold the hard drive,
install the units using the included
screws.
b. May need to install and wire the
case's fans before installing any
8. components. If so, follow the case's fan installation instructions.

9. Secure the motherboard. Once the


standoffs are installed, place the
motherboard in the case and push it up
against the backplate. All of the back
ports should fit into the holes in the I/O
backplate.
a. Use the screws provided to secure
the motherboard to the standoffs
through the shielded screw holes on
the motherboard.

10. Plug in the case connectors. These


tend to be located together on the
motherboard near the front of
the case. The order in which these
are connected will depend on
which is easiest. Make sure that
the USB ports are connected, the
Power and Reset switches, the
LED power and hard drive lights,
and the audio cable.The
motherboard’s documentation
will show where on the
motherboard these connectors
attach.
a. There is typically only one
way that these connectors
can attach to the motherboard. Do not try to force anything to fit.

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)

13. Finish the computer assembly. Once


placed and connected the various
internal components for the computer,
all that's left to do is ensure that none of
the wires interfere with circulation and
close up the case.
a. If bought a cooling system,
install it before proceeding.
Refer to the cooling system's
installation instructions in order
to do so.
b. Many cases will have a panel
which either slides back into
place or screws onto the side of
the case.

RUNNING THE COMPUTER

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 :

The Computer System has been successfully assembled


Ex: 1 (b)

Installing Ubuntu in VMware Player on Windows


Date:

Aim :

To Install Ubuntu in VMware Player on

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:

3. Select “Create a New Virtual Machine”

4. Select “Installer disc image file” and browse to the Ubuntu iso
downloaded. Click next

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.

7. This brings to the confirmation page. Click “Customize Hardware”


8. In the hardware options section select the amount of memory wanted by the VM
to use. Click Close.

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.

11. Wait for it to install

12. Ubuntu will then start to install

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 ;

Ubuntu in VMware Player on Windows has been installed successfully


EXP 2(A)

CPU Scheduling Algorithms

Date: FIRST COME FIRST SERVE

Aim

To Implement cpu scheduling processes queued according to FCFS scheduling Process

Scheduling

➢ CPU scheduling is used in multiprogrammed operating systems.

➢ By switching CPU among processes, efficiency of the system can be improved.

➢ Some scheduling algorithms are FCFS, SJF, Priority, Round-Robin, etc.

➢ Gantt chart provides a way of visualizing CPU scheduling and enables to understand better.

First Come First Serve (FCFS)

➢ Process that comes first is processed first

➢ FCFS scheduling is non-preemptive

➢ Not efficient as it results in long average waiting time.

➢ 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.

2. Get length of the ready queue, i.e., number of process (say n)

3. Obtain btime for each process.

4. The wtime for first process is 0.

5. Compute wtime and ttime for each process as:


a. wtimei+1 = wtimei + btimei

b. ttimei = wtimei + btimei

6. Compute average waiting time awat and average turnaround time atur

7. Display the btime, ttime and wtime for each process.

8. Display GANTT chart for the above scheduling

9. Display awat time and atur

10. Stop

PROGRAM:

#include<stdio.h> int

main()

int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;

printf("Enter total number of processes(maximum 20):");

scanf("%d",&n);

printf("nEnter Process Burst Timen");

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];

printf("nProcessttBurst TimetWaiting TimetTurnaround Time");

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;

printf("nnAverage Waiting Time:%d",avwt); printf("nAverage

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)

CPU Scheduling Algorithms

Date : SHORTEST JOB

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.

➢ Generally efficient as it results in minimal average waiting time.

➢ 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.

2. Get length of the ready queue, i.e., number of process (say n)

3. Obtain btime for each process.

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.

5. The wtime for first process is 0.

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 btime, ttime and wtime for each process.

9. Display GANTT chart for the above scheduling

10. Display awat and atur

11. Stop
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;

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;

printf("nProcess\t Burst Time \tWaiting Time\t Turnaround Time");

for(i=0;i<n;i++)

tat[i]=bt[i]+wt[i];

total+=tat[i];

printf("np%dtt %dtt %dttt%d",p[i],bt[i],wt[i],tat[i]);

avg_tat=(float)total/n;

printf("nnAverage Waiting Time=%f",avg_wt);

printf("nAverage Turnaround Time=%fn",avg_tat);

}
Output:

RESULT:

Hence the program for cpu scheduling process in SHORTEST JOB FIRST is implemented
and verified successfully
EXP 2(C)

CPU Scheduling Algorithms


Date :
ROUND ROBBIN

Aim

To Implement cpu scheduling processes queued according to RR scheduling

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.

➢ Round robin is a fair preemptive scheduling algorithm.

➢ A process that is yet to complete in a round is preempted after the time slice and put at the
end of the queue.

➢ When a process is completely processed, it is removed from the queue.


Algorithm

1. Get length of the ready queue, i.e., number of process (say n)

2. Obtain Burst time Bi for each processes Pi.

3. Get the time slice per round, say TS

4. Determine the number of rounds for each process.

5. The wait time for first process is 0.

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.

7. Calculate average waiting time and turn around time

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

rounds they were processed).

10. Display average wait time and turnaround time

11. Stop

PROGRAM:

#include<stdio.h>

int main()

int i, limit, total = 0, x, counter = 0, time_quantum;

int wait_time = 0, turnaround_time = 0, arrival_time[10], burst_time[10], temp[10]; float

average_wait_time, average_turnaround_time;

printf("nEnter Total Number of Processes:t"); scanf("%d",

&limit);

x = limit;

for(i = 0; i < limit; i++)

printf("nEnter Details of Process[%d]n", i + 1);

printf("Arrival Time:t");

scanf("%d", &arrival_time[i]);
printf("Burst Time:t");

scanf("%d", &burst_time[i]);

temp[i] = burst_time[i];

printf("nEnter Time Quantum:t");

scanf("%d", &time_quantum);

printf("nProcess IDttBurst Timet Turnaround Timet Waiting Timen"); for(total = 0,

i = 0; x != 0;)

if(temp[i] <= time_quantum && temp[i] > 0)

total = total + temp[i];

temp[i] = 0;

counter = 1;

else if(temp[i] > 0)

temp[i] = temp[i] - time_quantum; total

= total + time_quantum;

if(temp[i] == 0 && counter == 1)

x--;
printf("nProcess[%d]tt%dtt %dttt %d", i + 1, burst_time[i], total - arrival_time[i],

total - arrival_time[i] - burst_time[i]);

wait_time = wait_time + total - arrival_time[i] - burst_time[i];

turnaround_time = turnaround_time + total - arrival_time[i];

counter = 0;

if(i == limit - 1)

i = 0;

else if(arrival_time[i + 1] <= total)

i++;

else

i = 0;

average_wait_time = wait_time * 1.0 / limit; average_turnaround_time =

turnaround_time * 1.0 / limit; printf("nnAverage Waiting Time:t%f",

average_wait_time); printf("nAvg Turnaround Time:t%fn",

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)

CPU Scheduling Algorithms

Date :
PRIORITY SCHEDULING

Aim

To Implement cpu scheduling processes queued according to PRIORITY SCHEDULING


scheduling

Priority Scheduling:

➢ Process that has higher priority is processed first

. ➢ Prioirty can be preemptive or non–preemptive’

➢ 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.

2. Get length of the ready queue, i.e., number of process (say n)

3. Obtain btime and pri for each process.

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

. 5. The wtime for first process is 0.

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.

9. Display GANTT chart for the above scheduling


10. Display awat and atur

11. Stop

PROGRAM

#include<stdio.h> int

main()

int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat; printf("Enter

Total Number of Process:");

scanf("%d",&n);

printf("\nEnter Burst Time and Priority\n"); for(i=0;i<n;i+

+)

printf("\nP[%d]\n",i+1);

printf("Burst Time:");

scanf("%d",&bt[i]);

printf("Priority:");

scanf("%d",&pr[i]);

p[i]=i+1; //contains process number

//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;

wt[0]=0; //waiting time for first process is 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=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\t%d",p[i],bt[i],wt[i],tat[i]);

avg_tat=total/n; //average turnaround time printf("\n\

nAverage Waiting Time=%d",avg_wt); printf("\nAverage

Turnaround Time=%d\n",avg_tat); return 0;

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:

Write C program to illustrate IPC using pipes mechanisms.

Algorithm: IPC using pipes:

1. Create a child process using fork()


2. Create a simple pipe with C, we make use of the pipe() systemcall.
3. Create two file descriptor fd[0] is set up for reading, fd[1] is set up for writing
4. Close the read end of parent process using close() and perform write operation
5. Close the write end of child process and perform reading
6. Display the text.

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:

Thus, IPC using pipes mechanisms is illustrated using c program successfully.

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:

1. Start the program.


2. Open a file for O_RDWR for R/W,O_CREATE for creating a file ,O_TRUNC
for truncate a file.
3. Using getchar(), read the character and stored in the string[]
array.

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() {

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:

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:

To write a C program to implement banker’s algorithm for deadlock avoidance.

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:

1. Start the program.


2. Declare the memory for the process.
3. Read the number of process, resources, allocation matrix and available matrix.
4. Compare each and every process using the banker’s algorithm.
5. If the process is in safe state then it is a not a deadlock process otherwise it is a
deadlock process
6. Produce the result of state of process
7. Stop the program

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]);
}

for (i = 0; i < *n; i++)


for (j = 0; j < *m; j++)
N[i][j] = M[i][j] - A[i][j];

printf("\n ********Allocation Matrix**********");


final_output(A, *n, *m);
printf("\n ********Maximum Requirement Matrix"
"*********");
final_output(M, *n, *m);
printf("\n ***********Need Matrix*********");
final_output(N, *n, *m);
}
//Safety algorithm
int safety(int A[][10], int N[][10],
int B[1][10], int n, int m, int a[])
{

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];

for (k = 0; k < n; k++)


{
for (i = 0; i < n; i++)
{
if (F[i] == 0)
{
f2 = 0;
for (j = 0; j < m; j++)
{
if (N[i][j] > W[0][j])
f2 = 1;
}
if (f2 == 0 && F[i] == 0)

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]);
}

for (i = 0; i < K; i++)


if (rmat[0][i] > N[pid][i])
{
printf("\n ******Error encountered******\n");
exit(0);
}

for (i = 0; i < K; i++)


if (rmat[0][i] > B[0][i])
{
printf("\n ******Resources unavailable*****\n");
exit(0);
}

for (i = 0; i < K; i++)


{
B[0][i] -= rmat[0][i];
A[pid][i] += rmat[0][i];
N[pid][i] -= rmat[0][i];
}
}
int banker(int A[][10], int N[][10],
int W[1][10], int n, int m)
{
int j, i, a[10];
j = safety(A, N, W, n, m, a);
if (j != 0)
{

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.

EXP 4(A) PAGING


Date:
29
Aim:

To write a C program to implement paging concept.

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:

1. Start the program.


2. Declare the array to store the pages.
3. Read the number of process, resources, allocation matrix and available matrix.
4. If the page is not present, then enter as -1.
5. Enter the required logical address and physical address to find the page.
6. Stop the program

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 :

Thus , the paging concept is implemented successfully using C program.

32
EXP 4(B) PAGE REPLACEMENT ALGORITHM

Date: FIRST IN FIRST OUT

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. 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

#include <stdio.h> int

main()

int referenceString[10], pageFaults = 0, m, n, s, pages, frames; printf("\nEnter the

number of Pages:\t");

scanf("%d", &pages);

printf("\nEnter reference string values:\n"); for

(m=0; m < pages; m++)

printf("Value No. [%d]:\t", m + 1);

scanf("%d", &referenceString[m]);

printf("\n What are the total number of frames:\t");

scanf("%d", &frames);

int temp[frames];

for(m = 0; m < frames; m++)

temp[m] = -1;

for(m = 0; m < pages; m++)


{

s = 0;

for(n = 0; n < frames; n++)

if(referenceString[m] == temp[n])

s++;

pageFaults--;

pageFaults++;

if((pageFaults <= frames) && (s == 0))

temp[m] = referenceString[m];

else if(s == 0)

temp[(pageFaults - 1) % frames] = referenceString[m];

printf("\n");

for(n = 0; n < frames; 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

LEAST RECENTLY USED


Date :

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>

int findLRU(int time[], int n){

int i, minimum = time[0], pos = 0;

for(i = 1; i < n; ++i){

if(time[i] < minimum){

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;

printf("Enter number of frames: ");

scanf("%d", &no_of_frames);

printf("Enter number of pages: ");

scanf("%d", &no_of_pages);

printf("Enter reference string: ");

for(i = 0; i < no_of_pages; ++i){

scanf("%d", &pages[i]);

for(i = 0; i < no_of_frames; ++i){

frames[i] = -1;

for(i = 0; i < no_of_pages; ++i){


flag1 = flag2 = 0;

for(j = 0; j < no_of_frames; ++j){

if(frames[j] == pages[i]){

counter++; time[j]

= counter;

flag1 = flag2 = 1;

break;

if(flag1 == 0){

for(j = 0; j < no_of_frames; ++j){

if(frames[j] == -1){

counter++;

faults++;

frames[j] = pages[i];

time[j] = counter;

flag2 = 1;

break;

if(flag2 == 0){

pos = findLRU(time, no_of_frames);

counter++;
faults++;

frames[pos] = pages[i];

time[pos] = counter;

printf("\n");

for(j = 0; j < no_of_frames; ++j){

printf("%d\t", frames[j]);

printf("\n\nTotal Page Faults = %d", faults);

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

OPTIMAL PAGE REPLACEMENT


Date:

Aim:

To write a C program to implement Page Replacement technique using


Optimal page replacement.
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.

1. Take the input of pages as an array.

2. Look for the page allocated is present in near future, if no then replace that
page in the memory with new page,

3. If page already present increment hit, else increment miss.


4. Repeat till we reach the last element of the array.

5. Print the number of hits and misses.

PROGRAM

#include<stdio.h>

int main()

int frames_number, pages_number, frames[10], pages[30], temp[10], flag1,


flag2, flag3, i, j, k, pos, max,faults, miss = 0;

printf("Enter number of frames:

"); scanf("%d", &

frames_number); printf("Enter

number of pages: "); scanf("%d",

&pages_number); printf("Enter

page reference string: "); for(i = 0;

i < pages_number; ++i){

scanf("%d", &pages[i]);

for(i = 0; i < frames_number; +

+i){ frames[i] = -1;

for(i = 0; i < pages_number; ++i){


flag1 = flag2 = 0;

for(j = 0; j < frames_number;

++j){ if(frames[j] == pages[i]){

flag1 = flag2 =

1; break;

if(flag1 == 0){

for(j = 0; j < frames_number;

++j){ if(frames[j] == -1){

faults++;

frames[j] =

pages[i]; flag2 = 1;

break;

if(flag2 == 0){

flag3 =0;

for(j = 0; j < frames_number; +

+j){ temp[j] = -1;


for(k = i + 1; k < pages_number; ++k){

if(frames[j] == pages[k]){

temp[j] =

k; break;

for(j = 0; j < frames_number;

++j){ if(temp[j] == -1){

pos = j;

flag3 = 1;

break;

if(flag3 ==0){

max = temp[0];

pos = 0;

for(j = 1; j < frames_number; ++j){ if(temp[j] >

max){ max = temp[j];

pos = j;

}
}

frames[pos] =

pages[i]; miss++;

printf("\n");

for(j = 0; j < frames_number;

++j){ printf("%d\t",

frames[j]);

printf("\n\nTotal Page miss = %d", miss);

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 main()

int

RQ[100],i,n,TotalHeadMoment=0,initia

l; 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);

// logic for FCFS disk

scheduling for(i=0;i<n;i++)

TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-
initial); initial=RQ[i];

printf("Total head moment is

%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:

To Write a C program to perform disc scheduling by SSTF method

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.

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 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);

// logic for sstf disk scheduling

/* loop will execute until all process is completed*/

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];

// 1000 is for max

// you can use any

number

RQ[index]=1000;

count++;

printf("Total head movement is

%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:

To Write a C program to perform Scan

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.

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.

ALGORITHM:
1. Input the maximum number of work queue and its head starting position.

2.SCAN– 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 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);

// logic for Scan disk scheduling

/*logic for sort the request

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;

// if movement is towards high value


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];

// if movement is towards low

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];

printf("Total head movement is

%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

Date: LOOK METHOD

AIM:

To Write a C program to perform LOOK

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 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);

// logic for look disk scheduling


/*logic for sort the request 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;

// if movement is towards high value


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];

// if movement is towards low

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];
}

printf("Total head movement is

%d",TotalHeadMoment); return 0;

OUTPUT:

RESULT:

Hence The C program to process disc scheduling by LOOK is written and


verified successfully.
EX NO: 6(A)

FILE ALOCATION METHOD

Date: SEQUENTIAL ALLOCATION

AIM:

To write a C program to implement SEQUENTIAL FILE ALLOCATION.

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:

1. Start the program.


2. Gather information about the number of files.
3. Gather the memory requirement of each file.
4. Allocate the memory to the file in a sequential manner.
5. Select any random location from the available location.
6. Check if the location that is selected is free or not.
7. If the location is allocated set the flag = 1.
8. Print the file number, length, and the block allocated.
9. Gather information if more files have to be stored.
10. If yes, then go to STEP 2.
11. If no, Stop the program.

PROGRAM:

#include <stdio.h>

#include <conio.h>

#include <stdlib.h> void

recurse(int files[]){

int flag = 0, startBlock, len, j, k, ch;

printf("Enter the starting block and the length of the files: "); scanf("%d

%d", &startBlock, &len);

for (j=startBlock; j<(startBlock+len); j++){

if (files[j] == 0)

flag++;

if(len == flag){

for (int k=startBlock; k<(startBlock+len); k++){ if

(files[k] == 0){

files[k] = 1; printf("%d\t%d\n",

k, files[k]);

}
}

if (k != (startBlock+len-1))

printf("The file is allocated to the disk\n");

else

printf("The file is not allocated to the disk\n");

printf("Do you want to enter more files?\n");

printf("Press 1 for YES, 0 for NO: ");

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)

FILE ALLOCATION METHOD


Date:
INDEXED ALLOCATION

AIM:

To write a C program to implement INDEXED FILE ALLOCATION

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:

1. Start the program


2. Get information about the number of files.
3. Get the memory requirement of each file.
4. Allocate the memory to the file by selecting random locations.
5. Check if the location that is selected is free or not.
6. If the location is allocated set the flag = 1, and if free set flag = 0.
7. Print the file number, length, and the block allocated.
8. Gather information if more files have to be stored.
9. If yes, then go to STEP 2.
10. If no, Stop the program.

PROGRAM
#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

int files[50], indexBlock[50], indBlock, n;

void recurse1();

void recurse2();

void recurse1(){

printf("Enter the index block: ");

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{

printf("%d is already allocated\n", indBlock);


recurse1();

recurse2();

void recurse2(){

int ch;

int flag = 0;

for (int i=0; i<n; i++){

scanf("%d", &indexBlock[i]);

if (files[indexBlock[i]] == 0)

flag++;

if (flag == n){

for (int j=0; j<n; j++){

files[indexBlock[j]] = 1;

printf("Allocated\n");

printf("File Indexed\n");

for (int k=0; k<n; k++){

printf("%d-----> %d : %d\n", indBlock, indexBlock[k], files[indexBlock[k]]);

else{

printf("File in the index is already allocated\n");


printf("Enter another indexed file\n");

recurse2();

printf("Do you want to enter more files?\n");

printf("Enter 1 for Yes, Enter 0 for No: ");

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)

FILE ALLOCATION METHOD

INDEXED ALLOCATION
Date:

AIM:

To write a C program to implement SEQUENTIAL FILE ALLOCATION.

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:

1. Start the program.

2. Gather information about the number of files.

3. Allocate random locations to the files.


4. Check if the location that is selected is free or not.
5. If the location is free set the flag=0 a location is allocated set the flag
= 1.
6. Print the file number, length, and the block allocated.
7. Gather information if more files have to be stored.
8. If yes, then go to STEP 2.
9. If no, Stop the program.

PROGRAM:

#include <stdio.h>

#include <conio.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); getch();

return 0;
}
OUTPUT:

RESULT:
Hence the C program to implement Linked file allocation is written and implemented
successfully.

You might also like