OS CSE TECH
OS CSE TECH
RECORD NOTEBOOK
CS3461- OPERATING SYSTEMS LAB
FOURTH SEMESTER
STUDENT NAME :
REGISTER NUMBER :
THANGAVELU ENGINEERING COLLEGE
IT Highway, Rajiv Gandhi Salai- 600 097
BONAFIDE CERTIFICATE
REGISTER No.:
Certified that this is the Bonafide Record of Work done by
Mr./Ms.
Date
3
EX.NO DATE NAME OF THE EXPERIMENT PAGE NO SIGNATURE
4
EX.NO DATE NAME OF THE EXPERIMENT PAGE NO SIGNATURE
5
DATE :
EXPT.NO.1
1. DATE COMMAND:
SYNTAX : date
USES : Used to display system date and
OPTIONS :
OUTPUT : 05
OUTPUT : May
OUTPUT : 06
OUTPUT : 53
OUTPUT : 15
6
SYNTAX : date +%a
USES : Used to displays the aggregated form of the day.
OUTPUT : Thu
OUTPUT : 03:54:43 PM
OUTPUT : 15:55:58
2. CALENDER COMMAND:
SYNTAX : cal
USES : It displays the current month calendar.
OUTPUT :
May 2006
Su Mo Tu We Th S
Fr a
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19
20
21 22 23 24 25 26
27
28 29 30 31
3. ECHO COMMAND:
OUTPUT : UNIX
7
TYPING A CONTENTS MORE THAN ONE LINE
OUTPUT : This
command line exceeds
a single line
4. BC COMMAND:
SYNTAX : bc
USES : Used to perform simple mathematical calculations. By default this
command accepts decimal numbers and also perform mathematical calculations on
octal and hexadecimal numbers.
OUTPUT :
1) 5+3
8
2) 1.1+2.2
3.3
3) 3.3-1.2
2.1
4) 5.6*4.1
22.9
5) 8.4/3.2
2
8
6) 3-1
2
7) 4*5
20
5. WHO COMMAND:
SYNTAX : who
USES : Used to display the login details for all users using the UNIX systems.
OUTPUT :
WHO AM I
SYNTAX : who am i
USES : Used to displays the login details of the current users of the system
, who invokes the command.
6. TTY COMMAND:
OUTPUT : /dev/pts/1
7. MAN COMMAND:
9
DIRECTORY
COMMANDS
1. MAKE DIRECTORY
2. CHANGE DIRECTORY
OUTPUT : cd jeeva
3. REMOVE DIRECTORY
SYNTAX : rmdir
USES : Used to remove the directory.
4. PWD
SYNTAX : pwd
USES : Used to display the path that we are working.
OUTPUT : /home/student/vs
5. CAT
OUTPUT :
cat
>sample
flower
jasmine
rose
Press ctrl + d
10
SYNTAX : cat filename
USES : Used to display the content of that file.
OUTPUT :
cat
sample
flower
jasmine
rose
OUTPUT :
cat sample1
a
c
d
cat <sample >sample1
flower
jasmin
e rose
cat
sample1
flower
jasmine
rose
OUTPUT :
a
b
bc
d
ef
OUTPUT :
who >
sample4 cat
sample4
student pts/1 May 4 15:50 (192.168.2.3)
student pts/11 May 4 10:47 (192.168.2.19)
root :0 May 4 14:52 (console)
OUTPUT :
13
b
c
d
ef
flower
jasmin
e rose
SYNTAX : ls
USES : Used to list out all files in a directory.
SYNTAX : ls -a
USES : Used to list out all files including hidden files ( Files that begin with ( . , .. )
SYNTAX : ls -i
USES : Used to list out all files with its i-node number in the first column.
SYNTAX : ls -r
USES : Used to list out all files in reverse alphabetical order.
SYNTAX : ls -t
USES : Used to list out all files in the order of their last modification time.
SYNTAX : ls -u
USES : Used to list out all files in the order of their last access time.
SYNTAX : ls -l
USES : Used to list out all files in long format ( one entry per line) ,giving
its mode, number of links, owner, group , size in bytes, the time that each file was last
modified.
14
SYNTAX : ls -lt
USES : Used to list out all files in long format with their last modification time.
FILTER COMMANDS
SYNTAX : wc filename
USES : It will display the no of lines , no of words and used to
display no of characters.
SYNTAX : wc -l filename
USES : Used to display no of lines in a filename.
SYNTAX : wc -w filename
USES : Used to display no of words in a filename.
SYNTAX : wc -c filename
USES : Used to display no of Characters in a filename.
COMMON COMMAND
EX:
$cat n1 $cat nithi
sridhar sridhar
ramamoorthy vikky
mahalashmi vimal
Jegan prabu
15
OUTPUT :
$comm
n1 nithi
sridhar
ramamoorth
y
mahalashmi
jegan
prhb
u
prhb
u
vikky
vimal
OPTIONS
COMPARE COMMAND
OUTPUT :
cmp sample1 sample5
sample1 sample5 differ: byte 7, line 1
OUTPUT :
cat sample1 cat sample2
flower flower
jasmine carrot
rose papaya
banana
CUT COMMAND
OUTPUT :
cat
sample1
flower
jasmine
rose
OUTPUT :
cat
sample5
flower
carrot
papaya
banana
17
cut -c 4 sample5
w
r
a
a
COPY COMMAND
PASTE COMMAND
flower ab
jasmine bc
rose d
ef
flower
jasmine
rose
UNIQUE COMMAND
EX :
OUTPU
T:
$ cat n1
sridhar
ramamoorth
y
18
mahalash
mi jegan
prhb
u
prhb
u
$ uniq n1
sridhar
ramamoorth
y
mahalashmi
jegan
prhbu
OPTIONS
OUTPUT :
$ uniq –u
n1 sridhar
ramamoorth
y
mahalashmi
jegan
OUTPUT :
$ uniq –d n1
prhbu
OUTPUT :
$ uniq –c
n1 sridhar
ramamoorth
y
mahalashmi
19
GREP COMMAND:
OPTIONS:
OUTPUT:
name: Bahirathi
OUTPUT:
$grep –c `
`alamu 3
OUTPUT:
$grep –n ` `
alamu 1: rathi
3:rgi
5:vrs
OUTPUT:
$grep –i ` ` alamu
Rathi
Raj
i
vrs
PIPE COMMANDS
PIPE SYMBOL :
20
A pipe is a mechanism, which takes the output of the command as its input for the next
command .
OUTPUT :
$ who |wc -l
TEE COMMAND:
Wild
Cards
1. *
SYNTAX : $ls *
USES : used in representing any number of characters when used in the
prefix or suffix.
2. ?
SYNTAX : $ls ?
USES : this character is use to represent one character wither in prefix
or in suffix of the filename .
SORTING COMMANDS :
Sort :
OUTPUT :
$Sort alamu
OPTIONS :
21
OUTPUT : sort –r alamu
343
56
34
12
OUTPUT :
sort –n
alamu 12
24
56
343
OUTPUT :
sort –f alamu
*
#
1
2
24
56
343
OUTPUT :
sort –u
alamu
Malathi
Raji
Rath
i
Vassant
hi Vrs
CHMOD COMMAND
22
USES : This command is used to set the three permissions for all the three
categories of users of the file . Only the owner of the file can use it .
OUTPUT:
$ chmod –w cs 2 3
Ls –l cs 2 3
Total 8
Drwx rwx r-x 2 linux 4096 jun 24 14.46 cs 23
CP COMMAND
OUTPUT:
$cp rathi :rs
Cat rs
Name :
bahirathi Roll
no: 01 cs 23
3.7.1982
OPTIONS:
SYNTAX : $cp –I filename1 filename2
USES : The –I ( interactive option , originally warns the users before
overwriting the destination file .
OUTPUT
$cp –I rs rathi
cp : overwrite ‘rathi’? n
OUTPUT
$ cp –r rs rathi
RESULT :
Thus the above UNIX commands have been executed and the output is verified.
23
DATE:
EXPT. NO.: 2(a)
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
Process id is 3394
Result:
The Program for Process System Call was implemented and the output was
verified.
19
DATE:
EXPT. NO.: 2(b)
ALGORITHM:
PROGRAM CODING:
#include <stdio.h>
#include <unistd.h>
#include<stdlib.h>
int main()
{
int pid;
pid=fork();
if(pid== -
1)
{
perror(“Fork Failed”);
exit(0);
}
If(pid==0)
{
printf("\n Child Process under Execution……");
printf(“\n Process id of the Child Process is %d”,getpid());
printf(“\n Process id of the Parent Process is %d”, getppid());
}
20
else
{
printf("\n Parent Process under Execution……");
printf(“\n Process id of the Parent Process is %d”,getpid());
printf(“\n Process id of the Child Process in Parent is %d”, getppid());
printf(“\n Process id of the Parent of Parent is %d”, getppid());
}
return(0);
}
OUTPUT:
RESULT:
21
DATE
EXPT.NO.:2(c)
Write a program using the system calls – execlp
AIM:
To write a program using the system calls of UNIX operating
system (execlp)
ALGORITHM:
#include<stdio.h>
#include<unistd.h>
Main()
{
printf(“\n Execlp System Calls”);
printf(“Displaying the Date:”);
execlp(“/bin/date”,”date”,0);
}
OUTPUT:
RESULT:
Thus the program for the system call – execlp() was implemented and
the Output was successfully Verified.
2
DATE
EXPT.NO.:2(d)
Write a program using the system calls – Wait() and Exit()
AIM:
To write a program using the system calls of UNIX operating system
(wait() and exit())
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<unistd.h>
main()
{
int i, pid;
pid=fork();
if(pid==-1)
{
perror(“Fork Failed”);
exit(0);
}
else if(pid ==0)
{
printf(“\n Child Process Starts…….”);
for (i=0;i<5;i++)
{
printf(“\n Child Process is called”,i);
}
printf(“\n Child Process ends…”);
}
else
{
wait(0);
printf(“\n Parent Process Ends…..”);
}exit(0);} 2
OUTPUT:
Result:
Thus the program for the system call – wait() and exit() was implemented and
the Output was successfully Verified
2
DATE
EXPT.NO.:2(e)
Write a program using the system calls –Open() read() and
write()
AIM:
To write the program to implement the system calls open( ),read( ) and
write( ).
ALGORITHM :
PROGRAM 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(“Cat File1 is \n Hai”); 25
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”)
; return0;
}
OUTPUT:
RESULT:
Thus the program for the system call –open(), read() and write() was
implemented and the Output was successfully Verified
26
DATE
EXPT.NO.:2(f)
Write a program using the system calls –opendir() readdir() and
closedir()
AIM :
ALGORITHM :
Step 1 : Start.
Step 2 : In the main function pass the arguments.
Step 3 : Create structure as stat buff and the variables as integer.
Step 4 : Using the for loop,initialization
PROGRAM CODING:
#include<stdio.h>
#include<sys/types.h>
#include<sys/dir.h>
void main(int age,char *argv[])
{
DIR *dir;
struct dirent *rddir;
printf("\n Listing the directory
content\n"); dir=opendir(argv[1]);
while((rddir=readdir(dir))!=NULL)
{
printf("%s\t\n",rddir->d_name);
}
closedir(dir);
}
OUTPUT
RP
roshi.c
first.c
pk6.c f2
abc FILE1
RESULT:
Thus the program for the system call –opendir(), readdir() and closedir()
was implemented and the Output wassuccessfully Verified
27
DATE:
EXPT.NO.:3(a)
Write a programs to simulate ls UNIX
commands
AIM:
To write a program to simulate UNIX commands like ls
ALGORITHM:
1. Start the program.
2. Read the input through command line.
3. Open the specified file.
4. Options (c & i) are performed.
5. Stop the program.
PROGRAM:
#include<stdio.h>
#include<dirent.h>
int main(int ag,char* arg[])
{
Struct dirent **namelist;
int n,i;
char
pathname[100];
n=scandir(“pathname,&namelist,0,alphasort);
if(n<0)
printf(“\n Error”);
else
for(i=0;i<n;i++)
printf(“%s\n”,namelist[i]->d_name);
}
28
OUTPUT:
aaa
.
..
.bash_history
.bash_logout
.bash_profile
.bashre
emacs
lab1.c.swp
.mozilla
Progf.c.swo
Progf.c.swp
.viminfo
a.out
big.sh
big1.sh
even.sh
fact.sh
lab1.c
lab2.c
q1.c
q1.sh
q2.sh
q4.sh
RESULT:
29
DATE:
EXPT.NO.:3(b)
Write a programs to simulate grep UNIX
commands
AIM:
To write a program to simulate UNIX commands like grep
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
FILE *fp;
char c[100], pat[10];
int i,j=0,l,count=0,len,k,flag = 0;
printf(“\n Enter the Pattern :”);
scanf(“%s”,pat);
len=strlen(pat);
fp=fopen(“nn.txt”,”r”);
while(!feof(fp))
{
fscanf(fp,”%s”,c);
l=strlen©;
count++;
for(i=0;i<count;i++)
{
30
{
flag = 0;
for(k=1;k<i;k++)
{
if(c[i+k]!=pat[k])
flag=1;
}
if (flag==0)
printf(“\n The Pattern %s is present in the word %d”,pat, count);
} }
}
}
nn.text
Apple
Orange
Guava
Pomogranat
e
Banana
Mangoes
OUTPUT:
RESULT:
Thus the program to simulate the UNIX commands like grep was
executed and the output was verified successfully.
31
DATE:
EXPT.NO.:4(a)
ALGORITHM:
PROGRAM:
OUTPUT:
bash q1.sh
RESULT:
Thus the Shell program for calculating the value from quadratic
equations was implemented and output verified successfully.
32
DATE:
EXPT.NO.:4(
b) SWAPPING OF TWO NUMBERS
AIM:
To write a shell program to swap the two numbers.
ALGORITHM:
PROGRAM:
OUTPUT:
bash q2.sh
Thus the Shell program for swapping the two numbers was
33
implemented and output verified successfully.
34
DATE:
EXPT.NO.:4(
c) BIGGEST OF THREE NUMBERS
AIM:
To write a Shell Program to Find Biggest In Three Numbers.
ALGORITHM:
PROGRAM:
bash big1.sh
92 is greater
RESUL
T:
Thus the Shell program for finding biggest of three numbers was
implemented and output verified using various samples.
35
DATE:
EXPT.NO.:4(
d) GIVEN NUMBER IS ODD OR EVEN
AIM:
To write a program to find whether a number is even or odd.
ALGORITHM:
PROGRAM:
OUTPUT:
bash even.sh
80 is Even Number
RESULT:
Thus the Shell program for finding the given number is ODD or EVEN
was implemented and output verified using various samples.
36
DATE:
EXPT.NO.:4(
e)
ARITHEMETIC OPERATIONS
AIM:
a=1
0
b=2
0
val=$((a + b))
echo "a + b :
$val" val=$((a -
b))
echo "a - b :
$val" val=$((a *
b)) echo "a * b :
$val" val=$((b %
a))
OUTPUT:
bash
q4.sh a +
b : 30 a -
b : -10
a * b : 200
b/a:2
RESULT:
Thus the Shell program for finding the Arithmetic Operations was
37
implemented and output verified using various samples.
38
DATE:
EXPT.NO.:4(
f)
FACTORIAL VALUE
AIM:
OUTPUT:
bash fact.sh
5 Factorial of 5 is
120
RESULT:
Thus the Shell program for finding Factorial of a given Number was
39
implemented and output verified using various samples.
40
DATE:
EXPT.NO.:5(
a) FCFS SCHEDULING
AIM:
To write a C program to implement the array representation of the
CPU scheduling algorithm first come first serve using arrival time.
ALGORITHM:
41
PROGRAM CODING:
#include<stdio.h
>
#include<conio.
h> void main()
{
int n, b[10], w[10],i,j,h;
int tat[10];
float avg=0, avgtt=0;
clrscr();
printf("\n FCFS Job
Scheduling"); printf("\n Enter the
No. of Jobs:"); scanf("%d",&n);
printf("\n Enter the Burst Time:");
for(i=0;i<n;i++)
{
printf("\n Process %d:", i+1);
scanf("%d",&b[i]);
}
w[0] = 0; tat[0]=b[0];
printf("\n Process 1 waiting time is 0");
for(i=1;i<n;i++)
{
w[i]=b[i-1] + w[i-1];
printf("\n Process %d Waiting Time %d", i+1, w[i]);
avg=avg+w[i];
}
printf("\n Total Waiting Time : %f", avg);
printf("\n The avg. Waiting Time:
%f",avg/n); for(i=0;i<n;i++)
{
tat[i]=b[i] + w[i];
printf("\n Process %d Turnaround Time %d", i,
tat[i]); avgtt += tat[i];
}
printf("\n Total Turnaround Time : %f",avgtt);
printf("\n Avg. Turn around time %f",
avgtt/n); getch();
}
42
OUTPUT:
FCFS Job Scheduling
Enter the No. of Jobs :
3
Process 2: 6
Process 3: 7
RESULT:
Thus the program for generating CPU scheduling algorithm first come first
serve using arrival time was implemented and output verified using various
samples.
43
DATE
EXPT.NO.:5(
b) SJF SCHEDULING
AIM:
A program to simulate the SJF CPU scheduling algorithm .
ALGORITHM:
Step 1: Get the number of process.
Step 2: Get the id and service time for each process.
Step 3: Initially the waiting time of first short process as 0 and total time
of first short is process the service time of that process.
Step 4: Calculate the total time and waiting time of remaining
process.
Step 5: Waiting time of one process is the total time of the
previous process.
Step 6: Total time of process is calculated by adding the waiting
time and service time of each process.
Step 7: Total waiting time calculated by adding the waiting time of
each process.
Step 8: Total turnaround time calculated by adding all total time of
each process.
Step 9: Calculate average waiting time by dividing the total waiting time
by total number of process.
Step 10: Calculate average turnaround time by dividing the total waiting time
by total number of process.
Step11: Display the result.
PROGRAM CODING:
#include<stdio.h
>
#include<conio.
h> void main()
{
int n, b[10], w[10],i,j,h,t,tt,turn[10];
int a[10];
float avg=0,
avgtt=0; clrscr();
printf("\n Shortest Job Scheduling");
printf("\n Enter the No. of
44
Processes:"); scanf("%d",&n);
45
for(i=0;i<n;i++)
{
printf("\n Process %d:", i+1);
scanf("%d",&b[i]);
a[i]=i;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(b[i]<b[j])
{
t = b[i];
tt = a[i];
b[i]=b[j];
a[i]=a[j];
b[j]=t;
a[j]=tt;
}
}
}
w[0] = 0; turn[0]=b[0];
for(i=1;i<n;i++)
{
w[i]=b[i-1] + w[i-1];
avg=avg+w[i];
}
for(i=0;i<n;i++)
{
turn[i]=b[i] + w[i];
avgtt += turn[i];
}
printf("\n Process Id\t Burst Time \t Waiting Time \t Turn Around Time
\n"); for(i=0;i<n;i++)
{
printf("%d\t\t %d\t\t %d\t\t %d\n", a[i],b[i], w[i],turn[i]);
}
printf("\n Total Waiting Time : %f", avg);
printf("\n Total Turn Around Time
:%f",avgtt); avg=avg/n;
printf("\n The avg. Waiting Time:
%f",avg); avgtt=avgtt/n;
printf("\n Avg. Turn around time %f",
avgtt); getch();
}
46
OUTPUT:
Shortest Job Scheduling
Enter the No. of
Processes:3
Process 2 : 4
Process 3 : 6
RESULT:
Thus the program for generating CPU scheduling algorithm for SJF
using arrival time was implemented and output verified using various samples.
47
DATE:
EXPT.NO.:5(c)
PRIORITY SCHEDULING
AIM
:
ALGORITHM:
Step 1: Get the number of process
Step 2: Get the id and service time for each process.
Step 3: Initially the waiting time of first short process as 0 and total time
of first short is process the service time of that process.
Step 4: Calculate the total time and waiting time of remaining process.
Step 5: Waiting time of one process is the total time of the
previous process.
Step 6: Total time of process is calculated by adding the waiting
time and service time of each process.
Step 7: Total waiting time calculated by adding the waiting time of each
process.
Step 8:Total turnaround time calculated by adding all total time of
each process.
Step 9: Calculate average waiting time by dividing the total waiting time by
total number of process.
Step 10: Calculate average turnaround time by dividing the total
waiting time by total number of process.
Step 11: Display the result.
PROGRAM CODING:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
OUTPUT:
Input:
Output:
RESULT:
Thus the program for generating CPU scheduling algorithm for priority using
arrival time was implemented and output verified using various samples.
46
DATE
EXPT.NO.:5(d
)
AIM:
A program to simulate the Round Robin CPU scheduling algorithm.
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int et[30],ts,n,i,x=0,tot=0; char pn[10][10];
clrscr();
printf("Enter the no of processes:");
47
scanf("%d",&n);
48
printf("Enter the time quantum:");
scanf("%d",&ts);
for(i=0;i<n;i++)
{
printf("enter process name & estimated time:");
scanf("%s %d",pn[i],&et[i]);
}
printf("The processes are:");
for(i=0;i<n;i++)
printf("process %d: %s\n",i+1,pn[i]);
for(i=0;i<n;i++)
tot=tot+et[i];
while(x!=tot)
{
for(i=0;i<n;i++)
{
if(et[i]>ts)
{
x=x+ts;
printf("\n %s -> %d",pn[i],ts);
et[i]=et[i]-ts;
}
else if((et[i]<=ts)&&et[i]!=0)
{
x=x+et[i];
printf("\n %s -> %d",pn[i],et[i]); et[i]=0;}
}
}
printf("\n Total Estimated Time:%d",x);
getch();
}
49
OUTPUT:
Input:
Enter the no of
processes: 2 Enter the
time quantum: 3
Output:
p1 -> 3
p2 -> 3
p1 -> 3
p2 -> 3
p1 -> 3
p2 -> 3
p1 -> 3
p2 -> 3
p2 -> 3
RESULT:
Thus the program for generating CPU scheduling algorithm for round robin
using arrival time was implemented and output verified using various samples.
50
DATE:
EXPT.NO.:6( FILE ALLOCATION STRATERGIES
a) SEQUENTIAL ALLOCATION
AIM:
ALGORITHM:
51
PROGRAM:
#include<stdio.h>
main()
{
int f[50],i,st,j,len,c,k;
clrscr();
for(i=0;i<50;i++)
f[i]=0;
X:
printf("\n Enter the starting block & length of file");
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already allocated");
break;
}
if(j==(st+len))
printf("\n the file is allocated to disk");
printf("\n if u want to enter more files?(y-1/n-0)");
scanf("%d",&c);
if(c==1) goto X;
else exit();
getch();
}
51
Output:
4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
The file is allocated to disk
If you want to enter more files? (Y-1/N-0)
RESULT:
Thus the C program for File Allocation concept using the technique
sequential Allocation was implemented and output was verified using
various samples.
52
DATE: INDEXED ALLOCATION
EXPT.NO.:6(
b)
AIM:
To write a C program to implement File Allocation concept using the
indexed allocation Technique.
ALGORITHM:
PROGRAM:
#include<stdio.h>
main()
{
int f[50],p,i,j,k,a,st,len,n,c;
clrscr(); for(i=0;i<50;i++)
f[i]=0;
printf("Enter how many blocks that are already allocated");
scanf("%d",&p);
printf("\nEnter the blocks no.s that are already allocated");
for(i=0;i<p;i++)
{ scanf("%d",&a);
f[a]=1;
} X:
printf("Enter the starting index block & length");
for(j=st;j<(k+st);j++) 53
scanf("%d%d",&st,&len);
for(j=st;j<(k+st);j++) 53
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;
}
}
printf("\n If u want to enter one more file? (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch( );
}
54
OUTPUT:
Enter how many blocks are already allocated 3
Enter the blocks no’s that are already allocated 479
Enter the starting index block & length 3
7
3-> 1
4- > File is already allocated
5->1
6->1
7-> File is already allocated
8->1
9-> File is already allocated
10->1
11->1
12->1
If u want to enter one more file? (yes-1/no-0)
RESULT:
Thus the C program for File Allocation concept using the technique indexed
Allocation was implemented and output was verified using various samples.
55
DATE:
EXPT.NO.:6(
c) LINKED ALLOCATION
AIM:
To write a C program to implement File Allocation concept using the
linked list allocation Technique.
ALGORITHM:
PROGRAM:
#include<stdio.h>
main( )
{
int f[50],i,k,j,index[50],n,c,count=0;
for(i=0;i<50;i++)
f[i]=0;
X:
printf("Enter index block");
scanf("%d",&i);
if(f[i]!=1)
{
f[i]=1;
printf("Enter no of files on index");
scanf("%d",&n);
}
Y:
for(i=0;i<n;i++)
scanf("%d",&index[i]);
if(f[index[i]]==0) count++;
if(count==n)
{
for(j=0;j<nj++)
f[index[j]]=1;
printf("\nAllocated");
printf("\n File indexed");
56
for(k=0;k<n;k++)
printf("\n%d->%d:%d",i,index[k],f[index[k]]);
}
else
{
printf("\nFile in the index already allocation");
printf("\nEnter another file indexed");
goto Y;
}
printf("\nIndex is already allocated");
count=0;
printf("\n if u enter one more block(1/0)");
scanf("%d",&c);
if(c==1)
goto X;
}
OUTPUT:
Enter how many blocks already
allocated 5
Enter block numbers : 3 7 9 10 14
Enter index starting block & length : 4 10
4->1
5- >1
6- >1
7- >file is already
allocated 8->1
9->file is already
allocated 10->file is
already allocated 11->1
12->1
13->1
14->file is already
allocated 15->1
16->1
17->1
RESULT:
Thus the C program for File Allocation concept using the technique
linked list Allocation was implemented and output was verified using
various samples.
57
DATE:
EXPT.NO.:7
SEMAPHORE USING PRODUCER CONSUMER PROBLEM
AIM:
ALGORITHM:
ii) If there is empty space in the buffer check the mutex value for enter
into the critical section.
iii) If the mutex value is 0, allow the producer to add value in the
temporary variable to the buffer.
Step 3: In the case of consumer process
i) It should wait if the buffer is empty
ii) If there is any item in the buffer check for mutex value, if the
mutex==0, remove item from buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.
Step 4: Print the result
58
PROGRAM:
#include<stdio.h>
void main()
{
int buffer[10], bufsize, in, out, produce, consume, choice=0;
in = 0; out = 0; bufsize = 10;
while(choice !=3)
{
printf("\n1. Produce \t 2. Consume \t3. Exit");
printf("\nEnter your choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1: if((in+1)%bufsize==out)
printf("\nBuffer is Full");
else
{
printf("\nEnter the value: ");
scanf("%d", &produce);
buffer[in] = produce;
in = (in+1)%bufsize;
}
break;
case 2: if(in == out)
printf("\nBuffer is Empty");
else
{
consume = buffer[out];
printf("\nThe consumed valueis %d", consume);
out = (out+1)%bufsize;
}
break;
}
}
}
59
OUTPUT:
1. Producer 2. Consumer 3.Exit
RESULT:
Thus the C program for the Producer and Consumer using the
technique Semaphore was implemented and output was verified using
various samples.
60
DATE:
EXPT.NO.:8. a
SHARED MEMORY
AIM:
ALGORITHM:
62
{
shmid=shmget(2041,32,0666);
shmptr=shmat(shmid,0,0);
printf("\nCHILD IS READING");
for(i=0;i<10;i++)
putchar(shmptr[i]);
shmdt(NULL);
shmct(shmid,IPC_RMID,NULL);
}
return 0;
}
OUTPUT:
RESULT:
Thus the program for shared memory was implemented and the output
executed successfully.
63
DATE:
EXPT.NO.:8. b
INTER PROCESS COMMUNICATION
AIM:
ALGORITHM:
PROGRAM CODING:
#include <stdio.h>
main()
{
int fd[2],child;
char a[10];
printf("Enter the string to enter into the pipe:");
scanf("%s",a); pipe(fd);
child=fork();
if(!child)
{
close(fd[0]);
write(fd[1],a,5);
write(0);
}
64
else
{
close(fd[1]);
read(fd[0],a,5);
printf("string is retrived from the pipe is%s\n",a);
}
}
OUTPUT:
RESULT:
Thus the program for Inter Process Communication was implemented and
the output executed successfully.
65
DATE:
EXPT.NO.:9
IMPLEMENTATION OF DEADLOCK DETECTION
ALGORITHM
AIM:
ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and in data types.
Step 3: Obtain the number of process, resources
instances, max and allocation matrix.
Step 4: Enter the available resources.
Step 5: Display the process, available, max , allocation. Step 6: Calculate the
deadlock process and print the deadlock systems if need is greater.
Step 7: Else print the deadlock not occurred process.
Step 8: Stop the program execution.
PROGRAM 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++)
66
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++)
{
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]) 67
{
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:");
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();
}
68
OUTPUT:
P0 p1 p2
RESULT:
Thus the program for the Deadlock Detection concept was implemented and
output was verified using various samples.
69
DATE:
EXPT.NO.:10
IMPLEMENTATION OF DEADLOCK AVOIDANCE
ALGORITHM
AIM:
ALGORITHM:
Step 6: If the new request comes then check that the system is in safety
PROGRAM CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,i,j,k,p,u=0,s=0,m;
int block[10],run[10],active[10],newreq[10];
int max[10][10],resalloc[10][10],resreq[10][10];
int totalloc[10],totext[10],simalloc[10];
clrscr();
printf("Enter the no of processes:");
scanf("%d",&n);
printf("Enter the no ofresource classes:");
scanf("%d",&r);
printf("Enter the total existed resource in each class:");
scanf("%d",&totext[k]); 70
printf("Enter the allocated resources:");
for(i=1; i<=n; i++)
for(k=1; k<=r; k++)
scanf("%d",&resalloc);
printf("Enter the process making the new request:");
scanf("%d",&p);
printf("Enter the requested resource:");
for(k=1; k<=r; k++)
scanf("%d",&newreq[k]);
printf("Enter the process which are n blocked or running:");
for(i=1; i<=n; i++)
{
if(i!=p)
{
printf("process %d:\n",i+1);
scanf("%d%d",&block[i],&run[i]);
}
}
block[p]=0;
run[p]=0;
for(k=1; k<=r; k++)
{
j=0;
for(i=1; i<=n; i++)
{
totalloc[k]=j+resalloc[i][k];
j=totalloc[k];
}
}
for(i=1; i<=n; i++)
{
if(block[i]==1||run[i]==1)
active[i]=1;
else
active[i]=0;
}
for(k=1; k<=r; k++)
{
resalloc[p][k]+=newreq[k];
totalloc[k]+=newreq[k];
}
for(k=1; k<=r; k++)
{
if(totext[k]-totalloc[k]<0)
{
u=1; 71
break;
}
}
if(u==0)
{
for(k=1; k<=r; k++)
simalloc[k]=totalloc[k];
for(s=1; s<=n; s++)
for(i=1; i<=n; i++)
{
if(active[i]==1)
{
j=0;
for(k=1; k<=r; k++)
{
if((totext[k]-simalloc[k])<(max[i][k]-resalloc[i][k]))
{
j=1;
break;
}}}
if(j==0)
{
active[i]=0;
for(k=1; k<=r; k++)
simalloc[k]=resalloc[i][k];
}
}
m=0;
for(k=1; k<=r; k++)
resreq[p][k]=newreq[k];
printf("Deadlock willn't occur");
}
else
{
for(k=1; k<=r; k++)
{
resalloc[p][k]=newreq[k];
totalloc[k]=newreq[k];
}
printf("Deadlock will occur");
}
getch();
}
72
OUTPUT:
RESULT:
Thus the program for the Deadlock Avoidance concept was implemented and
output was verified using various samples.
73
DATE:
EXPT.NO.:11(a)
THREADING
APPLICATIONS
AIM:
ALGORITHM:
PROGRAM CODING:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
void * thread1()
{
while(1)
{
printf("Hello!!\n");
}
}
void * thread2()
{
while(1)
{
printf("How are you?\n");
74
}
}
int main()
{
int status;
pthread_t tid1,tid2;
pthread_create(&tid1,NULL,thre
ad1,NULL);
pthread_create(&tid2,NULL,thre
ad2,NULL);
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
return 0;
}
OUTPUT:
RESULT:
75
DATE:
EXPT.NO.:11(b)
SYNCHRONIZATION APPLICATIONS
AIM:
ALGORITHM:
PROGRAM CODING:
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0 char n[1024];
pthread_mutex_t lock= PTHREAD_MUTEX_INITIALIZER;
int string_read=FALSE;
pthread_cond_t cond;
void * read1()
{
while(1)
{
while(string_read);
pthread_mutex_lock(&lock);
printf("Enter a string: ");
scanf("%s",n);
string_read=TRUE;
75
pthread_mutex_unlock(&lock);
pthread_cond_signal(&cond);
}
}
void * write1()
{
while(1)
{
pthread_mutex_lock(&lock);
while(!string_read)
pthread_cond_wait(&cond,&lock);
printf("The string entered is %s\n",n);
string_read=FALSE;
pthread_mutex_unlock(&lock);
}
}
int main()
{
int status; pthread_t tr, tw;
pthread_create(&tr,NULL,read1,NULL);
pthread_create(&tw,NULL,write1,NULL);
pthread_join(tr,NULL); pthread_join(tw,NULL);
return 0;
}
OUTPUT:
RESULT:
Thus the program for Synchronization was implemented and executed and
the output was verified successfully.
76
DATE:
EXPT.NO.:12(a)
MEMORY ALLOCATION METHODS FOR FIXED
PARTITION – FIRST FIT
AIM:
ALGORITHM:
PROGRAM CODING:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - First Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{ 7
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
7
OUTPUT:
Memory Management Scheme - First Fit
Enter the number of blocks:5
Enter the number of files:4
Enter the size of the blocks:
Block 1:140
Block 2:160
Block 3:270
Block 4:80
Block 5:56
Enter the size of the files :
File 1:200
File 2:130
File 3:180
File 4:200
RESULT:
Thus the program for Memory Allocation Methods for Fixed Partition
using the First Fit was executed successfully.
79
DATE:
EXPT.NO.:12(b)
MEMORY ALLOCATION METHODS FOR FIXED PARTITION –
WORST FIT
AIM:
ALGORITHM:
PROGRAM CODING:
#include<stdio.h
>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
static int bf[max],ff[max];
clrscr();
printf("\n\tMemory Management Scheme - Worst Fit");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
80
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1) //if bf[j] is not allocated
{
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
{
ff[i]=j;
highest=temp;
}
}
}
frag[i]=highest;
bf[ff[i]]=1;
highest=0;
}
printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");
for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
81
OUTPUT:
Memory Management Scheme - Worst Fit
Enter the number of blocks:5
Enter the number of files:4
Enter the size of the blocks:
Block 1:140
Block 2:160
Block 3:270
Block 4:80
Block 5:56
Enter the size of the files :
File 1:200
File 2:130
File 3:180
File 4:200
RESULT:
Thus the program for Memory Allocation Methods for Fixed Partition
using the Worst Fit was executed successfully.
82
DATE:
EXPT.NO.:12(c)
MEMORY ALLOCATION METHODS FOR FIXED PARTITION –
BEST FIT
AIM:
ALGORITHM:
PROGRAM CODING:
#include<stdio.h>
#include<conio.h>
#define max 25
void main()
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
clrscr();
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
84
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");
for(i=1;i<=nf && ff[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
getch();
}
85
OUTPUT:
Memory Management Scheme - Best Fit
Enter the number of blocks:5
Enter the number of files:4
Enter the size of the blocks:
Block 1:140
Block 2:160
Block 3:270
Block 4:80
Block 5:56
Enter the size of the files :
File 1:200
File 2:130
File 3:180
File 4:200
RESULT:
Thus the program for Memory Allocation Methods for Fixed Partition
using the Worst Fit was executed successfully.
86
DATE:
EXPT.NO.:
13 PAGING TECHNIQUE OF MEMORY MANAGEMENT
AIM:
ALGORITHM:
87
OUTPUT:
“page.c" 34L, 1129C written
[2cse110@cse ~]$cc page.c
[2cse110@cse ~]$ ./a.out
Enter how many pages
3
Enter the
page size
2
page1 address 147984408
page2 address 147984424
page3 address 147984440
RESULT:
88
DATE:
EXPT.NO.:14(a)
PAGE REPLACEMENT ALGORITHMS - FIFO
AIM:
ALGORITHM:
PROGRAM CODING:
#include<stdio.h
>
#include<conio.h
> void main()
{
int
a[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;
char f='F';
clrscr();
printf("Enter the Number of Pages:");
scanf("%d",&n);
printf("Enter %d Page
Numbers:",n); for(i=0;i<n;i++)
scanf("%d",&b[i]);
89
{if(p==0)
{
if(q>=3
) q=0;
a[q]=b[i]
; q++;
if(q1<3)
{
q1=q;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
}
p=0;
for(k=0;k<q1;k++)
{
if(b[i+1]==a[k])
p=1;
}
}
printf("\nNo of faults:%d",m);
getch();
}
90
OUTPUT:
2 2-> F
3 23-> F
2 23
1 231-> F
5531-> F
2521-> F
4524-> F
5524
3 324-> F
2 324
5 354-> F
2 352-> F
No of faults: 9
RESULT:
Thus the program for Page Replacement Algorithm using the First in
First out was executed successfully.
91
DATE:
EXPT.NO.:14(b)
PAGE REPLACEMENT ALGORITHMS - LRU
AIM:
ALGORITHM:
PROGRAM CODING:
#include<stdio.h>
#include<conio.h> void main()
{
int g=0,a[5],b[20],p=0,q=0,m=0,h,k,i,q1=1,j,u,n; char f='F';
clrscr();
printf("Enter the number of pages:");
scanf("%d",&n);
printf("Enter %d Page Numbers:",n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
if(p==0)
{
if(q>=3)
q=0; a[q]=b[i];
q++;
if(q1<3)
{
q1=q; 91
//g=1;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
}
p=0; g=0;
if(q1==3)
{
for(k=0;k<q1;k++)
{
if(b[i+1]==a[k
]) p=1;
}
for(j=0;j<q1;j++)
{
u=0;
k=i;
while(k>=(i-1)&&(k>=0))
{
if(b[k]==a[j]
) u++;k--;
}
if(u==0)
q=j;
}
}
else
{
for(k=0;k<q;k++)
{
if(b[i+1]==a[k
])
p=1;
}
}
}
printf("\nNo of faults:%d",m);
getch();} 92
OUTPUT:
2 2-> F
3 2 3-> F
2 23
1 2 3 1-> F
5 2 5 1-> F
2 251
4 2 5 4-> F
5 254
3 3 5 4-> F
2 3 5 2-> F
5 3 5 2
2 3 5 2
No of faults: 7
RESULT:
Thus the program for Page Replacement Algorithm using the Least
Recently Used was executed successfully.
93
DATE:
EXPT.NO.:14(c)
PAGE REPLACEMENT ALGORITHMS - LFU
AIM:
ALGORITHM:
PROGRAM CODING:
#include<stdio.h>
void main()
{
Int
q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
clrscr();
printf("Enter no of pages:");
scanf("%d",&n);
printf("Enter the reference string:");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of
frames:"); scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{ 94
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}
if(c1==f)
{
c++
;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("\t%d",q[j]);
printf("\n");
}
else
{
for(r=0;r<f;r++)
{
c2[r]=0;
for(j=i-1;j<n;j++)
{
if(q[r]!=p[j])
c2[r]++;
else
break;
}
}
for(r=0;r<f;r++)
b[r]=c2[r];
for(r=0;r<f;r++)
{
for(j=r;j<f;j++)
{
if(b[r]<b[j])
{
t=b[r]; 95
b[r]=b[j];
b[j]=t;
}
}
}
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
}
printf("\n");
}
}
}
printf("\nThe no of page faults is %d",c);
}
OUTPUT:
2 2-> F
3 2 3-> F
2 23
1 2 3 1-> F
5 2 5 1-> F
2 251
4 2 5 4-> F
5 254
3 3 5 4-> F
2 3 5 2-> F
5 3 5 2
2 3 5 2
No of faults: 7
96
RESULT:
Thus the program for Page Replacement Algorithm using the Least
Frequently Used was executed successfully.
97
DATE:
EXPT.NO.:15(a)
ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and int data types.
Step 3: Enter the filename,
index block.
Step 4: Print the file name index loop.
Step 5: Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked
allocation. Step 7: Stop the execution
PROGRAM 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 the Number of Directories:");
scanf("%d",&master);
printf("Enter the Names of the
Directories:"); for(i=0;i<master;i++)
printf("Enter the Size of the
Directories:"); for(i=0;i<master;i++)
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\tfile Names\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();
}
OUTPUT
99
RESULT:
Thus the program for File Organization Technique using the Single level
Directory was executed successfully.
10
DATE:
EXPT.NO.:15(b)
ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and int data
types. Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.
Step 5: Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked
allocation. Step 7: Stop the execution
PROGRAM 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;
scanf("%d",&n 101
for(i=0;i<n;i++)
{
printf("Enter Directory %d Names:",i+1);
scanf("%s",&dir[i].dname);
printf("Enter the Size of the
Directories:"); scanf("%d",&dir[i].ds);
for(j=0;j<dir[i].ds;j++)
{
printf("Enter the 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");
}
getch();
}
102
OUTPUT
Enter number of
Directories: 1 Enter Directory
1 Names: Files Enter the Size of
the Directories: 2
Enter the Subdirectory Name and Size: Program 1
Enter File Name: Basics
RESULT:
Thus the program for File Organization Technique using the Two level
Directory was executed successfully.
103
DATE:
EXPT.NO.:15(
b)
ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and int data types.
Step 3: Enter the filename,
index block.
Step 4: Print the file name index loop.
Step 5: Fill is allocated to the unused index blocks
Step 6: This is allocated to the unused linked
allocation. Step 7: Stop the execution
PROGRAM 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()
{
clrscr();
create(&root,0,"root",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);
printf("enter 1 for Dir/2 forfile
:"); 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+
+)
(*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+1g0a5p/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
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 subdirectories / files (for ROOT) :2
Enter Name of dir/file (under
ROOT):USER 1 Enter 1 for Dir /2 for file:1
No of subdirectories /files (for USER 1):1
Enter Name of dir/file (under USER
1):SUBDIR Enter 1 for Dir /2 for file:1 10
No of subdirectories /files (for
SUBDIR):2 Enter Name of dir/file
(under USER 1): JAVA Enter 1 for Dir
/2 for file:1
No of subdirectories /files (for JAVA): 0
Enter Name of dir/file (under
SUBDIR):VB
107
file:2
RESULT:
Thus the program for File Organization Technique using the Hierarchical
level Directory was executed successfully.
108