Operating System Lab Manual
Operating System Lab Manual
AIM:
To know how to install the windows operating system
INTRODUCTION:
Each version of Microsoft Windows is installed on a computer using similar steps. While
there are steps in the installation process that differ between versions of Windows, the following
general steps and guidelines help you install Windows on your computer. The steps below are for all
recent versions of Windows, including Windows 98, Windows ME, Windows 2000, Windows
XP, Windows Vista, Windows 7, Windows 8, Windows 10, and Windows 11. These steps even
work for earlier versions (e.g., Windows 95) as long as you use the disc version. The floppy diskette
version is similar, but it requires additional steps.
1
* If pressing F2 opens a diagnostics tool, your setup key is likely F10.
* F10 is also used for the boot menu. If pressing F10 opens a boot menu, your setup key is likely F2.
Setup keys are to be pressed as the computer is booting up. Most users see a message similar
to the example below upon startup. Some older computers may also display a flashing block of text
to indicate when to press F1 or F2.
Press F2 to enter BIOS setup.Once you have successfully entered the CMOS setup, a screen
similar to the example below appears. Your CMOS setup may look different, depending on the
manufacturer, but it should still share a lot of the same options and information.
Acer BIOS:
If your Acer computer cannot boot or you want to restore the BIOS to its original settings,
press and hold the F10 as you turn on the computer. While holding F10, two beeps should be heard
to indicate the settings are restored.
AMI BIOS:
Older AMI BIOS could be restored to bootable settings by pressing and holding ,Insert as the
computer is booting.
BIOS or CMOS diskettes:
Early 486, 386, and 286 computers required a floppy disk to enter the BIOS setup. These
diskettes may be called ICU, BBU, or SCU disks. Because these diskettes are unique to your
computer manufacturer, you must obtain the diskettes from them. See the computer manufacturers
list for contact information.
Access BIOS on early IBM computers:
Some early IBM computers require you to press and hold both mouse buttons as the
computer boots to enter the BIOS setup.
Additional suggestions for accessing BIOS or CMOS:
Finally, if none of the above suggestions allow access to the setup, try generating a stuck key
error, which gives an option to enter the BIOS or CMOS setup. To do this, press and hold any key
on the keyboard, and do not let go (you may get several beeps as you are doing this). Keep pressing
the key until the computer stops booting, and you have the option to enter setup. If this does not
work, make sure your keyboard is working. 2
HOW TO EXIT THE BIOS OR CMOS:
There are several ways to exit the BIOS or CMOS setup depending on the computer's type. The
most common methods include the following.
Press the Esc key to exit without saving any changes.
Press the F10 or F12 key to save changes and exit.
Access the Exit or Save & Exit tab in setup and select the Exit or Save and Exit option.
If you have trouble exiting the BIOS or CMOS setup, you can try the following methods to fix the
problem.
Press the F9 key to load default settings and press F10 to save and exit.
Access the Exit or Save & Exit tab in setup, select the Load Optimized Defaults option,
select Yes, and press Enter. Any changes made are reverted, and the BIOS or CMOS is set
back to default settings.
Turn off the computer (use only as a last resort and with caution).
3
FINAL WINDOWS AND COMPUTER CONFIGURATION:
After Windows is installed on the computer, you need to install the drivers and related
software for the hardware in the computer. You can use the installation discs that came with the
hardware or download the drivers from the hardware manufacturer's website.We strongly
recommend you install the latest drivers for each piece of hardware.
To determine which hardware needs drivers to be installed, check the Device Manager and
look for the exclamation mark "!" next to hardware devices. The exclamation point means drivers
are needed for that device.After installing the necessary hardware device drivers, install any software
programs on the computer that you want to use.
Finally, download and install any available Windows updates. Updating Windows improves
the operating system's performance, the hardware in the computer, and the software programs you
use. It can also improve security by fixing potential security holes and flaws in Windows.
RESULT:
Thus the study exercise for installing windows operating system is studied successfully
4
EX NO: 2
BASIC UNIX COMMANDS
DATE:
AIM:
To implement the Basic unix commands.
COMMANDS:
1.1 GENERAL PURPOSE COMMANDS:
1. THE DATE COMMAND:
7. THE id COMMAND:
[exam@fosslab ~]$ id
uid=662(exam) gid=662(exam) groups=662(exam)
1.CREATE A DIRECTORY:
[exam@fosslab ~]$ mkdir student
[exam@fosslab ~]$ cd student
[exam@fosslab student]$
6. THE PATH
4.MOVING A FILE:
[exam@fosslab student~]$ cat >test1
the basic unix commands are cat,pwd,clear,cp,mv,rm,mv,test..^C
mv:
[exam@fosslab student ~]$ mv test test1
[exam@fosslab student ~]$ cat test 1
the basic unix commands are cat, pwd, mkdir, rmdir, cd, path,clear,cp,rm,
mv,ls,wc.
9
4. SELECTING FIELDS FROM A LINE:
cut
[exam@fosslab ~]$ cat >std
Aswini
Bharathi
Charu
Deepa^C
[exam@fosslab ~]$ cut -c1 std
A
B
C
D
5. THE more COMMAND:
[exam@fosslab ~]$ more test1
a.out
data
mylist
program
public_html
stud25
student
test
test1
6. PASTING FILES:
[exam@fosslab ~]$ paste std
Aswini
Bharathi
Charu
Deepa
7. COMPARING FILES:
cmp
[exam@fosslab ~]$ cmp test1 std
test1 std differ: byte 1, line 1
8. THE mesg COMMAND:
mesg
[exam@fosslab ~]$ mesg exam25
Usage: mesg [y|n]
[exam@fosslab ~]$ y
Message from [email protected] on pts/0 at 12:34 ...
hiiiii ... study well for your exams
hiiiii ... study well for your exams
RESULT:
Thus the basic UNIX commands were executed successfully.
11
EX NO: 3
SHELL PROGRAMMING
DATE:
SHELL SCRIPT:
echo "enter radius"read r
val=`expr 3 \* $r \* $r`echo
"$val"
OUTPUT:
RESULT:
Thus the shell program to find the area of circle is written and executed successfully
12
EX NO: 3B
SHELL PROGRAMMING – BIGGEST OF TWO NUMBERS
DATE:
AIM:
To write a shell program to find the biggest of two numbers
SHELL SCRIPT:
echo "enter two numbers"read a
b
if [ $a -gt $b ]then
echo "a is big"else
echo "b is big"fi
OUTPUT:
RESULT:
Thus the shell program to find the biggest of two numbers is written and executed
successfully
13
EX NO: 3C
SHELL PROGRAMMING – BIGGEST OF THREE NUMBERS
DATE:
AIM:
To write a shell program to find the biggest of three numbers
SHELL SCRIPT:
echo "enter three numbers"read a b
c
if [ $a -gt $b ]&&a [ $b -gt $c ]then
echo "a is big" elif [ $b -
gt $c ]then
echo "b is big"else
echo "c is big"fi
OUTPUT:
RESULT:
Thus the shell program to find the biggest of three numbers is written and executedsuccessfully.
14
EX NO: 3D
SHELL PROGRAMMING – NATURAL NUMBERS UPTO ‘N’
DATE:
AIM:
To write a shell program to find n natural numbers
SHELL SCRIPT:
echo "upper limit"read n
$i=0
while [ $i -lt $n ]do
echo $i i=`expr $i+1`
done
OUTPUT:
RESULT:
Thus shell program to find n natural numbers is written and executed successful
15
EX NO: 3E
SHELL PROGRAMMING – NATURAL NUMBERS
USING FORLOOP
DATE:
AIM:
To write a shell program to find n natural numbers using for loop.
SHELL SCRIPT:
for i in 1 2 3 4 5do
echo $idone
OUTPUT:
RESULT:
Thus the shell program to find n natural numbers using for loop is written andexecuted
successfully
16
EX NO: 3F
SHELL PROGRAMMING – ARITHMETIC OPERATIONS
DATE:
AIM:
To write a shell program to perform arithmetic operations on two numbers.
SHELL SCRIPT:
echo "enter two numbers"read a b
echo "1.Add 2.Sub 3.Mul 4.Div 5.Exit"read op
case $op in
1) c=`expr $a + $b` ;;
2) c= `expr $a - $b` ;;
3) c= `expr $a \ * $b` ;;
4) c= `expr $a / $b` ;;
5) exit esac
echo $c
OUTPUT:
RESULT:
Thus the shell program to perform arithmetic operations on two numbers is writtenand
executed successfully.
17
EX NO: 3G
SHELL PROGRAMMING – GROSS SALARY OF AN
EMPLOYEE
DATE:
AIM:
To write a shell program to calculate gross salary of an employee
SHELL SCRIPT:
echo "Basic Salary"read
basic
da=`expr $basic \* 10 / 100` hra=`expr
$basic \* 20 / 100` gross=`expr $basic +
$da + $hra`echo "$gross"
OUTPUT:
RESULT:
Thus the shell program to calculate gross salary of an employee is written andexecuted
successfully.
18
EX NO: 3H
SHELL PROGRAMMING – FACTORIAL OF A NUMBER
DATE:
AIM:
To write a shell program to find factorial of a number.
SHELL SCRIPT:
echo "enter number"read n
i=1f=1
while [ $i -lt $n ]do
f=`expr $f \* $i`i=`expr
$i + 1` done
echo "Factorial is...$f"
OUTPUT:
RESULT:
Thus the shell program to find factorial of a number is written and executedsuccessfully.
19
EX NO: 4
SYSTEM CALLS OF UNIX OPERATING SYSTEM
DATE:
4A . CLOSE()
AIM:
To write the program to implement the system calls close().
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:
Use the for loop initialization.
Step 5: Stop.
20
PROGRAM:
#include<stdio.h>
#include<fcntl.h>
int main()
if(fd1<0)
perror("c1");
exit(1);
if(close(fd1)<0)
perror("c1");
exit(1);
21
OUTPUT:
RESULT:
Thus the program was executed and verified successfully.
22
4B . GETPID()
AIM:
ALGORITHIM:
Step 1: Start
Step 2: Get the process id integer value by using the system call getpid()
Step 3: It returns the process id of the calling process.
Step 4: After getting the pid value it prints the process id number an exists.
Step 5: Then compile the program either with the gcc or cc command.
Step 6: Run the program.
Step 7: Stop
23
PROGRAM:
Example.c
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
printf("PID of example.c=%d\n",getpid());
execv("./hello",args);
printf("BACK TO EXAMPLE.C");
Hello.c
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
printf("PID of hello.c=%d\n",getpid());
return 0;
24
OUTPUT:
RESULT:
Thus the program for getpid() system call has been executed and verified
successfully.
25
4C . FORK()
AIM:
To write the program to create a Child Process using system call fork().
ALGORITHM:
26
PROGRAM:
#include <stdio.h>
#include<unistd.h>
int main()
int id;
printf("hello world!\n");
id=fork();
if (id>0)
else if(id==0)
else
return 0;
27
OUTPUT:
RESULT:
Thus the program for fork() system call has been executed and verified successfully.
28
4D . EXIT()
AIM:
To write the program to implement the system call exit( ).
ALGORITHM:
29
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<unistd.h>
int main()
{
pid_t cpid;
if (fork()== 0)
exit(0); /* terminate child */
else
cpid = wait(NULL); /* reaping parent */
printf("Parent pid = %d\n", getpid());
printf("Child pid = %d\n", cpid);
return 0;
}
OUTPUT:
Parent pid = 12345678
Child pid = 89546848
RESULT:
Thus the program for exit() system call has been executed and verified successfully.
30
4E .WAIT()
AIM:
To write the program to implement the system call wait( ).
ALGORITHM:
31
PROGRAM:
#include<stdio.h>
#include<sys/wait.h>
#include<unistd.h>
int main()
{
if (fork()== 0)
printf("HC: hello from child\n");
else
{
printf("HP: hello from parent\n");
wait(NULL);
printf("CT: child has terminated\n");
}
printf("Bye\n");
return 0;
}
OUTPUT:
HP: hello from parent
HC: hello from child
HC: Bye
CT: child has terminated
RESULT:
Thus the program for wait() system call has been executed and verified successfully.
32
EX NO: 5
CPU SCHEDULING ALGORITHMS
DATE:
5A. FIRST COME FIRST SERVE
AIM:
To write the program to implement CPU & scheduling algorithm for first come firstserve
scheduling.
ALGORITHM:
33
PROGRAM:
#include<stdio.h>
void main()
{
int i,n,sum,wt,tat,twt,ttat;
int t[10];
float awt,atat;
printf("enter the of processer:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter burst time");
scanf("\n %d",&t[i]);
}
printf("\n FIRST COME FRIST SERVE SCHEDULING");
printf("\n processid\twaittingtime\tturnaroundtime\n");
printf("1\t\t0\t\t%d\n",t[0]);
sum=0;
twt=0;
ttat=t[0];
for(i=1;i<n;i++)
{
sum+=t[i-1];
wt=sum;
tat=sum+t[i];
twt=twt+wt;
ttat=ttat+tat;
printf("\n%d\t\t%d\t\t%d",i+1,wt,tat);
printf("\n");
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n average waiting time%4.2f",awt);
printf("\n average turnaround time %4.2f",atat);
}
34
OUTPUT:
RESULT:
Thus the FCFS process scheduling program was executed and verified successfully.
35
EX NO: 5B
SHORTEST JOB FIRST – SCHEDULING ALGORITHM
DATE:
AIM:
To write a program to implement cpu scheduling algorithm for shortest job firstscheduling.
ALGORITHM:
36
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,k,n,sum,wt[10],tt[10],twt,ttat;int
t[10],p[10];
float awt,atat;
printf("enter the number of processer");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter burst time %d",i);
scanf("\n%d",&t[i]);
}
for(i=0;i<n;i++)
p[i]=i;
for(i=0;i<n;i++)
{
for(k=0;k<i+1;k++)
{
if(t[i]>t[k])
{
int temp;
temp=t[i];
t[i]=t[k];
t[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
}}
printf("\n\n SHOREST JOB SSHEDULING\n\n");
printf("\nprocerrid\tburst tim\twaitingtime\tturnaround time\n\n");
wt[0]=0;
for(i=0;i<n;i++)
{
sum=0;
for(k=0;k<i;k++)
{
wt[i]=sum+t[k];
sum=wt[i];
}}
for(i=0;i<n;i++)
{ 37
46
tt[i]=t[i]+wt[i];
}
for(i=0;i<n;i++)
{
wt[i]=sum+t[k];
sum=wt[i];
}
}
for(i=0;i<n;i++)
{
tt[i]=t[i]+wt[i];
}
for(i=0;i<n;i++)
{
printf("%5d\t\t%5d\t\t%5d\t\t%5d\n",p[i],t[i],wt[i],tt[i]);
}
twt=0;
ttat=t[0];
for(i=1;i<n;i++)
{
twt=twt+wt[i];
ttat=ttat+tt[i];
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n AVERAGE WAITING TIME %4.2f",awt);
printf("\n AVERAGE TURN AROUND TIME %4.2f",atat);
}
}
38
47
OUTPUT:
RESULT:
39
48
EX NO: 5C
PRIORITY – SCHEDULING ALGORITHM
DATE:
AIM:
To write a ‘C’ program to perform priority scheduling.
ALGORITHM:
40
PROGRAM:
#include<stdio.h>
void main()
{
int i,j,n,tat[10],wt[10],bt[10],pid[10],pr[10],t,twt=0,ttat=0;
float awt,atat;
printf("\n-----------PRIORITY SCHEDULING ---------- \n");
printf("Enter the number of process: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
pid[i]=i;
printf("Enter the Burst time of Pid %d: ",i);
scanf("%d",&bt[i]);
printf("Enter the Priority of Pid %d: ",i);
scanf("%d",&pr[i]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(pr[i]>pr[j])
{
t=pr[i];
pr[i]=pr[j];
pr[j]=t;
t=bt[i];
bt[i]=bt[j];
bt[j]=t;
t=pid[i];
pid[i]=pid[j];
pid[j]=t;
}
}
tat[0]=bt[0];
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=wt[i]+bt[i];
}
printf("\n \n");
printf("Pid \t Priority \t Burst time \t WaitingTime \tTurnAroundTime \n");
printf("\n \n");
for(i=0;i<n;i++)
{
41
printf("\n %d \t\t %d \t\t %d \t\t %d \t\t %d",pid[i],pr[i],bt[i],bt[i],wt[i],ta
t[i]);
}
for(i=0;i<n;i++)
{
ttat=ttat+tat[i];
twt=twt+wt[i];
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("\n\n Avg.Waiting Time: %f\n Avg.Turn Around Time: %f\n",awt,atat);
}
OUTPUT:
RESULT:
Thus the priority scheduling program was executed and verified successfully
42
EX NO: 5D
ROUND ROBIN – SCHEDULING ALGORITHM
DATE:
AIM:
ALGORITHM:
43
PROGRAM:
#include<stdio.h>
void main()
{
int ts,pid[10],need[10],wt[10],tat[10],i,j,n,n1;
int bt[10],flag[10],ttat=0,twt=0;
float awt,atat;
printf("\n ROUND ROBIN SCHEDULING \n");
printf("Enter the number of processors \n");
scanf("%d",&n);
n1=n;
printf("\n Enter the Timeslice \n");
scanf("%d",&ts);
for(i=1;i<=n;i++)
{
printf("\n Enter the process ID %d",i);
scanf("%d",&pid[i]);
printf(" Enter the Burst Time for the process");
scanf("%d",&bt[i]);
need[i]=bt[i];
}
for(i=1;i<=n;i++)
{
flag[i]=1;
wt[i]=0;
}
while(n!=0)
{
for(i=1;i<=n;i++)
{
if(need[i]>=ts)
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
wt[j]+=ts;
}
need[i]=0;
n--;
flag[i]=0;
}}
twt=0;
ttat=0;
for(i=1;i<=n1;i++)
{
tat[i]=wt[i]+bt[i];
twt=twt+wt[i];
ttat=ttat+tat[i];
}}
awt=(float)twt/n1;
atat=(float)ttat/n1;
44
printf("\n\n ROUND ROBIN SCHEDULING ALGORITHM \n\n");
printf("\n Process \t Process ID \t BurstTime \t Waiting Time \t Turnaround Time \n");
for(i=1;i<=n1;i++)
{
printf("\n %5d \t %5d \t\t %5d \t\t %5d \t\t %5d \n",i,pid[i],bt[i],wt[i],tat[i]);
}
printf("\n The average Waiting Time=%4.2f",awt);
printf("\n The average Turn around Time=%4.2f",atat);
}
OUTPUT:
RESULT:
Thus the Round Robin scheduling program was executed and verifiedsuccessfully.
45
EX NO: 6
IPC-SHARED MEMORY
DATE:
AIM
To demonstrate communication between process using shared memory.
ALGORITHM:
Server
Client
46
PROGRAM:
47
OUTPUT:
Writer:
gcc write.c –o write
./write
Data written in memory
Hii
Reader:
Gcc read.c –o read
./read
Data read from memory
Hii
RESULT:
Thus the above program for read and write using IPC is executed successfully
48
EX NO: 7
SEMAPHORES
DATE:
AIM:
ALGORITHM:
49
PROGRAM
#include<stdio.h>
int mutex=1,full=0,empty=3,x=0;
main()
{
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n 1.producer\n2.consumer\n3.exit\n");
while(1) {
printf(" \nenter ur choice");
scanf("%d",&n);
switch(n)
{
case 1:if((mutex==1)&&(empty!=0))
producer();
else
printf("buffer is full\n");
break;
case 2:if((mutex==1)&&(full!=0))
consumer();
else
printf("buffer is empty");
break;
case 3:exit(0);
break;
}
}}
int wait(int s)
{
return(--s);
}
int signal(int s)
{
return (++s);
}
void producer()
{
mutex=wait(mutex);
full=signal(full);
empty=wait(empty);
50
x++;
printf("\n producer produces the items %d",x);
mutex=signal(mutex);
}
void consumer()
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\n consumer consumes the item %d",x);
x--;
mutex=signal(mutex);
}
51
OUTPUT:
RESULT:
Thus the program for Producer & consumer Problem using Semaphore was executed
successfully
52
EX NO: 8A
DEADLOCK AVOIDANCE – BANKER’S ALGORITHM
DATE:
AIM:
To implement deadlock avoidance by using Banker’s Algorithm.
Banker’s Algorithm:
When a new process enters a system, it must declare the maximum number of instances of each
resource type it needed. This number may exceed the total number of resources in the system. When the
user request a set of resources, the system must determine whether the allocation of each resources will
leave the system in safe state. If it will the resources are allocation; otherwise the process must wait until
some other process release the resources.
Data structures
n-Number of process, m-number of resource types.
Available: Available[j]=k, k – instance of resource type Rj is available.
Max: If max[i, j]=k, Pi may request at most k instances resource Rj.
Allocation: If Allocation [i, j]=k, Pi allocated to k instances of resource Rj
Need: If Need[I, j]=k, Pi may need k more instances of resource type Rj,Need[I,
j]=Max[I, j]-Allocation[I, j];
Safety Algorithm
1. Work and Finish be the vector of length m and n respectively, Work=Available andFinish[i]
=False.
2. Find an i such that both
Finish[i] =False
Need<=Work
If no such I exists go to 4.
3. work=work+Allocation, Finish[i] =True;
4. if Finish[1]=True for all I, then the system is in safe state.
ALGORITHM:
1. Start the program.
2. Get the values of resources and processes.
3. Get the avail value.
4. After allocation find the need value.
5. Check whether its possible to allocate.
6. If it is possible then the system is in safe state.
7. Else system is not in safety state.
8. If the new request comes then check that the system is in safety.
9. Or not we allow the request.
10. Stop the program.
54
PROGRAM:
/* BANKER’S ALGORITHM */
#include<stdio.h>
struct da
{
int max[10],a1[10],need[10],before[10],after[10];
}p[10];
void main()
{ int i,j,k,l,r,n,tot[10],av[10],cn=0,cz=0,temp=0,c=0;
clrscr();
printf("\n ENTER THE NO. OF PROCESSES:");
scanf("%d",&n);
printf("\n ENTER THE NO. OF RESOURCES:");
scanf("%d",&r);
for(i=0;i<n;i++)
{
printf("PROCESS %d \n",i+1);
for(j=0;j<r;j++)
{
printf("MAXIMUM VALUE FOR RESOURCE %d:",j+1);
scanf("%d",&p[i].max[j]);
}
for(j=0;j<r;j++)
{
printf("ALLOCATED FROM RESOURCE %d:",j+1);
scanf("%d",&p[i].a1[j]);
p[i].need[j]=p[i].max[j]-p[i].a1[j];
}
}
for(i=0;i<r;i++)
{
printf("ENTER TOTAL VALUE OF RESOURCE %d:",i+1);
scanf("%d",&tot[i]);
}
for(i=0;i<r;i++)
{
for(j=0;j<n;j++)
temp=temp+p[j].a1[i];
av[i]=tot[i]-temp;
temp=0;
}
printf("\n\t RESOURCES ALLOCATED NEEDED TOTAL AVAIL");
55
for(i=0;i<n;i++)
{
printf("\n P%d \t",i+1);
for(j=0;j<r;j++)
printf("%d",p[i].max[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].a1[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].need[j]);
printf("\t");
for(j=0;j<r;j++)
{
if(i==0)
printf("%d",tot[j]);
}
printf(" ");
for(j=0;j<r;j++)
{
if(i==0)
printf("%d",av[j]);
}
}
printf("\n\n\t AVAIL BEFORE\T AVAIL AFTER ");
for(l=0;l<n;l++)
{
for(i=0;i<n;i++)
{
for(j=0;j<r;j++)
{
if(p[i].need[j] >av[j])
cn++;
if(p[i].max[j]==0)
cz++;
}
if(cn==0 && cz!=r)
{
for(j=0;j<r;j++)
{
p[i].before[j]=av[j]-p[i].need[j];
p[i].after[j]=p[i].before[j]+p[i].max[j];
av[j]=p[i].after[j];
p[i].max[j]=0;
}
56
printf("\n P %d \t",i+1);
for(j=0;j<r;j++)
printf("%d",p[i].before[j]);
printf("\t");
for(j=0;j<r;j++)
printf("%d",p[i].after[j]);
cn=0;
cz=0;
c++;
break;
}
else
{
cn=0;cz=0;
}
}
}
if(c==n)
printf("\n THE ABOVE SEQUENCE IS A SAFE SEQUENCE");
else
printf("\n DEADLOCK OCCURED");
57
OUTPUT:
//RUN: NO deadlock
//RUN2: Deadlock occurs
RESULT
Thus the banker’s algorithm is implemented successfully for Deadlock avoidance &
Dead Lock Prevention. 59
EX NO: 8B
DEADLOCK DETECTION – BANKER’S ALGORITHM
DATE:
AIM
To implement deadlock detection by using Banker’s Algorithm.
ALGORITHM:
1. Mark each process that has a row in the Allocation matrix of all zeros.
2. Initialize a temporary vectorW to equal the Available vector.
3. Find an indexi such that processi is currently unmarked and thei th row ofQ
is less than or equal to W . That is,Q ik … Wk, for 1 … k … m . If no such row isfound,
terminate the algorithm.
4. If such a row is found, mark processi and add the corresponding row of the
allocation matrix to W . That is, setWk = Wk + Aik, for 1 … k … m . Return to
step 3.
60
PROGRAM:
#include<stdio.h>
static int mark[20];
int i,j,np,nr;
int main()
{
int alloc[10][10],request[10][10],avail[10],r[10],w[10];
printf("\nEnter the no of process: ");
scanf("%d",&np);
printf("\nEnter the no of resources: ");
scanf("%d",&nr);
for(i=0;i<nr;i++)
{
printf("\nTotal Amount of the Resource R%d: ",i+1);
scanf("%d",&r[i]);
}
printf("\nEnter the request matrix:");
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
scanf("%d",&request[i][j]);
Deadlock detected
RESULT:
Thus the banker’s algorithm is implemented successfully for Deadlock detection.
63
EX NO: 9
IMPLEMENTATION OF THREADING AND
SYNCHRONIZATION APPLICATIONS
DATE:
AIM:
To implement threading and synchronization techniques using c language.
ALGORITHM:
64
PROGRAM:
#include<stdio.h>
#include <string.h>
#include<pthread.h>
// Global variable:
int i = 2;
void* foo(void* p){
// Print value received as argument:
printf(“Value recevied as argument in starting routine:”);
printf(“%i\n”, * (int*)p);
// Return reference to global variable:
pthread_exit(&i);
}
int main(void){
// Declare variable for thread’s ID:
pthread_t id;
int j = 1;
pthread_create(&id, NULL, foo, &j);
int* ptr;
// Wait for foo() and retrieve value in ptr;
pthread_join(id, (void**)&ptr);
printf(“Value recevied by parent from child: “);
printf(“%i\n”, *ptr);
}
OUTPUT:
Value recevied as argument in starting routine: 1
Value recevied by parent from child: 2
RESULT:
Thus to implement threading and synchronization techniques using c language has
been executed and verified successfully.
65
EX NO: 10
PAGING TECHNIQUE OF MEMORY MANAGEMENT
DATE:
AIM:
To implement the Memory management policy- Paging.
ALGORITHM:
66
PROGRAM:
#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);
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;
67
}
}
getch();
printf("\n\nPAGE TABLE\n\n");
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();
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();
cphyaddr();
getch();
}
68
OUTPUT:
RESULT:
Thus the Memory management policy- Paging isimplemented successfully
69
EX NO: 11
MEMORY ALLOCATION METHODS FOR FIXED PARTITION
DATE:
ALGORITHM:
1. Declare structures hole and process to hold information about set of holes and processes
respectively.
2. Get number of holes, say nh.
3. Get the size of each hole
4. Get number of processes, say np.
5. Get the memory requirements for each process.
6. Allocate processes to holes, by examining each hole as follows:
a. If hole size>process size then
i. Mark process as allocated to that hole.
ii. Decrement hole size by process size.
b. Otherwise check the next from the set of holes
7. Print the list of process and their allocated holes or unallocated status.
8. Print the list of holes, their actual and current availabilit y.9.Stop
the program.
70
PROGRAM
#include<stdio.h>
struct process
{
int size; int flag; int holeid;
}p[10];
struct hole
{
int size;
int actual;
}h[10];
main()
{
int i,np,nh,j;
printf("EnterthenumberofHoles:");
scanf("%d",&nh);
for(i=0;i<nh;i++){
printf("EntersizeforholeH%d:",i);
scanf("%d",&h[i].size);
h[i].actual=h[i].size;
}
printf("\nEnternumberofprocess:");
scanf("%d",&np);
for(i=0;i<np;i++){
printf("enterthesizeofprocessP%d:",i);
scanf("%d",&p[i].size);
p[i].flag=0;
}
for(i=0;i<np;i++){
for(j=0;j<nh;j++){
if(p[i].flag!=1){
if(p[i].size<=h[j].size){
p[i].flag=1; p[i].holeid=j; h[j].size-=p[i].size;
}}}}
printf("\n\tFirstfit\n");
printf("\nProcess\tPSize\tHole");
for(i=0;i<np;i++){
if(p[i].flag!=1)
printf("\nP%d\t%d\tNotallocated",i,p[i].size);
else
printf("\nP%d\t%d\tH%d",i,p[i].size,p[i].holeid);
}
printf("\n\nHole\tActual\tAvailable");
for(i=0;i<nh;i++)
printf("\nH%d\t%d\t%d",i,h[i].actual,h[i].size);
printf("\n");
}
71
OUTPUT:
RESULT:
Thus processes were allocated memory using first fit method.
72
DATE: 11.B.WORST FIT ALLOCATION
AIM:
To allocate memory requirements for processes using worst fit allocation.
ALGORITHM:
73
PROGRAM:
#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++)
{
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();
}
74
INPUT
Enter the number of blocks: 3
Enter the number of files: 2
OUTPUT
File No File Size Block No Block Size Fragment
1 1 1 5 4
2 4 3 7 3
RESULT
Thus processes were allocated memory using worst fit method.
75
DATE: 11.C.BEST FIT ALLOCATION
AIM:
To allocate memory requirements for processes using best fit allocation.
ALGORITHM:
1. Declare structures hole and process to hold information about set of holes and processes
respectively.
2. Get number of holes, say nh.
3. Get the size of each hole
4. Get number of processes, say np.
5. Get the memory requirements for each process.
6. Allocate processes to holes, by examining each hole as follows:
a. Sort the holes according to their sizes in ascending order
b. If hole size>process size then
i. Mark process as allocated to that hole.
ii. Decrement hole size by process size.
c. Otherwise check the next from the set of sorted hole.
7. Print the list of process and their allocated holes or unallocated status.
8. Print the list of holes, their actual and current availabilit y.
9. Stop
76
PROGRAM:
#include<stdio.h>
struct process
{
int size;
int flag;
int holeid;
}p[10];
struct hole
{
int hid;
int size;
int actual;
}h[10];
main()
{
int i,np,nh,j;
void bsort(structhole[],int);
printf("Enter the number of Holes:");
scanf("%d",&nh);
for(i=0;i<nh;i++)
{
printf("Enter size for holeH%d:",i);
scanf("%d",&h[i].size);
h[i].actual=h[i].size;
h[i].hid=i;
}
printf("\nEnter number of process:");
scanf("%d",&np);
for(i=0;i<np;i++)
{
printf("enter the size of processP%d:",i);
scanf("%d",&p[i].size);
p[i].flag=0;
}
for(i=0;i<np;i++)
{
bsort(h,nh);
for(j=0;j<nh;j++)
{
if(p[i].flag!=1)
{
if(p[i].size<=h[j].size)
{
p[i].flag=1;
p[i].holeid=h[j].hid;
h[j].size-=p[i].size;
}}}
77
}
printf("\n\tBestfit\n");
printf("\nProcess\tPSize\tHole");
for(i=0;i<np;i++)
{
if(p[i].flag!=1)
printf("\nP%d\t%d\tNotallocated",i,p[i].size);
else
printf("\nP%d\t%d\tH%d",i,p[i].size,p[i].holeid);
}
printf("\n\nHole\tActual\tAvailable");
for(i=0;i<nh;i++)
printf("\nH%d\t%d\t%d",h[i].hid,h[i].actual, h[i].size);
printf("\n");
}
Void bsort(structholebh[],intn)
{
struct holetemp;
int i,j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(bh[i].size>bh[j].size)
{
temp=bh[i];
bh[i]=bh[j];
bh[j]=temp;
}
}
}
}
78
OUTPUT:
RESULT:
Thus processes were allocated memory using best fit method.
79
EX NO: 12
PAGE REPLACEMENT ALGORITHMS
DATE:
ALGORITHM:
80
PROGRAM:
#include<stdio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
void main()
{
printf("\n \t\t\t FIFO PAGE REPLACEMENT ALGORITHM");
printf("\n Enter no.of frames ....");
scanf("%d",&nof);
printf("Enter number of reference string..\n");
scanf("%d",&nor);
printf("\n Enter the reference string..");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
printf("\nThe given reference string:");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
frm[i]=-1;
printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
printf("\n\t Reference np%d->\t",ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1;
break;
}}
if(flag==0)
{
pf++;
victim++;
victim=victim%nof;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}}
printf("\n\n\t\t No.of pages faults...%d",pf);
}
81
OUTPUT:
RESULT:
Thus the FIFO page replacement algorithm is implemented successfully.
82
EX NO: 12B
LRU PAGE REPLACEMENT ALGORITHM
DATE:
AIM:
To implement page replacement algorithm LRU (Least Recently Used LRU (Lease
Recently Used). Here we select the page that has not been used for the longest period of time.
ALGORITHM:
1: Create a queue to hold all pages in memory
2: When the page is required replace the page at the head of the queue3: Now
the new page is inserted at the tail of the queue
4: Create a stack
5: When the page fault occurs replace page present at the bottom of the stack
83
PROGRAM:
#include<stdio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],lrucal[50],count=0;
int lruvictim();
void main()
{
clrscr();
printf("\n\t\t\t LRU PAGE REPLACEMENT
ALGORITHM");printf("\n Enter no.of Frames ");
scanf("%d",&nof);
printf(" Enter no.of reference string..");
scanf("%d",&nor);
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=1;i<=nof;i++)
{
frm[i]=-1;
lrucal[i]=0;
}
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
recent[ref[i]]=i;
}
printf("\n\n\t No.of page faults...%d",pf);
getch();
}
int lruvictim()
{
int i,j,temp1,temp2;
for(i=0;i<nof;i++)
{
temp1=frm[i];
lrucal[i]=recent[temp1];
}
temp2=lrucal[0];
for(j=1;j<nof;j++)
{
if(temp2>lrucal[j])
temp2=lrucal[j];
}
for(i=0;i<nof;i++)
if(ref[temp2]==frm[i])
return i;
return 0;
}
85
OUTPUT:
RESULT:
Thus the LRU page replacement algorithm is implemented successfully.
86
EX NO: 12C
OPTIMAL (LFU) PAGE REPLACEMENT ALGORITHM
DATE:
AIM:
To implement page replacement algorithms Optimal (The page which is not used for
longest time)
ALGORITHM:
Optimal algorithm:
Here we select the page that will not be used for the longest period of time.
OPTIMAL:
1: Create an array
2: When the page fault occurs replace page that will not be used for the
longest period of time.
87
PROGRAM:
/*OPTIMAL (LFU) page replacement algorithm*/
#include<stdio.h>
#include<conio.h>
int i,j,nof,nor,flag=0,ref[50],frm[50],pf=0,victim=-1;
int recent[10],optcal[50],count=0;
int optvictim();
void main()
{
clrscr();
printf("\n OPTIMAL PAGE REPLACEMENT ALGORITHN");
printf("\n ................................ ");
printf("\nEnter the no.of frames");
scanf("%d",&nof);
printf("Enter the no.of reference string");
scanf("%d",&nor);
printf("Enter the reference string");
for(i=0;i<nor;i++)
scanf("%d",&ref[i]);
clrscr();
printf("\n OPTIMAL PAGE REPLACEMENT ALGORITHM");
printf("\n ...............................");
printf("\nThe given string");
printf("\n ................... \n");
for(i=0;i<nor;i++)
printf("%4d",ref[i]);
for(i=0;i<nof;i++)
{frm[i]=-1; optcal[i]=0;
}
for(i=0;i<10;i++)
recent[i]=0;
printf("\n");
for(i=0;i<nor;i++)
{
flag=0;
printf("\n\tref no %d ->\t",ref[i]);
for(j=0;j<nof;j++)
{
if(frm[j]==ref[i])
{
flag=1;
88
break;
}
}
if(flag==0) {
count++;
if(count<=nof)
victim++;
else
victim=optvictim(i);
pf++;
frm[victim]=ref[i];
for(j=0;j<nof;j++)
printf("%4d",frm[j]);
}
}
printf("\n Number of page faults: %d",pf);
}
int optvictim(int index)
{
int i,j,temp,notfound;
for(i=0;i<nof;i++) {
notfound=1;
for(j=index;j<nor;j++)
if(frm[i]==ref[j])
{
notfound=0;
optcal[i]=j;
break;
}
if(notfound==1)
return i;
}
temp=optcal[0];
for(i=1;i<nof;i++)
if(temp<optcal[i])
temp=optcal[i];
for(i=0;i<nof;i++)
if(frm[temp]==frm[i])
return i;
return 0;
}
89
OUTPUT:
RESULT:
Thus the LFU page replacement algorithm is implemented successfully.
90
EX NO: 13
VARIOUS FILE ORGANIZATION TECHNIQUES
DATE:
13.A. IMPLEMENTATION OF SINGLE LEVEL DIRECTORY
AIM:
To write a C program to implement Single - Level directory structure in C
ALGORITHM:
1. Start
2. Declare the number, names and size of the directories and file names.
3. Get the values for the declared variables.
4. Display the files that are available in the directories.
5. Stop
91
PROGRAM:
#include<stdio.h>
main()
{
int master,s[20];
char f[20][20][20];
char d[20][20];
int i,j;
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++)
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");
}
92
OUTPUT:
RESULT:
Thus the Single level directory structure is written and executed successfully.
93
EX NO: 13B
IMPLEMENTATION OF TWO-LEVEL DIRECTORY
DATE:
AIM:
To write a C program to implement Two-level directory structure in C.
ALGORITHM:
1. Start
2. Declare the number, names and size of the directories and subdirectories and filenames.
3. Get the values for the declared variables.
4. Display the files that are available in the directories and subdirectories.
5. Stop.
94
PROGRAM:
#include<stdio.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:");
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"); }
}
95
OUTPUT:
RESULT:
Thus a C program to implement Two-level directory structure is written and executed
successfully.
96
EX NO: 14
FILE ALLOCATION STRATEGIES
DATE:
ALGORITHM:
1: Start the program.
2: Get the number of memory partition and their sizes.
3: Get the number of processes and values of block size for each process. 4: First fit
algorithm searches all entire memory block until a hole which is
big enough is encountered. It allocates that memory block for the requestingprocess.
5: Best-fit algorithm searches the memory blocks for the smallest hole which canbe allocated
to requesting process and allocates if.
6: Worst fit algorithm searches the memory blocks for the largest hole andallocates it
to the process.
7: Analyses all the three memory management techniques and display the bestalgorithm which
utilizes the memory resources effectively and efficiently.
8: Stop the program.
97
PROGRAM:
#include<stdio.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);
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]);
}
98
OUTPUT:
RESULT:
Thus the SEQUENTIAL file allocation method is implemented successfully.
99
EX NO: 14B
FILE ALLOCATION STRATEGIES – INDEXED FILE
ALLOCATION
DATE:
AIM:
To Write a C Program to implement Indexed File Allocation method.
ALGORITHM:
1: Start.
2: Let n be the size of the buffer 3: check
if there are any producer
4. If yes check whether the buffer is full
5. If no the producer item is stored in the buffer6: If the
buffer is full the producer has to wait
7: Check there is any consumer.If yes check whether the buffer is empty8: If no
the consumer consumes them from the buffer
9: If the buffer is empty, the consumer has to wait.
10: Repeat checking for the producer and consumer till required11:
Terminate the process.
100
PROGRAM:
#include<stdio.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);
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]);
}
101
OUTPUT:
RESULT:
Thus the indexed file allocation method is implemented successfully
102
EX NO: 14C
FILE ALLOCATION STRATEGIES – LINKED FILE
ALLOCATION
DATE:
AIM:
To Write a C Program to implement Linked File Allocation method.
ALGORITHM:
1: Create a queue to hold all pages in memory
2: When the page is required replace the page at the head of the queue3: Now
the new page is inserted at the tail of the queue
4: Create a stack
5: When the page fault occurs replace page present at the bottom of the stack6: Stop
the allocation.
103
PROGRAM:
#include<stdio.h>
struct file
{
char fname[10];
int start,size,block[10];
}f[10];
main()
{
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");
}
}
104
OUTPUT:
RESULT:
Thus the linked file allocation method is implemented successfully.
105
15.A.FIRST COME FIRST SERVE ALGORITHM:
AIM:
To implement FCFS the simplest of all the Disk Scheduling Algorithms. In FCFS, the
requests are addressed in the order they arrive in the disk queue.
ALGORITHM:
1. Start the program
2. Declare the necessary header files
3. Declare the variables which is needed to execute FIFO
4. Get the no of variables RQ[i], using for loop
5. Assign the logic of the FIFO disk scheduling
6. Execute till the process get completed
7. Set the initial head position
8. Print the results TotalHeadMoment
9. Stop the execution
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
printf("Total head moment is %d",TotalHeadMoment);
return 0;
106
OUTPUT:
Enter the number of Request
8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Total head movement is 644
Example: Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the
Read-write head initially at the track 50 and the tail track being at 199.
RESULT:
Thus the above Disk scheduling FIFS is implemented successfully.
107
15.B.SHORTEST SEEK TIME FIRST (SSTF) ALGORITHM
AIM:
To implement Shortest seek time first (SSTF) algorithm, selects the disk I/O request
which requires the least disk arm movement from its current position regardless of the
direction. It reduces the total seek time as compared to FCFS
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
while(count!=n)
{
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{min=d;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
// 1000 is for max
// you can use any number
RQ[index]=1000; 108
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
OUTPUT:
RESULT:
Thus the above Disk scheduling SSTF is implemented successfully.
109
EX.NO.16
AIM:
To install the Linux OS using VMware
Note: If your Linux distribution is not RPM-based, has a custom kernel, or is unsupported,
use the steps below to compile VMware Tools.
To install VMware Tools in a Linux guest operating system using Compiler:
Note: Log in as a root user, or use the sudo command to complete each of these steps.
3. Right Click VM in the virtual machine menu, then click Guest > Install/Upgrade
VMware Tools.
4. Click OK.
Note: In some cases, verify that the CDROM device is Connected from within the Edit
Settings option of the virtual machine.
mkdir /mnt/cdrom
7. To copy the Compiler gzip tar file to a temporary local directory, run:
cp /mnt/cdrom/VMwareTools-version.tar.gz /tmp/
ls /mnt/cdrom
# VMwareTools-5.0.0-12124.tar.gz
9. To change to the tmp directory and extract the contents of the tar file into a new directory
called vmware-tools-distrib, run:
cd /tmp 110
tar -zxvf VMwareTools-version.tar.gz
10. To change directory to vmware-tools-distrib and run the vmware-install.pl PERL script to
install VMware Tools, run:
cd vmware-tools-distrib
./vmware-install.pl
Notes:
Complete the screen prompts to install the VMware Tools. Options in square brackets
are default choices and can be selected by pressing Enter.
To compile VMware Tools successfully, you need gcc Compiler and Linux Kernel
sources provided by your Linux distribution. Consult your Linux distribution
documentation for details on methods to install these packages.
It is normal for the console screen to go blank for a short time during the installation
when the display size changes.
Some warnings or errors are normal, like when a files does not exist.
Depending on the Linux distribution, your network service might restart after
installation. VMware recommends that you invoke this command from the console and
not remotely.
11. If you are running a GUI interface, restart your X Window session for any mouse or
graphics changes to take effect.
12. To start VMware Tools running in the background during an X Window session, using
terminal session run the command
/usr/bin/vmware-toolbox &
13. Depending on your environment, you may need to unmount the CD-ROM. To unmount
the CD-ROM, run:
umount /mnt/cdrom
14. Depending on your environment, you may need to manually end the VMware Tools
installation. To end the VMware Tools install, click VM in the virtual machine menu, then
click Guest > End VMware Tools Install.
RESULT:
Thus the study exercise for Linux installation using VMware studied successfully.
111