0% found this document useful (0 votes)
33 views82 pages

Operating Systems

operating systems refence material2

Uploaded by

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

Operating Systems

operating systems refence material2

Uploaded by

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

lOMoARcPSD|50491148

OS LAB Manual

Operating Systems (Anna University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by jayasree m ([email protected])
lOMoARcPSD|50491148

CS8461 OPERATING SYSTEM LABORATORY

LAB MANUAL

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

CS8461 OPERATING SYSTEMS LABORATORY LTPC 0 042

OBJECTIVES

 To learn Unix commands and shell programming


 To implement various CPU Scheduling Algorithms
 To implement Process Creation and Inter Process Communication.
 To implement Deadlock Avoidance and Deadlock Detection Algorithms
 To implement Page Replacement Algorithms
 To implement File Organization and File Allocation Strategies

LIST OF EXPERIMENTS

1. Basics of UNIX commands


2. Write programs using the following system calls of UNIX operating system fork, exec, getpid,
exit, wait, close, stat, opendir, readdir
3. Write C programs to simulate UNIX commands like cp, ls, grep, etc.
4. Shell Programming
5. Write C programs to implement the various CPU Scheduling Algorithms
6. Implementation of Semaphores
7. Implementation of Shared memory and IPC
8. Bankers Algorithm for Deadlock Avoidance
9. Implementation of Deadlock Detection Algorithm
10. Write C program to implement Threading & Synchronization Applications
11. Implementation of the following Memory Allocation Methods for fixed partition
a) First Fit b) Worst Fit c) Best Fit
12. Implementation of Paging Technique of Memory Management
13. Implementation of the following Page Replacement Algorithms
a) FIFO b) LRU c) LFU
14. Implementation of the various File Organization Techniques
15. Implementation of the following File Allocation Strategies
a) Sequential b) Indexed c) Linked
TOTAL: 60 PERIODS
OUTCOMES:

At the end of the course, the student should be able to

 Compare the performance of various CPU Scheduling Algorithms


 Implement Deadlock avoidance and Detection Algorithms
 Implement Semaphores
 Create processes and implement IPC
 Analyze the performance of the various Page Replacement Algorithms
 Implement File Organization and File Allocation Strategies

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex. No.: 1 BASIC UNIX COMMANDS

Aim:

To study and execute the commands in Unix.


Basic Commands:

Command Example Description


ls Lists files in current directory
Ls
ls –alF List in long format
cd tempdir Change directory to tempdir
Cd cd .. Move back one directory
cd ~dhyatt/web-docs Move into dhyatt's web-docs directory
mkdir mkdir graphics Make a directory called graphics
rmdir rmdir emptydir Remove directory (must be empty)
cp file1 web-docs Copy file into directory
Cp
cp file1 file1.bak Make backup of file1
rm file1.bak Remove or delete file
Rm
rm *.tmp Remove all file
Mv mv old.html new.html Move or rename files
more more index.html Look at file, one page at a time
Lpr lpr index.html Send file to printer
Man man ls Online manual (help) about command

Valuable UNIX Commands:

Command Example Description


grep <str><files> grep "bad word" * Find which files contain a certain word
chmod 644 *.html Change file permissions read only
chmod <opt><file>
chmod 755 file.exe Change file permissions to executable
Passwd Passwd Change passwd
ps aux List all running processes by #ID
ps <opt>
ps aux | grep dhyatt List process #ID's running by dhyatt
kill <opt><ID> kill -9 8453 Kill process with ID #8453
gcc file.c -o file Compile a program written in C
gcc (g++) <source>
g++ fil2.cpp -o fil2 Compile a program written in C++
gzip bigfile Compress file
gzip <file>
gunzip bigfile.gz Uncompress file
mail
Send file1 by email to someone
mail (pine) [email protected] < file1
Read mail using pine
pine
telnet vortex.tjhsst.edu Open a connection to vortex
telnet <host>
ssh -l dhyatt Open a secure connection to jazz as user
ssh <host>
jazz.tjhsst.edu dhyatt
ftp <host> ftp station1.tjhsst.edu Upload or Download files to station1
ncftp <host/directory> ncftp metalab.unc.edu Connect to archives at UNC

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

User UNIX Commands:

Command Example Description


Who Who Lists who is logged on your machine
Finger Finger Lists who is on computers in the lab
ytalk <user@place> ytalk dhyatt@threat Talk online with dhyatt who is on threat
History History Lists commands you've done recently
Fortune Fortune Print random humerous message
Date Date Print out current date
cal <mo><yr> cal 9 2000 Print calendar for September 2000
Xeyes xeyes & Keep track of cursor (in "background")
Xcalc xcalc & Calculator ("background" process)
Print 8 pages on a single sheet and send to
mpage <opt><file> mpage -8 file1 | lpr
printer (the font will be small!)

Result

Thus the study of basic UNIX commands has been executed successfully.

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No:2 System calls of UNIX operating system.


AIM:

To write a program using the following system calls of UNIX operating system fork, exec, getpid, exit,
wait, close, stat, opendir, readdir

ALGORITHM:

1)Start

2)Declare the ‘pid’ and get the pid value using getpid() method.

3)Create the child process by using the fork() system call.

4)Check if pid<0 then print the process failed.

5)Else if pid=0 then print parent process value otherwise print the id of child process.

6)Stop the program.

Coding:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
void main(intargc,char *arg[])
{
intpid;
pid=fork();
if(pid<0)
{
printf("fork failed");
exit(1);
}
else if(pid==0)
{
execlp("whoami","ls",NULL);
exit(0);
}
else
{
printf("\n Process id is -%d\n",getpid());
wait(NULL);
exit(0);
}
}
OUTPUT:
Cc fork.c
./a.out

THE CHILD PROCESS ID IS 8640


THE PARENT PROCESS ID IS 8644

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.: 2b SYSTEM CALLS OF UNIX OPERATING SYSTEM

Aim:

To write a C program to invoke system calls(readdir(), opendir(), closedir())

Algorithm:

Step 1: Start the program.

Step 2: Open a file for O_RDWR for R/W,O_CREATE for creating a file ,O_TRUNC for truncate a file.

Step 3: Using getchar(), read the character and stored in the string[] array.

Step 4: The string [] array is write into a file close it.

Step 5: Then the first is opened for read only mode and read the characters and displayed it and close the
file.

Step 6: Stop the program.

Coding:

#include<stdio.h>
#include<dirent.h>
struct dirent *dptr;
int main(int argc, char *argv[])
{
char buff[256];
DIR *dirp;
printf("\n\n Enter directory Name");
scanf("%s",buff);
if((dirp=opendir(buff))==NULL)
{
printf("Error");
exit(1);
}
while(dptr=readdir(dirp))
{
printf("%s\n",dptr->d_name);
} closedir(dirp);
}
Output:
Enter directory Name
inf
in
eng

Result:

Thus the invoking system calls of readdir(), opendir(), closedir() has been successfully executed and
completed

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:2b SYSTEM CALLS OF UNIX OPERATING SYSTEM


Aim:

To write a c program to implement the file operation using i/o system calls

Algorthim:

Step1: Include the header file.

Step2: Create a file.

Step3: Get the keyboard i/p from the user.

Step4: Write contents of file.

Step5: While reading contents, if a new line character occurs, increase the number of lines.

Step6: Similar steps are followed for character increment also.

Step7: End program.

Coding:

#include<fcntl.h>
#include<stdio.h>
#include<string.h>
int main()
{
int fd,sz;
char buffer[50];
fd=open("info9",O_WRONLY|O_TRUNC);
if(fd<0)
{
printf("ERROR");
scanf("%s",buffer);
sz=write(fd,buffer,strlen(buffer));
close(fd);
}
}

Output:
[user@linuxserver ~]$ ./a.out
information
[user@linuxserver ~]$ cat info9
information

Result:

Thus the file operations of I/O system calls has been successfully executed and completed.
8

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No:3a SIMULATION OF UNIX COMMANDS

Aim:

To write a program to simulate UNIX commands like cp, ls, grep using UNIX operating system

Algorithm:

Step 1 : Start

Step 2: Use O_CREATE for creating a file ,O_RDWR for opening in read and write mode and
O_TRUNC for truncating a file.

Step 3: Create an array for storing the characters of the string.

Step 4: Read the characters using getchar() method.

Step 5: Write the stored array in the file and close it.

Step 6: Then open the file in read only mode and display the file.

Step7: Stop.

Coding:

#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<fcntl.h>
main( )
{
int fd[2];
char buf1[25]= "just a test\n";
char buf2[50];
fd[0]=open("file1",O_RDWR);
fd[1]=open("file2",O_RDWR);
write(fd[0], buf1, strlen(buf1));
printf("\n Enter the text now….");
scanf("\n %s",buf1);
printf("\n Cat file1 is \n hai");
write(fd[0], buf1, strlen(buf1));
lseek(fd[0], SEEK_SET, 0);
read(fd[0], buf2, sizeof(buf1));
write(fd[1], buf2, sizeof(buf2));
close(fd[0]);
close(fd[1]);
printf("\n");
return 0;
}
SIMULATE LS COMMAND
The ls command lists all the contents of the directory including filse and sub-directories. The
following c program in simulates the ls command.
9

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

#include<stdio.h>
#include<dirent.h>
#include<stdlib.h>
int main()
{
char dirname[10];
DIR*p;
struct dirent *d;
printf("Enter directory name\n");
scanf("%s",dirname);
p=opendir(dirname);
if(p==NULL)
{
perror("Cannot find directory");
exit(-1);
}
while(d=readdir(p))
printf("%s\n",d->d_name);
return 0;
}

Simulation Of Grep Command In Linux

#include<stdio.h>
#include<string.h>
void main()
{
char fn[10],pat[10],temp[200];
FILE *fp;
printf("Enter file name\n");
scanf("%s",fn);
printf("Enter pattern to be searched\n");
scanf("%s",pat);
fp=fopen(fn,"r");
while(!feof(fp))
{
fgets(temp,1000,fp);
if(strstr(temp,pat))
printf("%s",temp);
}
fclose(fp);
}

10

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex. No.4a SHELL PROGRAMMING

Aim:

To write a program for factorial using shell script.

Algorithm:

Step 1: Start the program

Step 2: Read the value of n

Step 3 : Execute begin


(* test for stopping state *)
if n <= 0 then
factorial := 1
else
factorial := n * factorial(n - 1)
Step 4: Display the result
Step 5: Stop the program

Coding

echo " Enter the number for which factorial is to be found "
read n
f=1
a=0
i=1
if [ $n -eq $a ]
then
echo $f
else
while [ $i -le $n ]
do
f=`expr $f \* $i`
i=`expr $i + 1`
done
fi
echo " The factorial of the number is "
echo $f

Output:

[user@localhost shell]$sh fact.sh


Enter the number for which factorial is to be found
5
The factorial of the number is
120

Result:

Thus the program for factorial using shell script has been executed and verified successfully.
11

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex. No.4b SHELL PROGRAMMING

Aim:

To write a program for Fibonacci series using shell script

Algorithm:

Step 1: Start the program

Step 2: Declare the variables and initialize the variables, a=0, b=1, and show =0
Step 3: Enter the number of terms of Fibonacci series to be printed
Step 4: Print first two terms of series
Step 5: Using loop for the following steps
show=a+b
a=b
b=show
increase value of i each time by 1
print the value of show
Step 6 : Stop the program.

Coding:

echo "Enter the number"


read n
i=1
a=-1
fib=0
b=1
echo "Fibonacci series is"
while [ $i -lt $n ]
do
fib=`expr $a + $b`
a=$b
b=$fib
echo $fib
i=`expr $i + 1`
done

12

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:

[user@localhost shell]$ sh fib.sh


Enter the number
8
Fibonacci series is
0
1
1
2
3
5
8

Result:

Thus the program for Fibonacci series using shell script has been executed and verified
successfully.

13

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex. No. 5a CPU SCHEDULING ALGORITHM – ROUND ROBIN

Aim:

To write a c program to implement the scheduling algorithm round-robin.

Algorithm:

Step 1: Start the process

Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice

Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time

Step 4: Calculate the no. of time slices for each process where

No. of time slice for process (n) = burst time process(n)/time slice

Step 5: If the burst time is less than the time slice then the no. of time slices =1.

Step 6: Calculate Average waiting time = Total waiting Time / Number of process

and Average Turnaround time = Total Turnaround Time / Number of process

Step 7: Stop the process

Coding:

#include<stdio.h>
int main()
{
int bursttime[10][10],bt[10][10];
int i,j,nop,k=0,tq,sum=0;
float avg;
printf("\nEnter the Number of processes:");
scanf("%d",&nop);
printf("\n\tEnter the time quantum;");
scanf("%d",&tq);
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
bursttime[i][j]=0;
bt[i][j]=0;
}
for(i=0;i<nop;i++)
{ j=0;
printf("\n\tEnter the process time for process %d;",i+1);
scanf("%d",&bursttime[i][j]);}
for(j=0;j<10;j++)
for(i=0;i<nop;i++)
{
bt[2*j][i]=k;
if((bursttime[i][j]<=tq)&&(bursttime[i][j]!=0))
14

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

{
k=k+bursttime[i][j];
bt[2*j+1][i]=k;
}
else if(bursttime[i][j]!=0)
{
bursttime[i][j+1]=bursttime[i][j]-tq;
k=k+tq;
bt[2*j+1][i]=k;
}
else
{
bt[2*j][i]=0;
bt[2*j+1][i]=0;
} }
for(i=0;i<nop;i++)
sum=sum+bt[0][i];
for(i=0;i<nop;i++)
for(j=1;j<10;j++)
{
if((bt[j][i]!=0)&&(bt[j+1][i]!=0)&&((j+1)%2==0))
{
sum=sum+((bt[j+1][i]-bt[j][i]));
} }
avg=(float)sum/nop;
printf("\n\n\t\tAverage waiting time:%0.2f millisecs",avg);
sum=avg=0;
for(j=0;j<nop;j++)
{
i=1;
while(bt[i][j]!=0)
i++;
sum=sum+bt[i-1][j];
}
avg=(float)sum/nop;
printf("\n\n\t\tAverage Turnaround time: %0.2f ms\n",avg);
return 0;
}

15

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:
Enter the Number of processes: 3

Enter the time quantum: 6

Enter the process time for process 1: 9

Enter the process time for process 2: 4

Enter the process time for process 3: 7

Average waiting time: 9.67 millisecs

Average Turnaround time: 16.33 ms

Result:

Thus the Round Robin Scheduling algorithm has been successfully executed and verified.

16

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex. No. 5b CPU SCHEDULING ALGORITHM – SJF

Aim:

To write a c program to implement the scheduling algorithm Shortest Job First(SJF).

Algorthim:

Step 1: Start the process

Step 2: Accept the number of processes in the ready Queue

Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time

Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to highest
burst time.

Step 5: Set the waiting time of the first process as ‗0‘and its turnaround time as its burst time.

Step 6: Sort the processes names based on their Burt time

Step 7: For each process in the ready queue, calculate Waiting timess(n)= waiting time (n-1) + Burst time
(n-1),Turnaround time (n)= waiting time(n)+Burst time(n)

Step 8: Calculate Average waiting time = Total waiting Time / Number of process

and average Turnaround time = Total Turnaround Time / Number of process

Step 9: Stop the process

Coding:

#include<stdio.h>
int main()
{
int nop,i,j,t;
int bt[10],wt=0,tat=0;
float totwt=0.0,tottat=0.0;
float avgwt=0.0,avgtat=0.0;
printf("\n\tEnter the number of processes:");
scanf("%d",&nop);
for(i=1;i<=nop;i++){
printf("\n\tEnter the burst time for process %d in ms:",i);
scanf("%d",&bt[i]);
}
for(i=1;i<=nop;i++)
for(j=1;j<=nop;j++)
{
if(bt[i] < bt[j])
{
t=bt[i];
bt[i]=bt[j];
bt[j]=t;
}
}
17

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

for(i=0;i<nop;i++)
{
bt[0]=0;
wt=wt + bt[i];
totwt = totwt + wt;
}
printf("\n\t\tTotal waiting time: %0.2f ms",totwt);
avgwt=(float)totwt / (float)nop;
printf("\n\t\tAverage waiting time: %0.2f ms",avgwt);
for(i=1;i<=nop;i++)\
{
tat=tat + bt[i];
tottat=tottat + tat;
}
printf("\n\t\tTotal turn around time: %0.2f ms",tottat);
avgtat=(float)tottat / (float)nop;
printf("\n\t\tAverage Turn around time: %0.2f ms",avgtat);
return 0;
}
Output:
[user@linuxserver ~]$ ./a.out

Enter the number of processes:3

Enter the burst time for process 1 in ms:6

Enter the burst time for process 2 in ms:9

Enter the burst time for process 3 in ms:4

Total waiting time: 14.00 ms

Average waiting time: 4.67 ms

Total turn around time: 33.00 ms

Average Turn around time: 11.00 ms

Result:

Thus the SJF Scheduling algorithm has been successfully executed and verified.

18

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex. No. 5c CPU SCHEDULING ALGORITHM – FCFS

Aim:

To write a c program to implement the scheduling algorithm first come first serve.

Algorthim:

Step1: Read the,process time.

Step2: Find the waiting time.

Step3: Calculate turn around time=waiting time+burst time

Step4: Calculate the average waiting time and average turn around time

Step5: Display the details.

Coding:

#include<stdio.h>
int main()
{
int nop,wt=0,tat=0,i;
int bt[10];
float totwt=0.0,tottat=0.0;
float avgwt=0.0,avgtat=0.0;
printf("\n\tEnter the number of process:");
scanf("%d",&nop);
for(i=1;i<=nop;i++)
{
printf("\n\tEnter the burst time for the process%d in msecs:",i);
scanf("%d",&bt[i]);
}
for(i=0;i<nop;i++)
{
bt[0]=0;
wt = wt + bt[i];
totwt=totwt + wt;
}
printf("\n\t\tTotal waiting time: %0.2f ms",totwt);
avgwt=(float)totwt/(float)nop;
printf("\n\t\tAverage waiting time:%0.2f ms",avgwt);for(i=0;i<=nop;i++)
{
tat=tat + bt[i];
tottat=tottat + tat;
}
printf("\n\t\tTotal Turn around time: %0.2f ms",tottat);
avgtat=(float)tottat/(float)nop;
printf("\n\t\tAverage Turn around time: %0.2f ms",avgtat);
return 0;
}

19

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:
[user@linuxserver ~]$ ./a.out

Enter the number of process:3

Enter the burst time for the process1 in msecs:24

Enter the burst time for the process2 in msecs:15

Enter the burst time for the process3 in msecs:33

Total waiting time: 63.00 ms

Average waiting time:21.00 ms

Total Turn around time: 135.00 ms

Average Turn around time: 45.00 ms

Result:

Thus the FCFS Scheduling algorithm has been successfully executed and verified

20

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex. No. 5d CPU SCHEDULING ALGORITHM – PRIORITY BASED

Aim:

To write a c program to implement priority based scheduling algorithm.

Algorithm:

Step1: Read the process, process time and priority.

Step2: Sort the process according to their priorities.

Step3: Find the waiting time

Step4: Calculate the turn around time=waiting time + bus time

Step5: Display the details.

Coding:

#include<stdio.h>
#include<string.h>
int main()
{
float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],pt[10],tt[10],bt[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=10;
printf("\n\n Enter the no of process");
scanf("%d",&n);
printf("\n\nEnter the name and bursttime");
for(i=0;i<n;i++)
{
printf("\n\nNAME:");
scanf("%s",pname[i]);
printf("\n\n BURSTTIME");
scanf("%d",&bt[i]);
}
printf("\n\n enter the priority of the process:");
for(i=0;i<n;i++)
{
printf("\n\n priority of the process");
scanf("%d",&pt[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(pt[i]>pt[j])
{
t=pt[i];
pt[i]=pt[j];
pt[i]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
21

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
} }
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+wt[i];
sbt=sbt+wt[i+1];
tt[i]=wt[i]+bt[i];
ss=ss+bt[i];
}
printf("\n\nGENTT CHART");
printf("\n^^^^^^^^^^^^^^\n");
printf("\n TOTAL WAITING TIME OF THE PROCESS=%d",sum);
printf("\n TOTAL TURN AROUNT TIME OF THE PROCESS=%d",sbt);
avgwt=(float)sum/n;
avgtt=(float)sbt/n;
printf("\n AVERAGE WAITING TIME=%f",avgwt);
printf("\n AVERAGE TURN AROUND TIME=%f",avgtt);
return 0;}

Output:
[user@linuxserver ~]$ ./a.out

Enter the no of process2


Enter the name and bursttime
NAME: art
BURST TIME 6
NAME: th
BURSTTIME 4
enter the priority of the process:
priority of the process 2
priority of the process 3
TOTAL WAITING TIME OF THE PROCESS=6
TOTAL TURN AROUNT TIME OF THE PROCESS=16
AVERAGE WAITING TIME=3.000000
AVERAGE TURN AROUND TIME=8.000000

Result:

Thus the Priority Scheduling algorithm has been successfully executed and verified.

22

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.: 6 IMPLEMENTATION OF SEMAPHORES

Aim:

To implement producer – consumer problem using semaphore.

Algorithm:

Step 1: Start the program.

Step 2: Declare three semaphore variables.

 Mutex initialised to 0 which allows only one process to execute at any time.
 Two variables to indicate the limit of buffer.
Step 3: Wait and signal are two functions to implement the semaphore.

Wait-waits until semaphore variable reach 1 and then decrements it.

Signal – increments the semaphore variable by 1.

Step 4: The reader process, checks if any process is writing. If so it waits else it reads the content of
shared variable and then signals.

Step 4: The Writer process checks if any other process is accessing the shared variable. If not it changes
the value of shared variable and then signals.

Step 5: End the program.

Coding;

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
static int full,empty,mutex;
int buffer[5],in=0,out=0;
void wait(int *a);
void signal(int *b);
void producer()
{
int nextp;
printf("producer\n");
wait(&empty);
wait(&mutex);
nextp=rand()%10+1;
buffer[in]=nextp;
printf("produced item is %d\n",nextp);
in=(in+1)%5;
signal(&mutex);
signal(&full);
printf("full=%d\t empty=%d\n",full,empty);
}
void consumer()
{
int nextc;
23

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

printf("consumer\n");
wait(&full);
wait(&mutex);
nextc=buffer[out];
printf("consumerd item is %d\n",nextc);
out=(out+1)%5;
signal(&mutex);
signal(&empty);
printf("full=%d\t empty=%d\n",full,empty);
}
void wait(int *a)
{
while(*a<=0)
*a=*a-1;
}
void signal(int *b)
{
*b=*b+1;
}
main()
{
int c;
mutex=1;
empty=5;
full=0;
clrscr();
while(1)
{
printf("1.producer\t 2.consumer\t 3.both\t 4.Exit\n");
printf("choice\n");
scanf("%d",&c);
switch(c)
{
case 1:
if(empty==0)
printf("producer has to wait\n");
else
{
producer();
}
break;
case 2:
if(full==0)
printf("consumer has to wait");
else
{
consumer();
}
break;
case 3:
if(!empty)

24

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

{
printf("producer has to wait\n");
consumer();
}
else if(!full)
{
printf("consumer has to wait\n");
producer();
}
else {
consumer();
producer();
}
break;
case 4:
exit(0);
break;
} }
getch();
return 0;
}

Output:

1.producer 2.consumer 3.both 4.Exit


Choice 1
producer
produced item is 7
full=1 empty=4
1.producer 2.consumer 3.both 4.Exit
Choice 2
consumer
consumerd item is 7
full=0 empty=5
1.producer 2.consumer 3.both 4.Exit
Choice 3
consumer has to wait
producer
produced item is 1
full=1 empty=4

Result:

Thus the implementation of producer –consumer problem using Semaphore has been successfully
executed and verified.
25

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.: 7 INTERPROCESS COMMUNICATION USING SHARED MEMORY

Aim:

To implement inter process communication using shared memory.

Algorithm:

Step 1: Create the child process using fork()

Step 2: Create the shared memory for parent process using shmget() system call.
Step 3: Now allow the parent process to write in shared memory using shmptr pointer which is return
type.

Step 4: Now across and attach the same shared memory to the child process.

Step 5: The data in the shared memory is read by the child process using shmptr pointer.

Step 6: Now, detach and rebase the shared memory.

Coding:

#include<stdio.h>

#include<sys/shm.h>

#include<sys/ipc.h>

int main()

int child,shmid,i;

char * shmptr;

child=fork();

if(!child)

shmid=shmget(2041,32,0666 | IPC-CREAT);

shmptr=shmat(shmid,0,0);

printf(“\n PARENT WRITING \n”);

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

shmptr[i]=’a’+i;

putchar(shmptr[i]);

} }
26

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

printf(“\n\n%s”,shmptr);

wait(NULL);

else {

shmid=shmget(2041,32,0666);

shmptr=shmat(shmid,0,0);

printf(“\n CHILD IS READING:”);

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

putchar(shmptr[i]);

shmdt(NULL);

shmctl(shmid, IPC_RMID, NULL);

return 0;

Output:

PARENT WRITING:

ghghg

CHILD IS READING:

ghghg

Result:

Thus scheme to implement inter process communication using shared memory has been successfully
executed and verified

27

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:8 DEAD LOCK AVOIDANCE USING BANKER’S ALGORITHM

Aim:

To implement Dead Lock Avoidance using Bankers Algorithm.

Algorithm:

Step 1: Create variables and resources

Step 2: Consider customers=processes, units=resources, Banker= operating system

Step 3: if a process request for resources, the avoidance algorithm checks before the allocation of
resources about the state of system.

Step 4: If the state is safe, the system allocate the resources to the requesting process otherwise
(unsafe) do not allocate the resources.

Step 5: There is available, allocation and need of the resources.

Step 6: Check the resources in all the processes with available resources and find safe or unsafe.

Coding:

#include<stdio.h>

void main()

int max[20],all[20],need[20],seq[20],avail,work,i,j=0,d,m,n,e;

clrscr();

printf("Enter no of process");

scanf("%d",&n);

printf("Enter max allocated resources to the process");

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

printf("max of p %d is",i);

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

printf("\nAllocation of p %d is",i);

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

need[i]=max[i]-all[i];

printf("\nneed of p %d is : %d",i,need[i]);
28

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

printf("\nEnter available resources");

scanf("%d",&avail);

printf("\nMax allocation need \n");

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

printf("%d %d %d",max[i],all[i],need[i]);

m=d=n;

e=m+1;

while(m>0)

if(d==e)

m=0 ;

else

d=e;

e=0;

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

if((need[i]>0)&&(need[i]<=avail))

need[i]=0;

work=all[i]+avail;

avail=work;

seq[j]=i;

m--;

j++;

else

e++;

29

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

if(d==e)

printf("\n an unsafe sequence");

else

printf("\n safe sequence");

printf("\nThe sequence of process is :");

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

printf("p %d\t",seq[i]);

Output:
Enter the no of process 3

Enter max allocated resources to the process max of p0 is 2

Allocation of p 0 is 1

Need of p0 is : 1

Max of p1 is 5

Allocation of p1 is2

Need of p1 is : 3max of p 2 is 4

Allocation of p2 is 2

Need of p2 is : 2

Enter available resources 3

Max allocation need

2 1 15 2 3 4 2 2

Safe sequence

The sequence of process is p 0 p 1 p2

Result:

Thus the banker’s algorithm has been created to prevent the deadlock.

30

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:9 DEADLOCK DETECTION ALGORITHM

Aim:

To write a C program to implement an algorithm for Dead Lock detection.

Algorithm:

Step 1: Create variables and resources

Step 2: initialize the values for the number of process and resource.

Step 3: if a process request for resources, the detection algorithm checks before the allocation of
resources about the state of system.

Step 4: If the state is safe, the system allocate the resources to the requesting process otherwise
(unsafe) do not allocate the resources.

Step 5: There is available, allocation and need of the resources.

Step 6: Check the resources in all the processes with available resources and find safe or unsafe.

Coding:

#include <stdio.h>
#include <conio.h>
void main()
{
int found,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;
clrscr();

printf("Enter total no of processes");


scanf("%d",&tp);
printf("Enter total no of resources");
scanf("%d",&tr);
printf("Enter claim (Max. Need) matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&c[i][j]);
}
printf("Enter allocation matrix\n");
for(i=1;i<=tp;i++)
{
printf("process %d:\n",i);
for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);
}
printf("Enter resource vector (Total resources):\n");
for(i=1;i<=tr;i++)
{

31

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

scanf("%d",&r[i]);
}
printf("Enter availability vector (available resources):\n");
for(i=1;i<=tr;i++)
{

scanf("%d",&a[i]);
temp[i]=a[i];
}
for(i=1;i<=tp;i++)
{

sum=0;
for(j=1;j<=tr;j++)
{

sum+=p[i][j];

}
if(sum==0)
{

m[k]=i;
k++;

}
}
for(i=1;i<=tp;i++) {
for(l=1;l<k;l++)
if(i!=m[l])
{

flag=1;
for(j=1;j<=tr;j++)
if(c[i][j]<temp[j])
{

flag=0;
break;
}

}
if(flag==1)
{

m[k]=i;
k++;
for(j=1;j<=tr;j++)
temp[j]+=p[i][j];
} }

printf("deadlock causing processes are:");

32

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

for(j=1;j<=tp;j++)
{ found=0;
for(i=1;i<k;i++)
{ if(j==m[i])
found=1;
} if(found==0)
printf("%d\t",j);
}

getch();
}

Output:
Enter total no. of processes : 4
Enter total no. of resources : 5
Enter claim (Max. Need) matrix :
01001
00101
00001
10101
Enter allocation matrix :
10110
11000
00010
00000
Enter resource vector (Total resources) :
21121
Enter availability vector (available resources) :
00001
deadlock causing processes are : 2 3

Result:

Thus the C program to detect the deadlock has been created and executed.

33

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:11(a) MEMORY ALLOCATION SCHEME BEST FIT, FIRST FIT,

WORST FIT

AIM:
To write a C Program for the Implementation of Best fit, First fit, Worst fit in Memory Management
Scheme.

Algorithm:
Step 1 : start the program
Step 2 : Initialze Structure with pointer node to create a memory block.
Step 3 : In Best fit, the memory will be allocated to the exact block size of memory to the processes
created.
Step 4 : In First fit, the memory will be allocated where the block size is received first by the processes.
Step 5 : In worst fit, the memory will be allocated to large block of memory for the process initiated.
Step 6 : stop the program.

Coding:
#include<stdio.h>
struct node;
typedef struct node *ptrtonode;
typedef ptrtonode memory;
typedef struct node nodetype;
int pro_id,pro_size;
memory create();
struct node
{
int id;
int start;
int hole;
int end;
ptrtonode next;
};
memory create()
{
memory mem;
mem=(ptrtonode)malloc(sizeof(nodetype));
mem->next=NULL;
return mem;
}
void insert(memory mem,int s,int e)
{
ptrtonode tmp;
tmp=(ptrtonode)malloc(sizeof(nodetype));
tmp->next=mem->next;
tmp->start=s;
tmp->end=e;
tmp->hole=e-s;
tmp->id=0;
mem->next=tmp;
}
void firstfit(memory mem)
34

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

{
int diff;
ptrtonode tmp;
tmp=mem->next;
while(tmp!=NULL)
{
if(tmp->hole>=pro_size&&tmp->id==0)
{
tmp->id=pro_id;
diff=tmp->hole-pro_size;
tmp->hole=0;
tmp->end=tmp->start+pro_size;
if(tmp->next!=NULL&&tmp->next->hole==0)
{
tmp=tmp->next;
tmp->hole+=diff;
tmp->start-=diff;
}
else
{
ptrtonode t;
t=(ptrtonode)malloc(sizeof(nodetype));
t->next=tmp->next;
tmp->next=t;
t->id=0;
t->hole=diff;
t->start=tmp->end;
t->end=t->start+t->hole;
}
break;
}
Else
tmp=tmp->next;
}
}
void best_fit(memory mem)
{
int diff,count=0,c,min;
ptrtonode tmp;
tmp=mem->next;
min=3200;
while(tmp!=NULL)
{
count++;
if(tmp->hole>=pro_size&&tmp->id==0)
if(tmp->hole<min)
{
min=tmp->hole;
c=count;
}
tmp=tmp->next;

35

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

}
tmp=mem->next;
count=0;
while(tmp!=NULL)
{
count++;
if(c==count)
{
tmp->id=pro_id;
diff=tmp->hole-pro_size;
tmp->hole=0;
tmp->end=tmp->start+pro_size;
if(tmp->next!=NULL&&tmp->next->hole==0)
{
tmp=tmp->next;
tmp->hole+=diff;
tmp->start-=diff;
}
else
{
prtonode t;
t=(ptrtonode)malloc(sizeof(nodetype));
t->next=tmp->next;
tmp->nex=t;
t->id=0;
t->hole=diff;
t->start=tmp->end;
t->end=t->start+t->hole;
}
Break;
}
tmp=tmp->next;
}
}
void worst_fit(memory mem)
{
int diff,count=0,c,max;
ptrtonode tmp;
tmp=mem->next;
max=-1;
while(tmp!=NULL)
{
count++;
if(tmp->hole>=pro_size&&tmp->id==0)
if(tmp->hole>max)
{
max=tmp->hole;
c=count;
}
tmp=tmp->next;
{

36

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

count++;;
if(c==count)
{
tmp->id=pro_id;
diff=tmp->hole-pro_size;
tmp->hole=0;
tmp->end=tmp->start+pro_size;
if(tmp->next!=NULL&&temp->next->hole==0)
{
tmp=tmp->next;
tmp->hole+=diff;
tmp->start-=diff;
}
Else
{
Ptrtonode t;
t=(ptrtonode)malloc(sizeof(nodetype));
t->next=tmp->next;
tmp->next=t;
t->hole=diff;
t->id=0;
t->start=tmp->end;
t->end=t->start+t->hole;
}
Break;
}
tmp=tmp->next;
}
}
void allocate(memory mean)
{
Int opt;
printf(“\nEnter the process ID:”);
scanf(“%d”,&pro_id);
printf(“\n Enter the process size:”);
scanf(“%d”,&pro_size);
printf(“\nMENU”);
printf(“\n1.FIRST FIT”);
printf(“\n2.BEST FIT”);
printf(“\n3.WORST FIT”);
printf(“\nEnter your option”);
scanf(“%d”,opt);
switch(opt)
{
case 1:
first_fit(mem);
break;
case 2:
best_fit(mem);
break;
}

37

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

}
void deallocate(memory mem)
{
prtonode tmp;
int diff;
printf(“\nEnter the process ID:”);
scanf(“%d”,&pro_id);
tmp=mem;
while(tmp->next!=NULL)
{
if(tmp->next->id==pro_id)
{
Ptrtonode
t=tmp->next;
t->id=0;
t->next->start=t->start;
t->next->hole=t->next->end-t->next->start;
tmp->next=t->next;
free(t);
}
else
{
t->id=0;
t->hole=t->end-t->start;
}
break;
}
tmp=tmp->next;
}
}
void display(memory mem)
{
ptrtonode tmp;
tmp=mem->next;
while(tmp!=NULL)
{
tmp=tmp->next;
}
}
void del(memory mem)
{
ptrtonode tmp,tmp,t;
tmp=mem;
while(tmp!=NULL)
{
t=tmp->next;
free(t);
tmp=t;
}
free(mem);
}

38

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

int main()
{
int i,opt,mem_end=8000,mem_start;
memory mem;
mem=create();
insert(mem,0,10000);
for(;;)
{
printf(“\nMENU”);
printf(“\n1.Allocate memory”);
printf(“\n2.Deallocate Memory”);
printf(“\n3.Display”);
printf(“\n4.Exit”);
printf(“\nEnter your Option”);
scanf(“%d”,&opt);
switch(opt)
{
case 1:
allocate(mem);
break;
case 2:
deallocate(mem);
break;
case 3:
display(mem);
break;
case 4:
del(mem);
exit(0);
}
}
Return 0;

OUTPUT:
[examuser35@localhost Jebastin]$ cc fit.c

[examuser35@localhost Jebastin]$ ./a.out

MENU

1.Allocate Memory

2.Deallocate Memory

3.Display

4.Exit

Enter your option 1


Enter the Process ID:1
Enter the Process size:1500

MENU
39

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

1.FIRST FIT
2.BEST FIT
3.WORST FIT
Enter your Option1

MENU
1.Allocate Memory
2.Deallocate Memory
3.Display
4.Exit
Enter your option 3
id=1 start= 0 hole= 0 end=1500
id=0 start= 1500 hole= 8500 end=10000

MENU
1.Allocate Memory
2.Deallocate Memory
3.Display
4.Exit
Enter your option 1
Enter the Process ID:2
Enter the Process size:2500

MENU
1.FIRST FIT
2.BEST FIT
3.WORST FIT
Enter your Option 3

MENU
1.Allocate Memory
2.Deallocate Memory
3.Display
4.Exit
Enter your option 3
id=1 start= 0 hole= 0 end=1500
id=2 start= 1500 hole= 0 end=4000
id=0 start= 4000 hole= 6000 end=10000

MENU
1.Allocate Memory
2.Deallocate Memory
3.Display
4.Exit
Enter your option 2

Enter the Process ID:1

MENU
1.Allocate Memory
2.Deallocate Memory

40

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

3.Display
4.Exit
Enter your option 3
id=0 start= 0 hole= 1500 end=1500
id=2 start= 1500 hole= 0 end=4000
id=0 start= 4000 hole= 6000 end=10000

MENU
1.Allocate Memory
2.Deallocate Memory
3.Display
4.Exit
Enter your option 1
Enter the Process ID:4
Enter the Process size:1000

MENU
1.FIRST FIT
2.BEST FIT
3.WORST FIT
Enter your Option 2

MENU
1.Allocate Memory
2.Deallocate Memory
3.Display
4.Exit
Enter your option 3
id=4 start= 0 hole= 0 end=1000
id=2 start= 1000 hole= 500 end=4000
id=0 start= 4000 hole= 6000 end=10000

MENU
1.Allocate Memory
2.Deallocate Memory
3.Display
4.Exit
Enter your option 4

Result:

Thus the program for best fit, first fit, worst fit has been successfully executed and verified.

41

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:12 PAGING TECHNIQUE FOR MEMORY MANAGEMENT

Aim:

To implement the Memory management policy- Paging.

Algorithm:

Step 1: Read all the necessary input from the keyboard.

Step 2: Pages - Logical memory is broken into fixed - sized blocks.

Step 3: Frames – Physical memory is broken into fixed – sized blocks.

Step 4: Calculate the physical address using the following

Physical address = (Frame number * Frame size ) + offset

Step 5: Display the physical address.

Step 6: Stop the process.

Coding:

#include <stdio.h>

#include <conio.h>

struct pstruct

int fno;

int pbit;

}ptable[10];

int pmsize,lmsize,psize,frame,page,ftable[20],frameno;

void info()

printf("\n\nMEMORY MANAGEMENT USING PAGING\n\n");

printf("\n\nEnter the Size of Physical memory: ");

scanf("%d",&pmsize);

printf("\n\nEnter the size of Logical memory: ");

scanf("%d",&lmsize);

printf("\n\nEnter the partition size: ");

scanf("%d",&psize);

42

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

frame = (int) pmsize/psize;

page = (int) lmsize/psize;

printf("\nThe physical memory is divided into %d no.of frames\n",frame);

printf("\nThe Logical memory is divided into %d no.of pages",page);

void assign()

int i;

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

ptable[i].fno = -1;

ptable[i].pbit= -1;

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

ftable[i] = 32555;

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

printf("\n\nEnter the Frame number where page %d must be placed: ",i);

scanf("%d",&frameno);

ftable[frameno] = i;

if(ptable[i].pbit == -1)

ptable[i].fno = frameno;

ptable[i].pbit = 1;

getch();

// clrscr();

printf("\n\nPAGE TABLE\n\n");

43

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

printf("PageAddress FrameNo. PresenceBit\n\n");

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

printf("%d\t\t%d\t\t%d\n",i,ptable[i].fno,ptable[i].pbit);

printf("\n\n\n\tFRAME TABLE\n\n");

printf("FrameAddress PageNo\n\n");

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

printf("%d\t\t%d\n",i,ftable[i]);

void cphyaddr()

int laddr,paddr,disp,phyaddr,baddr;

getch();

clrscr();

printf("\n\n\n\tProcess to create the Physical Address\n\n");

printf("\nEnter the Base Address: ");

scanf("%d",&baddr);

printf("\nEnter theLogical Address: ");

scanf("%d",&laddr);

paddr = laddr / psize;

disp = laddr % psize;

if(ptable[paddr].pbit == 1 )

phyaddr = baddr + (ptable[paddr].fno*psize) + disp;

printf("\nThe Physical Address where the instruction present: %d",phyaddr);

void main()

clrscr();

info();

assign();

44

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

cphyaddr();

getch();

Output:

MEMORY MANAGEMENT USING PAGING

Enter the Size of Physical memory: 16

Enter the size of Logical memory: 8

Enter the partition size: 2

The physical memory is divided into 8 no.of frames

The Logical memory is divided into 4 no.of pages

Enter the Frame number where page 0 must be placed: 5

Enter the Frame number where page 1 must be placed: 6

Enter the Frame number where page 2 must be placed: 7

Enter the Frame number where page 3 must be placed: 2

PAGE TABLE

PageAddress FrameNo. PresenceBit

0 5 1

1 6 1

2 7 1

3 2 1

FRAME TABLE

FrameAddress PageNo

0 32555

1 32555

2 3

3 32555

4 32555

5 0

6 1

45

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

7 2

Process to create the Physical Address

Enter the Base Address: 1000

Enter theLogical Address: 3

The Physical Address where the instruction present: 1013

Result:

Thus the Program to implement paging for memory management has been executed and verified
successfully.

46

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:13 a) PAGE REPLACEMENT ALGORITHM – FIFO

Aim:

To write a C program to implement FIFO page replacement algorithm

Algorithm:

Step 1. Start the process

Step 2. Declare the size with respect to page length

Step 3. Check the need of replacement from the page to memory

Step 4. Check the need of replacement from old page to new page in memory

Step 5. Forma queue to hold all pages

Step 6. Insert the page require memory into the queue

Step 7. Check for bad replacement and page fault

Step 8. Get the number of processes to be inserted

Step 9. Display the values

Step 10. Stop the process

Coding:

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

47

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

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:

ENTER THE NUMBER OF PAGES: 12

ENTER THE PAGE NUMBER :2 3 2 3 4 5 1 7 2 3 9 10

ENTER THE NUMBER OF FRAMES :3

ref string page frames

2 2 -1 -1

3 2 3 -1

48

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

4 2 3 4

5 5 3 4

1 5 1 4

7 5 1 7

2 2 1 7

3 2 3 7

9 2 3 9

10 10 3 9

Page Fault Is 10

Result:

Thus the c program to implement FIFO page replacement algorithm has been successfully executed and
completed.

49

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:13b PAGE REPLACEMENT ALGORITHM – LRU

Aim:

To write a C program to implement LRU page replacement algorithm

Algorithm :

Step 1. Start the process and declare the size

Step 2. Get the number of pages to be inserted

Step 3. Get the value

Step 4. Declare counter and stack

Step 5. Select the least recently used page by counter value

Step 6. Stack them according the selection.

Step 7. Display the values

Step 8. Stop the process

Coding:

#include<stdio.h>

#include<conio.h>

int n,ref[100],fs,frame[100],count=0;

void input();

void show();

void cal();

void main()

printf("***** LRU Page Replacement Algo ********************\n");

input();

cal();

show();

getch();

void input()

50

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

int i;

printf("Enter no of pages in Refrence String\t");

scanf("%d",&n);

printf("Enter the reference string:");

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

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

printf("Enter the Frame Size\t");

scanf("%d",&fs);

void cal()

int i,j,k=0,c1,c2[100],r,temp[100],t;

frame[k]=ref[k];

count++;

k++;

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

c1=0;

for(j=0;j<fs;j++)

if(ref[i]!=frame[j])

c1++;

if(c1==fs)

count++;

if(k<fs)

frame[k]=ref[i];

51

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

k++;

else

for(r=0;r<fs;r++)

c2[r]=0;

for(j=i-1;j<n;j--)

if(frame[r]!=ref[j])

c2[r]++;

else

break;

for(r=0;r<fs;r++)

temp[r]=c2[r];

for(r=0;r<fs;r++)

for(j=r;j<fs;j++)

if(temp[r]<temp[j])

t=temp[r];

temp[r]=temp[j];

temp[j]=t;

52

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

for(r=0;r<fs;r++)

if(c2[r]==temp[0])

frame[r]=ref[i];

} } } } }

void show()

printf("Page Faults = %d",count);

Output:

Enter the frame size: 3

Total page faults= 0

Press 1 to continue: 2

****************** LRU Page Replacement Algo *********************

Enter no of pages in Refrence String 10

Enter the reference string: 2 3 4 5 1 2 1 7 8 2

Enter the Frame Size 3

Page Faults = 9

Result:

Thus the C program to implement LRU page replacement algorithm has been successfully executed and
completed.

53

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:13c PAGE REPLACEMENT ALGORITHM – LFU

Aim:

To write a c program to implement LFU page replacement algorithm

Algorithm:

Step 1. Take inputs

Step 2. Initialize Frame and Freq array to -1

Step 3. Check for Page Hit. If yes then Goto step 7 else Goto step 4

Step 4. Create array of page counts and store it in 'count' array.

Step 5. find the least frequently used page from the pages in FRAME.

Step 6. Replace page in frame by current page.

Step 7. increment counter.

Step 8. Print FRAME.

Coding:

#include<stdio.h>

int main()

int f,p;

int pages[50],frame[10],hit=0,count[50],time[50];

int i,j,page,flag,least,minTime,temp;

printf("Enter no of frames : ");

scanf("%d",&f);

printf("Enter no of pages : ");

scanf("%d",&p);

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

frame[i]=-1;

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

54

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

count[i]=0;

printf("Enter page no : \n");

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

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

printf("\n");

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

count[pages[i]]++;

time[pages[i]]=i;

flag=1;

least=frame[0];

for(j=0;j<f;j++)

if(frame[j]==-1 || frame[j]==pages[i])

if(frame[j]!=-1)

{ hit++;

flag=0;

frame[j]=pages[i];

break;

if(count[least]>count[frame[j]])

{ least=frame[j];

} }

if(flag)

{ minTime=50;

55

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

for(j=0;j<f;j++)

if(count[frame[j]]==count[least] && time[frame[j]]<minTime)

temp=j;

minTime=time[frame[j]];

} }

count[frame[temp]]=0;

frame[temp]=pages[i];

for(j=0;j<f;j++)

printf("%d ",frame[j]);

printf("\n");

printf("Page hit = %d",hit);

return 0;

56

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:

Enter no of frames : 3

Enter no of pages : 10

Enter page no :2 3 4 5 1 2 1 7 8 2

2 -1 -1

2 3 -1

234

534

514

512

512

712

718

218 Page hit = 1 Page fault: 9

Result:

Thus the C program to implement LFU page replacement algorithm has been successfully executed and
verified.

57

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:14a FILE ORGANIZATION TECHNIQUES- SINGLE LEVEL DIRECTORY

Aim:

To implement File organization technique using single level directory.

Algorithm:

Step 1: Start

Step 2: Initialize values gd=DETECT,gm,count,i,j,mid,cir_x;

Initialize character array fname[10][20];

Step 3: Initialize graph function as Initgraph(& gd, &gm," c:/tc/bgi");Clear device();

Step 4: set back ground color with setbkcolor();

Step 5: read number of files in variable count.

Step 6: if check i<count then move to the next directory.

Step 7: End

Coding:

#include<stdio.h>

#include<conio.h>

main()

int master,s[20];

char f[20][20][20];

char d[20][20];

int i,j;

clrscr();

printf("enter number of directorios:");

scanf("%d",&master);

printf("enter names of directories:");

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

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

printf("enter size of directories:");

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

58

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

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

printf("enter the file names :");

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

for(j=0;j<s[i];j++)

scanf("%s",&f[i][j]);

printf("\n");

printf(" directory\tsize\tfilenames\n");

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

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

printf("%s\t\t%2d\t",d[i],s[i]);

for(j=0;j<s[i];j++)

printf("%s\n\t\t\t",f[i][j]);

printf("\n");

printf("\t\n");

getch();

59

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:

enter number of directorios:3

enter names of directories : a b c

enter size of directories: 2 3 1

enter the file names : as bs cs ad fg as

directory size filenames

***************************************

a 2 as

bs

b 3 cs

ad

fg

c 1 as

Result:

Thus the File organization technique using single level directory has been successfully executed and
completed

60

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:14 b FILE ORGANIZATION TECHNIQUE- TWO LEVEL DIRECTORY


Aim:

To implement File organization technique using two level directory.

Algorithm:

Step 1: Start

Step 2: Initialize structure elements struct tree_ element char name[20];

Initialize integer variables x, y, ftype, lx, rx, nc, level; struct tree_element
*link[5];}typedef structure tree_element node;

Step 3: start main function

Step 4: Step variables gd=DETECT,gm; node *root; root=NULL;

Step 5: create structure using create(&root,0,"null",0,639,320);

Step 6: initgraph(&gd, &gm,"c:\tc\bgi"); display(root); closegraph();

Step 7: end main function

Step 8: Initialize variables i,gap;

Step 9: End the process.

Coding:

#include<stdio.h>

#include<conio.h>

struct st

char dname[10];

char sdname[10][10];

char fname[10][10][10];

int ds,sds[10];

}dir[10];

void main()

int i,j,k,n;

clrscr();

printf("enter number of directories:");


61

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

scanf("%d",&n);

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

printf("enter directory %d names:",i+1);

scanf("%s",&dir[i].dname);

printf("enter size of directories:");

scanf("%d",&dir[i].ds);

for(j=0;j<dir[i].ds;j++)

printf("enter subdirectory name and size:");

scanf("%s",&dir[i].sdname[j]);

scanf("%d",&dir[i].sds[j]);

for(k=0;k<dir[i].sds[j];k++)

printf("enter file name:");

scanf("%s",&dir[i].fname[j][k]);

} } }

printf("\ndirname\t\tsize\tsubdirname\tsize\tfiles");

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

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

printf("%s\t\t%d",dir[i].dname,dir[i].ds);

for(j=0;j<dir[i].ds;j++)

printf("\t%s\t\t%d\t",dir[i].sdname[j],dir[i].sds[j]);

for(k=0;k<dir[i].sds[j];k++)

printf("%s\t",dir[i].fname[j][k]);

printf("\n\t\t");

} printf("\n");

62

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

getch();

Output:

enter number of directories:3

enter directory 1 names:a

enter size of directories:b

enter directory 2 names:enter size of directories:2

enter subdirectory name and size: b 2

enter file name: as

enter file name: sd

enter subdirectory name and size: c 1

enter file name: af

enter directory 3 names: n

enter size of directories: 2

enter subdirectory name and size: aq 1

enter file name: file1

enter subdirectory name and size: as 1

enter file name: file2

dirname size subdirname size files

****************************************

a 0

b 2 b 2 as sd

c 1 af

n 2 aq 1 file1

as 1 file2

Result:

Thus the File organization technique using two level directory has been successfully executed and
completed

63

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.: 14c FILE ORGANIZATION TECHNIQUES- HIERARCHICAL DIRECTORY

Aim:

To implement File organization technique using hierarchical level directory.

Algorithm:

Step 1: Start

Step 2: define structure and declare structure variables

Step 3: start main and declare variables Node *root Root = NULL

Step 4: create root null Initgraph &gd,&gm Display root

Step 5:create a directory tree structure If check *root==NULL Display dir/file name.

Step 6: Root->link[i]=NULL Display sub dir/ files

Step 7: display the directory tree in graphical mood Display nood *root

If check root !=NULL

Step 8: foe i=0 to i<root->nc Line of root->x, root->y, root->link[i]->x, root- >link[i]-y

Step 9: if check root->ftype==1 Bar3d of root->x-20, root->y-10,root->x+20,root- >y+10,0 Then


Display root->link[i]

Step 10: Stop.

Coding:

#include<stdio.h>

#include<graphics.h>

struct tree_element

char name[20];

int x,y,ftype,lx,rx,nc,level;

struct tree_element *link[5];

};

typedef struct tree_element

node;

void main()

{
64

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

int gd=DETECT,gm;

node *root;

root=NULL;

clrscr();

printf("\n");

create(&root,0,"root",0,639,320);

clrscr();

initgraph(&gd,&gm,"c:\tc\BGI");

display(root);

getch();

close graph();

create(node **root,int lev,char *dname,int lx,int rx,int x)

int i,gap;

if(*root==NULL)

(*root)=(node *)malloc(sizeof(node));

printf("Enter name of dir/file(under %s) :",dname);

fflush(stdin);

gets((*root)->name);

printf("enter 1 for Dir/2 for file :");

scanf("%d",&(*root)->ftype);

(*root)->level=lev;

(*root)->y=50+lev*50;

(*root)->x=x;

(*root)->lx=lx;

(*root)->rx=rx;

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

65

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

(*root)->link[i]=NULL;

if((*root)->ftype==1)

printf("No of sub directories/files(for %s):",(*root)->name);

scanf("%d",&(*root)->nc);

if((*root)->nc==0)

gap=rx-lx;

else gap=(rx-lx)/(*root)->nc;

for(i=0;i<(*root)->nc;i++)

create(&((*root)->link[i]),lev+1,(*root)->name,lx+gap*i, lx+gap*i+gap, lx+gap*i+gap/2);

else

(*root)->nc=0;

display(node *root)

int i;

settextstyle(2,0,4);

settextjustify(1,1);

setfillstyle(1,BLUE);

setcolor(14);

if(root !=NULL)

for(i=0;i<root->nc;i++)

{ line(root->x,root->y,root->link[i]->x,root->link[i]->y);

if(root->ftype==1) bar3d(root->x-20,root->y-10,root->x+20,root->y+10,0,0);

else

66

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

fillellipse(root->x,root->y,20,20);

outtextxy(root->x,root->y,root->name);

for(i=0;i<root->nc;i++)

display(root->link[i]);

Output:

enter name of dir/file(under null):sld How many users(forsld):2

enter name of dir/file(under sld):tld hoe many files(fortld):2

enter name of dir/file(under tld):hir enter name of dir/file(under tld):dag

enter name of dir/file(under sld):bin how many files(forbin):2

enter name of dir/file(under bin):exe enter name of dir/file(under bin):obj

Result:

Thus the File organization technique using hierarchical directory has been successfully executed and
completed

67

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.:14 d) FILE ORGANIZATION TECHNIQUES- DAG DIRECTORY

Aim:

To implement File organization technique using DAG directory.

Algorithm:

Step 1: Start

Step 2: Declare structure and structure variables

Step 3: Start main and declare variables Node *root Root = NULL

Create root null read the shared file information

Step 4: Draw link lines for shared files Search root find the first and second

Step 5: if check root !-NULL If check string comparing root ->name, s==0

Then search root->link

Step 6: creates a directory tree structure If check *root==NULL Display directory name or file
name

Step 7: display the directory tree in graphical mode Display node *root

Step 8: if check root!=NULL draw lines

Step 9: line of root->x,root->y,root->link[i]->x, root->link[i]->y

If check root->ftype==1 if it is directory

Step10: then root->x,root->y,20,20 if it a file Root->x,root->y,root->name

Step11: for 0 to i<root->nc display children Display root->link[i]

Step 12; Stop the process.

Coding:

#include<stdio.h>

#include<graphics.h>

struct tree_element

char name[20];

int x,y,ftype,lx,rx,nc,level;

struct tree_element *link[5];

68

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

};

typedef struct tree_element node;

void main()

int gd=DETECT,gm;

node *root;

root=NULL;

clrscr();

create(&root,0,"null",0,639,320);

clrscr();

initgraph(&gd,&gm,"c:\tc\bgi");

display(root);

getch();

closegraph();

create(node **root,int lev,char *dname,int lx,int rx,int x)

int i,gap;

if(*root==NULL)

(*root)=(node*)malloc(sizeof(node));

printf("enter name of dir/file(under%s):",dname);

fflush(stdin);

gets((*root)->name);

if(lev==0||lev==1)

(*root)->ftype=1;

else

(*root)->ftype=2;

(*root)->level=lev;

69

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

(*root)->y=50+lev*50;

(*root)->x=x; (*root)->lx=lx; (*root)->rx=rx;

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

(*root)->link[i]=NULL;

if((*root)->ftype==1)

if(lev==0||lev==1)

if((*root)->level==0)

printf("How many users");

else

printf("hoe many files");

printf("(for%s):",(*root)->name);

scanf("%d",&(*root)->nc);

else (*root)->nc=0;

if((*root)->nc==0)

gap=rx-lx;

else

gap=(rx-lx)/(*root)->nc;

for(i=0;i<(*root)->nc;i++)

create(&((*root)->link[i]),lev+1,(*root)->name,lx+gap*i, lx+gap*i+gap, lx+gap*i+gap/2);

else (*root)->nc=0;

display(node *root)

int i;

70

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

settextstyle(2,0,4);

settextjustify(1,1);

setfillstyle(1,BLUE);

setcolor(14);

if(root!=NULL)

for(i=0;i<root->nc;i++)

line(root->x,root->y,root->link[i]->x,root->link[i]->y);

if(root->ftype==1) bar3d(root->x-20,root->y-10, root->x+20,root->y+10,0,0);

else

fillellipse(root->x,root->y,20,20);

outtextxy(root->x,root->y,root->name); for(i=0;i<root->nc;i++)

display(root->link[i]);

Output:

Enter name of dir/file(under root) :Root

enter 1 for Dir/2 for file :1

No of sub directories/files(for Root):2

Enter name of dir/file(under Root) :User1

enter 1 for Dir/2 for file :1

No of sub directories/files(for User1):1

Enter name of dir/file(under User1) :a

71

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

enter 1 for Dir/2 for file :1

No of sub directories/files(for a):1

Enter name of dir/file(under a) :b

enter 1 for Dir/2 for file :1

No of sub directories/files(for b):0

Enter name of dir/file(under Root) :user2

enter 1 for Dir/2 for file :1

No of sub directories/files(for user2):1

Enter name of dir/file(under user2) :c

enter 1 for Dir/2 for file :1

No of sub directories/files(for c):1

Enter name of dir/file(under c) :d

enter 1 for Dir/2 for file :1

No of sub directories/files(for d):0

Result:

Thus the File organization technique using DAG level directory has been successfully executed and
completed.

72

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.15a SEQUENTIAL FILE ALLOCATION STRATEGY

Aim:

To Write a C Program to implement Sequential File Allocation method.

Algorithm:

Step 1: Start the program.


Step 2: Get the number of files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations to each in sequential order
a). Randomly select a location from available location
s1= random(100);
b). Check whether the required locations are free from the selected location.
if(b[s1].flag==0)
{
for(j=s1;j<s1+p[i];j++)
{
if((b[j].flag)==0)
count++;
}
if(count==p[i])
break;
}
c). Allocate and set flag=1 to the allocated locations.
for(s=s1;s<(s1+p[i]);s++)
{
k[i][j]=s;
j=j+1;
b[s].bno=s;
b[s].flag=1;
}
Step 5: Print the results fileno, lenth ,Blocks allocated.
Step 6: Stop the program

Coding:

#include<stdio.h>

#include<conio.h>

main()

int n,i,j,b[20],sb[20],t[20],x,c[20][20];

clrscr();

printf("Enter no.of files:");

scanf("%d",&n);

73

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

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

printf("Enter no. of blocks occupied by file%d",i+1);

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

printf("Enter the starting block of file%d",i+1);

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

t[i]=sb[i];

for(j=0;j<b[i];j++)

c[i][j]=sb[i]++;

printf("Filename\tStart block\tlength\n");

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

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

printf("Enter file name:");

scanf("%d",&x);

printf("File name is:%d",x);

printf("length is:%d",b[x-1]);

printf("blocks occupied:");

for(i=0;i<b[x-1];i++)

printf("%4d",c[x-1][i]);

getch();

74

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:

Enter no.of files:2

Enter no. of blocks occupied by file1 3

Enter the starting block of file1 1

Enter no. of blocks occupied by file2 2

Enter the starting block of file2 2

Filename Start block length

1 1 3

2 2 2

Enter file name:1

File name is:1 length is:3 blocks occupied: 1 2 3

Result:

Thus the C Program for sequential file allocation has been executed and verified successfully

75

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.15b INDEXED FILE ALLOCATION STRATEGY

Aim:

To Write a C Program to implement Indexed File Allocation method.

Algorithm:

Step 1: Start the program.


Step 2: Get the number of files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations by selecting a location randomly
q= random(100);
a). Check whether the selected location is free .
b). If the location is free allocate and set flag=1 to the allocated locations.
q=random(100);
{
if(b[q].flag==0)
b[q].flag=1;
b[q].fno=j;
r[i][j]=q; }
Step 5: Print the results fileno, lenth ,Blocks allocated.
Step 6: Stop the program

Coding:

#include<stdio.h>

#include<conio.h>

main()

int n,m[20],i,j,sb[20],s[20],b[20][20],x;

clrscr();

printf("Enter no. of files:");

scanf("%d",&n);

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

printf("Enter starting block and size of file%d:",i+1);

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

printf("Enter blocks occupied by file%d:",i+1);

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

printf("enter blocks of file%d:",i+1);

76

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

for(j=0;j<m[i];j++)

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

printf("\nFile\t index\tlength\n");

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

printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);

printf("\nEnter file name:");

scanf("%d",&x);

printf("file name is:%d\n",x);

i=x-1;

printf("Index is:%d",sb[i]);

printf("Block occupied are:");

for(j=0;j<m[i];j++)

printf("%3d",b[i][j]);

getch();

77

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:

Enter no. of files:2

Enter starting block and size of file1: 2 5

Enter blocks occupied by file1:10

enter blocks of file1:3

2 5 4 6 7 2 6 4 7

Enter starting block and size of file2: 3 4

Enter blocks occupied by file2:5

enter blocks of file2: 2 3 4 5 6


File index length

1 2 10

2 3 5

Result:

Thus the C Program for Indexed file allocation strategy has been executed and verified
Successfully.

78

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Ex.No.15(c) LINKED FILE ALLOCATION STRATEGY

Aim:

To write a C Program to implement Linked File Allocation method.

Algorithm:

Step 1: Start the program.


Step 2: Get the number of files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations by selecting a location randomly
q= random(100);
a). Check whether the selected location is free .
b). If the location is free allocate and set flag=1 to the allocated locations.
While allocating next location address to attach it to previous location
for(i=0;i<n;i++)
{
for(j=0;j<s[i];j++)
{
q=random(100);
if(b[q].flag==0)
b[q].flag=1;
b[q].fno=j;
r[i][j]=q;
if(j>0)
{
p=r[i][j-1];
b[p].next=q;
}
}
}
Step 5: Print the results fileno, lenth ,Blocks allocated.
Step 6: Stop the program

Coding:

#include<stdio.h>

#include<conio.h>

struct file

char fname[10];

int start,size,block[10];

}f[10];

main()

79

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

int i,j,n;

clrscr();

printf("Enter no. of files:");

scanf("%d",&n);

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

printf("Enter file name:");

scanf("%s",&f[i].fname);

printf("Enter starting block:");

scanf("%d",&f[i].start);

f[i].block[0]=f[i].start;

printf("Enter no.of blocks:");

scanf("%d",&f[i].size);

printf("Enter block numbers:");

for(j=1;j<=f[i].size;j++)

scanf("%d",&f[i].block[j]);

printf("File\tstart\tsize\tblock\n");

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

printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);

for(j=1;j<=f[i].size-1;j++)

printf("%d--->",f[i].block[j]);

printf("%d",f[i].block[j]);

printf("\n");

getch();

80

Downloaded by jayasree m ([email protected])


lOMoARcPSD|50491148

Output:

Enter no. of files:2

Enter file name:file1

Enter starting block:20

Enter no.of blocks:6

Enter block numbers: 4

12

15

45

32

25

Enter file name:f ile2

Enter starting block:12

Enter no.of blocks:5

Enter block numbers:6

File start size block

file1 20 6 4--->12--->15--->45--->32--->25

file2 12 5 6--->5--->4--->3--->2

Result:

Thus the C Program for linked allocation strategy has been executed and verified successfully.

81

Downloaded by jayasree m ([email protected])

You might also like