OS Record - Satheesh
OS Record - Satheesh
COLLEGE
Chennai
LABORATORY RECORD
Name: _____________________________________________________
Class : II B.E (CSE) Semester: VI
Subject Code & Name: CS3461–Operating Systems Laboratory
Academic Year: 2021 – 2025
APOLLO ENGINEERING
COLLEGE
Chennai
Certificate
Name:
Class: II B.E (CSE) Reg. No:
student in the CS3461-Operating Systems Laboratory during the year 2021 – 2022.
4d. 42
CPU Scheduling: Round Robin
5. 47
Inter Process Communication Strategy
6. 51
Implement mutual exclusion by Semaphone
7. 56
To avoid Deadlock using Banker’s Algorithm
8. 63
To implement Deadlock Detection Algorithm
9. 68
Implement Threading
10. 71
Implement Paging Technique
11a. 74
Memory Allocation Methods: First Fit
11b. 77
Memory Allocation Methods: Worst Fit
11c. 81
Memory Allocation Methods: Best Fit
12a. 85
Page Replacement Algorithm: FIFO
12b. 88
Page Replacement Algorithm: LRU
12c. 93
Page Replacement Algorithm: LFU
14b. 115
File Allocation Strategies: Indexed
14c. 119
File Allocation Strategies: Linked
15a. 122
Disk Scheduling Algorithm: FCFS
15b. 125
Disk Scheduling Algorithm: SSTF
Instructions to Install Ubuntu Linux 12.04 (LTS) along with Windows Back Up Your Existing
Data!
This is highly recommended that you should take backup of your entire data before start with the
installation process.
There are several ways to boot the installation system. Some of the very popular ways are , Booting from
a CD ROM, Booting from a USB memory stick, and Booting from TFTP.
Before booting the installation system, one need to change the boot order and set CD-ROM as first boot
device.
As your computer starts, press the DEL, ESC, F1, F2, F8 or F10 during the initial startup screen.
Depending on the BIOS manufacturer, a menu may appear. However, consult the hardware
documentation for the exact key strokes. In my machine, its DEL key as shown in following screen- shot.
1
2. Find the Boot option in the setup utility. Its location depends on your BIOS. Select the Boot
option from the menu, you can now see the options Hard Drive, CD-ROM Drive, Removable
Devices Disk etc.
3. Change the boot sequence setting so that the CD-ROM is first. See the list of “Item Specific
Help” in right side of the window and find keys which is used to toggle to change the boot
sequence.
In a few minutes installation wizard will be started. Select your language and click the "Install
Ubuntu" button to continue...
2
Optionally, you can choose to download updates while installing and/or install third party software,
such as MP3 support. Be aware, though, that if you select those options, the entire installation process
will be longer!
Since we are going to create partitions manually, select Something else, then click Continue. Keep
in mind that even if you do not want to create partitions manually, it is better to select the same option
as indicated here. This would insure that the installer will not overwrite your Windows , which will
destroy your data. The assumption here is that sdb will be used just for Ubuntu 12.04, and that there
are no valuable data on it.
3
Where are you? Select your location and Click the "Continue" button.
Keyboard layout
Select your keyboard layout and UK (English) and Click on “Continue” button.
4
Who are you?
Fill in the fields with your real name, the name of the computer (automatically generated, but can be
overwritten), username, and the password.
Also at this step, there's an option called "Log in automatically." If you check it, you will
automatically be logged in to the Ubuntu desktop without giving the password.
Option "Encrypt my home folder," will encrypt your home folder. Click on the "Continue" button to
continue...
Now Ubuntu 12.04 LTS (Precise Pangolin) operating system will be installed.
5
It will take approximately 10-12 minutes (depending on computer's speed), a pop-up window will
appear, notifying you that the installation is complete, and you'll need to restart the computer in order
to use the newly installed Ubuntu operating system. Click the "Restart Now" button.
Please remove the CD and press the "Enter" key to reboot. The computer will be restarted. In a few
seconds, you should see Windows 7′s boot menu with two entires listed – Windows 7 and Ubuntu
12.04 (LTS).
Then you may choose to boot into Windows 7 or Ubuntu 12.04 using the UP/Down arrow key.
6
Please select Ubuntu 12.04 (LTS) and press Enter to boot the machine in Ubuntu 12.04
Linux.
Here you can see the users on the machine, Click on the user name and enter the password and press
Enter key to login.
7
We have successfully install and login to Ubuntu 12.04 LTS.
RESULT:
8
Ex.No:2
AIM:
1. Calendar Command:
cal is a standard program on Unix and Unix-like operating systems that prints an ASCII calendar
of the given month or year.
If the user does not specify any command-line options, cal will print a calendar of the current
month.
dell@dell-Inspiron-5423:~$ cal
November 2018
Su Mo Tu We Th Fr Sa
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
2. Date command:
Print or set the system date and time. The following options are used with this command.
9
%d day of month (01..31)
%D date (mm/dd/yy)
%F same as %Y-%m-%d
%h same as %b
%H hour (00..23)
%I hour (01..12)
%k hour ( 0..23)
%l hour ( 1..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%N nanoseconds (000000000..999999999)
%t a horizontal tab
10
%V week number of year wIth Monday as first day of week (01..53)
%Y year (1970...)
dell@dell-Inspiron-5423:~$ date
11
Thu
November
dell@dell-Inspiron-5423:~$ who
4. Who am I command: Displays the name of the user who runs the command.
dell@dell-Inspiron-5423:~$ who am i
5. Finger Command:
1. In Unix, finger is a program you can use to find information about computer users.
2. It usually lists the login name, the full name, and possibly other details about the user you
are fingering.
11
$ finger
6.Help command:
$ man clear
clear(1) clear(1)
NAME
SYNOPSIS
clear
DESCRIPTION
clear clears your screen if this is possible. IT looks in the environment for the terminal type and
then in the terminfo database to figure
SEE ALSO
tput(1), terminfo(5)
clear(1)
(END)
$ clear
8. ID command: To display the user id and group id information about a user. i.e. user identITy.
12
$ id
$ echo good
good
$ tty
/dev/pts/2
1.Create a file:
$ vi file1.c
(OR)
13
2.List information about files and directories
$ ls
$ ls -la
total 104
4.Copy a file:
$ cp file1.c file3.c
$ ls
$ mv file1.c file4.c
14
$ ls
6.Remove a file:
$ rm file3.c
$ ls
$ cat file4.c
#include <stdio.h>
void main()
return 0;
$ wc f1.txt
12 43 221 f1.txt
10.Find Command:
$ find
15
../pointer1.c
./sort.c
./f1.txt
./file_copy.c
./pointer2.c
./pointer3.c
./a.out
1c1
< Hello
---
> world
$ ls -l file2
$ touch file2
$ ls -l file2
16
make link between files
$ ls
$ ln -t dma file1
$ cd dma
$ ls
file1
Displays the inITial part of the text file. By default, IT displays the first 10 lines of a file.
$ head -3 f1.txt
Good day
CSE is raining
16.Tail command:
Displays the last part of he text file. By default, IT displays the last 10 lines of a file.
$ tail -5 f1.txt
1. Create a directory:
$ mkdir dir1
17
$ cd dir1
$ pwd
/home/Balajik/dir1
4. Remove a directory:
$ rmdir dir
$ ls
file2.cpp file4.c
Pipes: A mechanism in which the output of one command is redirected as input to another command.
$ who | wc -l
18
#include <stdio.h>
#define SIZE 50
Filter: Sort and grep commands are used in customizing the various commands.
Sort Filter:
$ sort f1.txt
Good day
How to go to school
IT is raining
Welcome
Grep filter:
It is used to search for a particular pattern from a file or from std. input. IT displays those lines on the
standard output. “grep” stands for “ Global Search for Regular Expression”
egrep command:
19
IT is an extension for grep command Multiple Patterns can be searched in a file by issuing a single
command. These multiple patterns should be separated by a pipe ( | ) symbol.
fgrep command:
IT stands for “fixed grep”. The command is used to extract only fixed strings without the use of any
regular expression.
Other Filters:
1.Uniq filter: It compares the adjacent lines in the sorted output file.
2.More filter:
IT displays the output of a command on the screen page by page. The next screen is viewd by pressing the
space bar.
$ ls | more
a.out
f1.txt
file_copy.c
pointer1.c
pointer2.c
pointer3.c
sort.c
3.Cut command:
$ cut -c 1 file1
20
B
4.Paste Command:
IT merges the contents of 2 files in to a single file. IT reads a line from each file in the list
specified and combines them into a single file.
$ cat f2.txt
Anand
Akhila
Arun
$ cat f3.txt
Badri
Rajaraman
Anand
$ cat f4.txt
Balajik
Subha
Akila
$ ls -l | grep "^d"
21
6. Tee Command:
(read from standard input and write to standard output and files)
$ tee jes
CSE
CSE
$ cat jes
CSE
uniq Command
$ cat kb
cubs
kItten
kItten
kiwi
parrot
peacock
puppy
puppy
$ uniq -d kb
kITten
puppy
$ uniq -u kb
cubs
kiwi
22
parrot
peacock
$ uniq -c kb
1 cubs
2 kItten
1 kiwi
1 parrot
1 peacock
2 puppy
RESULT:
Thus the study and execution of Unix commands has been complied successfully.
23
Ex.No:3a
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
int main(void)
int fork(void),value;
value=fork();
printf("main:value =%d\n",value);
return 0;
OUTPUT:
main:value =0
main:value =3172
RESULT:
Thus the program for fork system call has been executed successfully.
24
Ex.No:3b
AIM:
To Execute a Unix Command in a ‘C’ program using exit() system call.
ALGORITHM:
1. Start the program
2. Create a C program example.c to print the current id of the process.
3. Create an array of character pointers. The last element of this array should be NULL as the terminating
point.
4. Use the function execv() which takes the file name and the character pointer array as its argument.
5. Use ./ with the name of file, to specify the path of the file.
6. Stop the program.
PROGRAM:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("PID of example.c = %d\n", getpid());
char *args[] = {"Hello", "C", "Programming", NULL};
execv("./hello", args);
printf("Back to example.c");
return 0;
}
hello.c
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
25
{
printf("We are in Hello.c\n");
printf("PID of hello.c = %d\n", getpid());
return 0;
}
OUTPUT:
dell@dell-Inspiron-5423:~$ gcc -o example example.c
dell@dell-Inspiron-5423:~$ gcc -o hello hello.c
dell@dell-Inspiron-5423:~$ ./example
PID of example.c = 3752
We are in Hello.c
PID of hello.c = 3752
RESULT:
Thus the program for exit system call has been executed successfully.
26
Ex.No:3c
AIM:
To Execute a Unix Command in a ‘C’ program using getpid() system call.
ALGORITHM:
1. Start the program
2. Declare the necessary variables
3. The getpid() system call returns the process ID of the parent of the calling process.
5. Stop the program.
PROGRAM:
#include<stdio.h>
int main()
{
int pid;
pid=getpid();
printf("process ID is %d\n",pid);
pid=getppid();
printf("parent process ID id %d\n",pid);
}
OUTPUT:
process ID is 3187
parent process ID id 3139
RESULT:
Thus the program for getpid system call has been executed successfully.
27
Ex.No:3d
AIM :
To Execute a Unix Command in a ‘C’ program using wait() system call.
ALGORITHM :
1. Start the program
2. Initialize the necessary variables
3. Use wait() to return the parent id of the child else return -1 for an error
4. Stop the program.
PROGRAM:
#include<stdio.h>
#include<unistd.h>
int main(void)
{
int pid,status,exitch;
if((pid=fork())==-1)
{
perror("error");
exit (0);
}
if(pid==0)
{
sleep(1);
printf("child process");
exit (0);
}
else
{
printf("parent process\n");
if((exitch=wait(&status))==-1)
28
{
perror("during wait()");
exit (0);
}
printf("parent existing\n");
exit (0);
}
}
OUTPUT :
parent process
child process parent existing
RESULT:
Thus the program for wait system call has been executed successfully.
29
Ex.No:3e
AIM:
To Execute a Unix Command in a ‘C’ program using close() system call.
ALGORITHM:
1. Start the program
2. Declare the necessary variables
3. The close() system call returns the process ID of the parent of the calling process.
5. Stop the program
PROGRAM:
#include<stdio.h>
#include<fcntl.h>
{
int fd1 = open(“foo.txt”,O_RDONLY,0);
close(fd1);
int fd2 = open(“baz.txt”,O_RDONLY,0);
printf(“fd2 = %d\n”,fd2);
exit(0);
}
OUTPUT:
fd2 = 3
RESULT:
Thus the program for wait system call has been executed successfully.
30
Ex.No:4a
AIM:
To write a C program to implement First Come First Serve scheduling algorithm. (FCFS)
ALGORITHM:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Set the waiting of the first process as ‘0’ and its burst time as its turn around time
Step 5: for each process in the Ready Q calculate Waiting time for process(n)= waiting time of
process (n-1) + Burst time of process (n-1) Turn around time for Process(n)= waiting time of
Process(n)+ Burst time for process(n)
Step 6: Calculate Average waiting time = Total waiting Time / Number of process Average
Turnaround time = Total Turnaround Time / Number of process
PROGRAM:
#include<stdio.h>
void main()
int i,n,sum,wt,tat,twt,ttat;
int t[10];
float awt,atat;
scanf("%d",&n);
for(i=0;i<n;i++)
31
printf("\n Enter the Burst Time of the process %d",i+1);
scanf("\n %d",&t[i]);
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\n");
awt=(float)twt/n;
atat=(float)ttat/n;
32
OUTPUT:
dell@dell-Inspiron-5423:~$ cc fcfs.c
dell@dell-Inspiron-5423:~$ ./a.out
1 0 24
2 24 27
3 27 30
RESULT:
Thus the C program to implement First Come First Serve scheduling algorithm (FCFS) is
executed successfully.
33
Ex.No:4b
AIM:
ALGORITHM:
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
Step 5: Set the waiting time of the first process as ‘0’ and its turnaround time as its burst time.
Step 6: For each process in the ready queue, calculate Waiting time for process(n)= waiting time
of process (n-1) + Burst time of process (n-1) Turn around time for Process(n)= waiting time of
Process(n)+ Burst time for process(n)
Step 7: Calculate Average waiting time = Total waiting Time / Number of process Average
Turnaround time = Total Turnaround Time / Number of process
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;
scanf("%d",&n);
34
for(i=0;i<n;i++)
scanf("\n %d",&t[i]);
for(i=0;i<n;i++)
p[i]=i;
for(i=0;i<n;i++)
for(k=i+1;k<n;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;
wt[0]=0;
for(i=0;i<n;i++)
35
{
sum=0;
for(k=0;k<i;k++)
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++)
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;
36
printf("\n AVERAGE WAITING TIME %4.2f",awt);
OUTPUT:
dell@dell-Inspiron-5423:~$ cc sjf.c
dell@dell-Inspiron-5423:~$ ./a.out
1 1 0 1
0 3 1 4
2 2 4 6
RESULT:
Thus the C program to implement Shortest Job First scheduling algorithm (SJF) is executed
successfully.
37
Ex.No:4c
AIM:
ALGORITHM:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 5: Set the waiting of the first process as ‘0’ and its burst time as its turn around time
1. Waiting time for process(n)= waiting time of process (n-1) + Burst time of process(n-1)
2. Turn around time for Process(n)= waiting time of Process(n)+ Burst time for process(n)
Step 7: Calculate
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");
38
scanf("%d", &n);
for (i=0;i<n;i++)
pid[i] = i;
scanf("%d",&bt[i]);
scanf ("%d",&pr[i]);
// Sorting start
for (i=0;i<n;i++)
for(j=i+1;j<n;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;
39
}
// Sorting finished
tat[0] = bt[0];
wt[0] = 0;
for (i=1;i<n;i++)
printf("\n---------------------------------------------------------------\n");
printf("\n--------------------------------------------------------------\n");
for(i=0;i<n;i++)
printf("\n%d\t\t%d\t%d\t\t%d\t\t%d",pid[i],pr[i],bt[i],wt[i],tat[i]);
for(i=0;i<n;i++)
ttat = ttat+tat[i];
awt = (float)twt / n;
atat = (float)ttat / n;
40
OUTPUT:
dell@dell-Inspiron-5423:~$ cc priority.c
dell@dell-Inspiron-5423:~$ ./a.out
-----------PRIORITY SCHEDULING--------------
---------------------------------------------------------------
--------------------------------------------------------------
1 1 4 0 4
2 2 2 4 6
0 3 1 6 7
RESULT:
41
Ex.No:4d
AIM:
ALGORITHM:
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: Consider the ready queue is a circular Q, calculate Waiting time for process(n) = waiting
time of process(n-1)+ burst time of process (n-1 ) + the time difference in getting the CPU from
process(n-1) Turn around time for process(n) = waiting time of process(n) + burst time of
process(n)+ the time difference in getting CPU from process(n).
Step 7: Calculate Average waiting time = Total waiting Time / Number of process Average
Turnaround time = Total Turnaround Time / Number of process
PROGRAM:
#include<stdio.h>
int main()
int bt[20],gc[20],wt[20],tat[20],bt1[20],st[20],ts,n,i,j,k,count=0,count1,sum_bt=0,tq;
int swt=0,stat=0,temp,sq=0,c,p=0;
float awt=0.0,atat=0.0;
scanf("%d",&n);
42
printf("Enter the burst time");
{scanf("%d",&bt[i]);
bt1[i]=bt[i];
st[i]=bt[i];}
scanf("%d",&ts);
tq=ts;
sum_bt=sum_bt+bt[i];
do
if(bt[i]>=ts)
gc[j]=i+1;
count+=ts;
bt[i]=bt[i]-ts;
else
43
gc[j]=i+1;
count+=bt[i];
bt[i]=0;
}while(bt[k]!=0);
while(1)
for(i=0,count=0;i<n;i++)
temp=tq;
if(st[i]==0)
count++;
continue;
if(st[i]>tq)
st[i]=st[i]-tq;
else
if(st[i]>=0)
temp=st[i];
st[i]=0;
sq=sq+temp;
44
tat[i]=sq;
if(n==count)
break;
for(i=0;i<n;i++)
wt[i]=tat[i]-bt1[i];
swt=swt+wt[i];
stat=stat+tat[i];
awt=(float)swt/n;
atat=(float)stat/n;
for(i=0;i<n;i++)
printf("%d %d %d %d\n",i+1,bt1[i],wt[i],tat[i]);
45
OUTPUT:
dell@dell-Inspiron-5423:~$ cc rr1.c
dell@dell-Inspiron-5423:~$ ./a.out
1 24 6 30
2 3 6 9
3 3 7 10
dell@dell-Inspiron-5423:~$
RESULT:
Thus the C program to implement the Round Robin scheduling mechanism is executed
sucessfully.
46
Ex.No:5
AIM:
ALGORITHM:
Step 3: The main process reads a string and passes it to one of the child process ,the child
process C1 receive string from P1.
Step 5: C1 also reads an integer array of length equal to the length of the string and sends it to
C2.
Step 6: C2 receive integer array from C1 and find the sum of the elements and sends the sum
to the parent process P1.
Step 7: The sleep() function is used in the program to suspend the processes for a desired
interval of time.
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<string.h>
void main()
int pid[2],pid1[2],pid2[2],pid3[2],pid4[2];
int a[20],i,l,s=0;
char str[20];
47
pipe(pid);
pipe(pid1);
pipe(pid2);
pipe(pid3);
pipe(pid4);
if(fork()==0)
sleep(5);
close(pid[1]);
read(pid[0],str,sizeof(str));
for(i=0,l=0;str[i]!='\0';i++)
l=l+1;
close(pid3[0]);
write(pid3[1],&l,sizeof(l));
sleep(6);
for(i=0;i<l;i++)
scanf("%d",&a[i]);
close(pid1[0]);
write(pid1[1],a,sizeof(a));
close(pid4[0]);
write(pid4[1],&l,sizeof(l));
else if(fork()==0)
sleep(2);
48
close(pid1[1]);
close(pid4[1]);
read(pid4[0],&l,sizeof(l));
read(pid1[0],a,sizeof(a));
for(i=0;i<l;i++)
s=s+a[i];
close(pid2[0]);
write(pid2[1],&s,sizeof(s));
else
printf("\nEnter string:");
scanf("%s",str);
close(pid[0]);
write(pid[1],str,sizeof(str));
sleep(7);
close(pid3[1]);
read(pid3[0],&l,sizeof(l));
sleep(8);
close(pid2[1]);
read(pid2[0],&s,sizeof(s));
printf("\nSum=%d\n",s);
49
OUTPUT:
dell@dell-Inspiron-5423:~$ cc IPC.c
dell@dell-Inspiron-5423:~$ ./a.out
Enter string:OPERATING
11
23
45
11
23
Sum=129
dell@dell-Inspiron-5423:~$
RESULT:
50
Ex.No:6
AIM:
ALGORITHM:
c. If the new Buffer size is full Don’t produce anything; display an error message
Producer has to wait till any consumer consume the existing item
d. Else Produce the item Increment the Buffer by the number of item produced
d. Else Consume the item Decrement the Buffer by the number of item consumed
PROGRAM:
#include<stdio.h>
int n=0,buffersize=0,currentsize=0;
void producer()
51
printf("\nEnter number of elements to be produced: ");
scanf("%d",&n);
if(0<=(buffersize-(currentsize+n)))
currentsize+=n;
else
void consumer()
int x;
scanf("%d",&x);
if(currentsize>=x)
currentsize-=x;
else
printf("\nNumber of Elements consumed should not be greater than Number of Elements produced\n");
void main()
52
{
int c;
scanf("%d",&buffersize);
do
printf("\nEnter Choice:");
scanf("%d",&c);
switch(c)
case 1:
else
producer();
break;
case 2:
if(currentsize <= 0)
else
consumer();
break;
default:
break;
53
}
while(c!=3);
OUTPUT:
Enter Choice: 2
Enter Choice: 1
Enter Choice: 1
Enter Choice: 2
Enter Choice: 2
Number of elements consumed should not be greater than Number of Elements Produced
Enter Choice: 1
54
Enter number of elements to be produced: 5
Enter Choice: 1
RESULT:
Thus the C program to implement Producer Consumer problem using semaphore is executed
sucessfully.
55
Ex.No:7
AIM:
ALGORITHM:
Step 4: Enter the Max Matrix and calculate with Need = Max - Allocation
Step 5: Enter the Allocation Matrix and calculate for each process.
PROGRAM:
#include<stdio.h>
int i,j,np,nr;
void main()
int a[10][10],m[10][10],n[10][10],ar[10],t[10];
56
int a1[10][10],m1[10][10],ar1[10];
scanf("%d",&np);
scanf("%d",&nr);
for(i=0;i<nr;i++)
scanf("%d",&t[i]);
for(i=0;i<nr;i++)
printf("R%d\t",i+1);
for(i=0;i<np;i++)
printf("\nP%d\t",i+1);
for(j=0;j<nr;j++)
scanf("%d",&a[i][j]);
a1[i][j]=a[i][j];
printf("\n\n");
for(i=0;i<nr;i++)
printf("R%d\t",i+1);
57
for(i=0;i<np;i++)
printf("\nP%d\t",i+1);
for(j=0;j<nr;j++)
scanf("%d",&m[i][j]);
m1[i][j]=m[i][j];
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
n[i][j]=m[i][j]-a[i][j];
for(j=0;j<nr;j++)
ar[j]=t[j];
for(i=0;i<np;i++)
ar[j]-=a[i][j];
ar1[j]=ar[j];
if(safe(n,ar,a,m))
else
58
printf("\n\nConclusion: The system cannot acheive safe state");
additionalrequest(a1,m1,ar1);
int count;
count=0;
while(count<np)
for(i=0;i<np;i++)
count++;
visited[i]=1;
printf("P%d\t",i+1);
break;
if(i==np)
return 0;
return 1;
59
/*function for checking the processing of the process*/
for(j=0;j<nr;j++)
if(x[j]>ar[j])
return 0;
for(j=0;j<nr;j++)
ar[j]+=y[j];
y[j]=z[j]=0;
return 1;
/*Additional Request*/
int pno,vector[10];
int n1[10][10];
scanf("%d",&pno);
for(j=0;j<nr;j++)
scanf("%d",&vector[j]);
for(j=0;j<nr;j++)
a1[pno][j]+=vector[j];
60
ar1[j]-=vector[j];
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
n1[i][j]=m1[i][j]-a1[i][j];
if(safe(n1,ar1,a1,m1))
else
a1[pno][j]-=vector[j];
ar1[j]+=vector[j];
OUTPUT:
R1 R2 R3
P1 2 1 1
P2 4 2 1
P3 2 0 1
61
R1 R2 R3
P1 4 2 2
P2 3 2 2
P3 3 2 2
RESULT:
Thus the C program to implement banker’s algorithm for deadlock avoidance was executed
successfully.
62
Ex.No:8
AIM:
ALGORITHM:
Step 6: Find a process such that the process can complete with the available resources.
Step 7: After completion release and add the resources to available vector.
Step 8: Repeat step 6 and 7 until all process completed its execution.
PROGRAM:
#include<stdio.h>
int i,j,np,nr;
int main()
int alloc[10][10],request[10][10],avail[10],r[10],w[10];
scanf("%d",&np);
63
scanf("%d",&nr);
for(i=0;i<nr;i++)
scanf("%d",&r[i]);
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
scanf("%d",&request[i][j]);
for(i=0;i<np;i++)
for(j=0;j<nr;j++)
scanf("%d",&alloc[i][j]);
for(j=0;j<nr;j++)
avail[j]=r[j];
for(i=0;i<np;i++)
avail[j]-=alloc[i][j];
for(i=0;i<np;i++)
64
int count=0;
for(j=0;j<nr;j++)
if(alloc[i][j]==0)
count++;
else
break;
if(count==nr)
mark[i]=1;
for(j=0;j<nr;j++)
w[j]=avail[j];
for(i=0;i<np;i++)
int canbeprocessed=0;
if(mark[i]!=1)
for(j=0;j<nr;j++)
if(request[i][j]<=w[j])
canbeprocessed=1;
else
65
canbeprocessed=0;
break;
if(canbeprocessed)
mark[i]=1;
for(j=0;j<nr;j++)
w[j]+=alloc[i][j];
int deadlock=0;
for(i=0;i<np;i++)
if(mark[i]!=1)
deadlock=1;
if(deadlock)
else
66
OUTPUT:
dell@dell-Inspiron-5423:~$ cc detect.c
dell@dell-Inspiron-5423:~$ ./a.out
223
211
111
211
111
111
No Deadlock possible
RESULT:
Thus the C program to implement deadlock detection algorithm was executed successfully.
67
Ex.No:9
AIM:
ALGORITHM:
Step 3: Even if thread2 is scheduled to start while thread was not done, access to shared
Step 5: Stop
PROGRAM:
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
pthread_t tid[2];
int counter;
pthread_mutext_t lock;
unsigned long i = 0;
counter += 1;
68
for (i=0; i<0(0xFFFFFFFF); i++);
pthread_mutex_unlock( &lock);
return NULL;
main()
int i = 0;
return 1;
while ( i < 2 )
if (error != 0 )
i++;
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy( &lock);
return 0;
69
OUTPUT:
$ ./a.out
Job 1 started
Job 1 finished
Job 2 started
Job 2 finished
RESULT:
Thus the concurrent threads are executed and the output is verified successfully.
70
Ex.No:10
AIM:
ALGORITHM:
Step 2: Read the memory size, page size and number of process.
Step 4: If available allocate the page, otherwise display error memory is full.
Step 5: Read the logical address with page number and offset value.
PROGRAM:
#include<stdio.h>
Void main()
scanf("%d",&ms);
scanf("%d",&ps);
nop = ms/ps;
71
scanf("%d",&np);
rempages = nop;
for(i=1;i<=np;i++)
scanf("%d",&s[i]);
if(s[i] >rempages)
printf("\nMemory is Full");
break;
for(j=0;j<s[i];j++)
scanf("%d",&fno[i][j]);
else
pa=fno[x][y]*ps+offset;
72
}
OUTPUT:
dell@dell-Inspiron-5423:~$ ./a.out
Memory is Full
RESULT:
Thus the C program to implement paging technique of memory management was executed
successfully.
73
Ex.No:11a
AIM:
ALGORITHM:
Step 2: Read the number of blocks and block size of each blocks.
Step 5: Start by picking each process and check if it can be assigned to current block.
Step 6: If size-of-process <= size-of-block if yes then assign and check for next process.
PROGRAM:
#include<stdio.h>
void main()
flags[i] = 0;
allocation[i] = -1;
scanf("%d", &bno);
74
printf("\nEnter size of each block: ");
scanf("%d", &bsize[i]);
scanf("%d", &pno);
scanf("%d", &psize[i]);
allocation[j] = i;
flags[j] = 1;
break;
if(flags[i] == 1)
printf("%d\t\t\t%d",allocation[i]+1,psize[allocation[i]]);
else
printf("Not allocated");
75
}
OUTPUT:
dell@dell-Inspiron-5423:~$ ./a.out
1 100 2 75
2 150 1 125
3 200 3 100
4 350 4 200
5 450 5 350
RESULT:
Thus the C program to implement first fit memory allocation method was executed successfully.
76
Ex.No:11b
AIM:
ALGORITHM:
Step 2: Read the number of blocks and block size of each blocks.
Step 5: Start by picking each process and find the maximum block size that can be assigned to
current process i.e., find max(bockSize[1], blockSize[2],.....blockSize[n]) > processSize[current],
if found then assign it to the current process.
Step 6: If not then leave that process and keep checking the further processes.
PROGRAM:
#include<stdio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;
scanf("%d",&nb);
scanf("%d",&nf);
77
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
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++)
temp=b[j]-f[i];
if(temp>=0)
if(highest<temp)
ff[i]=j;
highest=temp;
78
}
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]);
79
OUTPUT:
dell@dell-Inspiron-5423:~$ cc worstfit.c
dell@dell-Inspiron-5423:~$ ./a.out
Block 1:10
Block 2:20
Block 3:30
File 1:15
File 2:23
File 3:30
1 15 3 30 15
2 23 0 -1080227116 0
3 30 0 -1080227116 0
RESULT:
Thus the C program to implement worst fit memory allocation method was executed successfully.
80
Ex.No:11c
AIM:
ALGORITHM:
Step 2: Read the number of blocks and block size of each blocks.
Step 5: Start by picking each process and find the maximum block size that can be assigned to
current process i.e., find max(bockSize[1], blockSize[2],.....blockSize[n]) > processSize[current],
if found then assign it to the current process.
Step 6: If not then leave that process and keep checking the further processes.
PROGRAM:
#include<stdio.h>
#define max 25
void main()
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
scanf("%d",&nb);
scanf("%d",&nf);
81
for(i=1;i<=nb;i++)
printf("Block %d:",i);
scanf("%d",&b[i]);
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;
82
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
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]);
OUTPUT:
dell@dell-Inspiron-5423:~$ ./a.out
Block 1:10
Block 2:15
Block 3:25
Block 4:35
File 1:15
File 2:23
File 3:45
File 4:29
1 15 2 15 0
2 23 3 25 2
83
RESULT:
Thus the C program to implement best fit memory allocation method was executed successfully.
84
Ex.No:12a
AIM:
To Write a C program to implement Page replacement algorithm- First In First Out (FIFO).
ALGORITHM:
Step 4: Check the need of replacement from old page to new page in memory
PROGRAM:
#include <stdio.h>
int main()
scanf(“%d”,&a[i]);
scanf(“%d”, &no);
85
for(i=0; i<no; i++)
frame[i] = -1;
j = 0;
printf(“%d\t\t”, a[i]);
avail = 0;
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”)
86
return 0;
OUTPUT:
dell@dell-Inspiron-5423:~$ ./a.out
10
7012030423
7 7 -1 -1
0 7 0 -1
1 7 0 1
2 2 0 1
3 2 3 1
0 2 3 0
4 4 3 0
2 4 2 0
3 4 2 3
Page Fault Is 9
RESULT:
Thus the C program to implement Page replacement algorithm- First In First Out (FIFO) was
executed successfully.
87
Ex.No:12b
AIM:
To Write a C program to implement Page replacement algorithm- Least Recently Used (LRU).
ALGORITHM:
PROGRAM:
#include<stdio.h>
main()
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages:");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames:");
88
scanf("%d",&f);
q[k]=p[k];
printf("\n\t%d\n",q[k]);
c++;
k++;
for(i=1;i<n;i++)
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
89
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];
b[r]=b[j];
b[j]=t;
for(r=0;r<f;r++)
90
{
if(c2[r]==b[0])
q[r]=p[i];
printf("\t%d",q[r]);
printf("\n");
OUTPUT:
dell@dell-Inspiron-5423:~$ cc lru.c
dell@dell-Inspiron-5423:~$ ./a.out
Enter no of pages:10
Enter no of frames:3
7 5
7 5 9
4 5 9
4 5 7
4 3 7
5 3 7
5 2 7
91
RESULT:
Thus the C program to implement Page replacement algorithm- Least Recently Used (LRU) was
executed successfully.
92
Ex.No:12c
AIM:
To Write a C program to implement Page replacement algorithm- Least Frequently Used (LFU).
ALGORITHM:
Step 5: In LFU (Least Frequently Used) algorithm the page which has with the smallest count is
going to be replaced.
PROGRAM:
#include<stdio.h>
int n,nf;
int in[100];
int p[50];
int hit=0;
int i,j,k;
int pgfaultcnt=0;
void getData()
scanf("%d",&n);
93
printf("\nEnter the page reference sequence:");
scanf("%d",&in[i]);
printf("\nEnter no of frames:");
scanf("%d",&nf);
void initialize()
pgfaultcnt=0;
p[i]=9999;
hit=0;
if(p[j]==data)
hit=1;
break;
return hit;
94
{
int hitind;
if(p[k]==data)
hitind=k;
break;
return hitind;
void dispPages()
if(p[k]!=9999)
printf(" %d",p[k]);
void dispPgFaultCnt()
void lfu()
95
{
int usedcnt[100];
int least,repin,sofarcnt=0,bn;
initialize();
usedcnt[i]=0;
if(isHit(in[i]))
int hitind=getHitIndex(in[i]);
usedcnt[hitind]++;
else
pgfaultcnt++;
if(bn<nf)
p[bn]=in[i];
usedcnt[bn]=usedcnt[bn]+1;
bn++;
else
96
least=9999;
if(usedcnt[k]<least)
least=usedcnt[k];
repin=k;
p[repin]=in[i];
sofarcnt=0;
if(in[i]==in[k])
sofarcnt=sofarcnt+1;
usedcnt[repin]=sofarcnt;
dispPages();
dispPgFaultCnt();
int main()
getData();
lfu();
97
OUTPUT:
dell@dell-Inspiron-5423:~$ cc lfu.c
dell@dell-Inspiron-5423:~$ ./a.out
Enter no of frames: 3
For 7 : 7
For 0 : 7 0
For 1 : 7 0 1
For 2 : 2 0 1
For 3 : 3 0 1
For 4 : 4 0 1
For 2 : 2 0 1
For 3 : 2 0 3
For 1 : 1 0 3
For 2 : 2 0 3
For 1 : 2 0 1
For 7 : 2 0 7
For 1 : 2 0 1
98
Total no of page faults:13
RESULT:
Thus the C program to implement Page replacement algorithm- Least Frequently Used (LRU)
was executed successfully.
99
Ex.No:13a
AIM:
To Write a C program to implement file organization technique- single level directory structure.
ALGORITHM:
Step1: Start
Step 2: Create a single directory and read the name of the directory.
Step 5: Search the files in the directory and display the result of search operation.
Step 6: Delete the files in the directory and display the files.
Step 7: Stop
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct
char dname[10],fname[10][10];
int fcnt;
}dir;
void main()
int i,ch;
char f[30];
100
dir.fcnt = 0;
scanf("%s", dir.dname);
while(1)
printf("\n\n 1. Create File\t2. Delete File\t3. Search File \n 4. Display Files\t5. Exit\nEnter your choice --
");
scanf("%d",&ch);
switch(ch)
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
if(strcmp(f, dir.fname[i])==0)
strcpy(dir.fname[i],dir.fname[dir.fcnt-1]);
break;
if(i==dir.fcnt)
101
else
dir.fcnt--;
break;
scanf("%s",f);
for(i=0;i<dir.fcnt;i++)
if(strcmp(f, dir.fname[i])==0)
break;
if(i==dir.fcnt)
break;
case 4: if(dir.fcnt==0)
else
for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);
break;
default: exit(0);
102
}
OUTPUT:
dell@dell-Inspiron-5423:~$ cc single.c
dell@dell-Inspiron-5423:~$ ./a.out
File b is deleted
103
1. Create File 2. Delete File 3. Search File 4. Display Files 5. Exit
RESULT:
Thus the C program to implement file organization technique-single level directory structure was
executed successfully.
104
Ex.No:13b
AIM:
To Write a C program to implement file organization technique- two level directory structure.
ALGORITHM:
Step1: Start
Step 2: Create directories to store files and read the name of the directories.
Step 3: Create files in the directory by entering the name of the directory first.
Step 5: Search the files in the directory and display the result of search operation.
Step 6: Delete the files in the directory and display the files.
Step 7: Stop
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct
char dname[10],fname[10][10];
int fcnt;
}dir[10];
void main()
int i,ch,dcnt,k;
105
dcnt=0;
while(1)
scanf("%d",&ch);
switch(ch)
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
scanf("%s",dir[i].fname[dir[i].fcnt]);
dir[i].fcnt++;
printf("File created");
break;
if(i==dcnt)
106
printf("Directory %s not found",d);
break;
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
dir[i].fcnt--;
strcpy(dir[i].fname[k],dir[i].fname[dir[i].fcnt]);
goto jmp;
goto jmp;
jmp : break;
107
case 4: printf("\nEnter name of the directory -- ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
scanf("%s",f);
for(k=0;k<dir[i].fcnt;k++)
if(strcmp(f, dir[i].fname[k])==0)
goto jmp1;
goto jmp1;
jmp1: break;
case 5: if(dcnt==0)
else
108
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
printf("\n%s\t\t",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("\t%s",dir[i].fname[k]);
break;
default:exit(0);
OUTPUT:
dell@dell-Inspiron-5423:~$ cc two.c
dell@dell-Inspiron-5423:~$ ./a.out
Directory created
Directory created
109
1. Create Directory 2. Create File 3. Delete File
File created
File created
File created
Directory Files
aa one two
bb one
110
Enter your choice -- 4
RESULT:
Thus the C program to implement file organization technique-two level directory structure was
executed successfully.
111
Ex.No:14a
AIM:
ALGORITHM:
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
int f[50],i,st,j,len,c,k;
for(i=0;i<50;i++)
f[i]=0;
X:
scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j++)
if(f[j]==0)
112
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
else
break;
if(j==(st+len))
scanf("%d",&c);
if(c==1)
goto X;
else
exit(0);
OUTPUT:
dell@dell-Inspiron-5423:~$ cc seq.c
dell@dell-Inspiron-5423:~$ ./a.out
10->1
11->1
12->1
13->1
113
14->1
15->1
16->1
RESULT:
Thus the C program to implement sequential file allocation was executed successfully.
114
Ex.No:14b
AIM:
ALGORITHM:
Step 4: Check the files are allocated based on the indexes that are created for each fragment of the
file.
Step 5: Check that each and every similar indexed file is maintained by the primary index
thereby providing flow to the file fragments.
Step: 6 Allocate the files to the disk.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int f[50],i,k,j,inde[50],n,c,count=0,p;
void main()
for(i=0;i<50;i++)
f[i]=0;
x:
scanf("%d",&p);
115
if(f[p]==0)
f[p]=1;
scanf("%d",&n);
else
goto x;
for(i=0;i<n;i++)
scanf("%d",&inde[i]);
for(i=0;i<n;i++)
if(f[inde[i]]==1)
goto x;
for(j=0;j<n;j++)
f[inde[j]]=1;
printf("\n allocated");
for(k=0;k<n;k++)
printf("\n %d->%d:%d",p,inde[k],f[inde[k]]);
116
scanf("%d",&c);
if(c==1)
goto x;
else
exit(0);
OUTPUT:
dell@dell-Inspiron-5423:~$ cc index.c
dell@dell-Inspiron-5423:~$ ./a.out
14
allocated
file indexed
5->1:1
5->4:1
367
117
enter no of files on index 2
11 12
allocated
file indexed
9->11:1
9->12:1
RESULT:
Thus the C program to implement indexed file allocation was executed successfully.
118
Ex.No:14c
AIM:
ALGORITHM:
Step: 7 Check that each and every fragment is linked to the other file through either addresses or
pointers. Check that the starting location of the file serves for the purpose of extraction of the
entire file because every fragment is linked to each other.
Step: 8 Allocate the files to the disk.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void main()
int f[50],p,i,j,k,a,st,len,n,c;
for(i=0;i<50;i++)
f[i]=0;
119
scanf("%d",&p);
for(i=0;i<p;i++)
scanf("%d",&a);
f[a]=1;
X:
scanf("%d%d",&st,&len);
k=len;
for(j=st;j<(k+st);j++)
if(f[j]==0)
f[j]=1;
printf("\n%d->%d",j,f[j]);
else
k++;
scanf("%d",&c);
120
if(c==1)
goto X;
else
exit(0);
OUTPUT:
dell@dell-Inspiron-5423:~$ cc linked.c
dell@dell-Inspiron-5423:~$ ./a.out
14892
3->1
5->1
6->1
7->1
10->1
dell@dell-Inspiron-5423:~$
RESULT:
Thus the C program to implement linked file allocation was executed successfully.
121
Ex.No:15a
AIM:
ALGORITHM:
Step 1: Let Request array represents an array storing indexes of tracks that have been requested in
ascending order of their time of arrival. ‘head’ is the position of disk head.
Step 2: Let us one by one take the tracks in default order and calculate the absolute distance of the
track from the head.
Step 4: Currently serviced track position now becomes the new head position.
Step 5: Go to step 2 until all tracks in request array have not been serviced.
PROGRAM:
#include<stdio.h>
int main()
int queue[20],n,head,i,j,k,seek=0,max,diff;
float avg;
scanf("%d",&max);
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&queue[i]);
122
scanf("%d",&head);
queue[0]=head;
for(j=0;j<=n-1;j++)
diff=abs(queue[j+1]-queue[j]);
seek+=diff;
avg=seek/(float)n;
return 0;
123
OUTPUT:
200
50
RESULT:
Thus the C program for to implement FCFS disk scheduling algorithms was executed and the
output is verified successfully.
124
Ex.No:15b
AIM:
ALGORITHM:
Step 1: Let Request array represents an array storing indexes of tracks that have been requested.
‘head’ is the position of disk head.
Step 2: Find the positive distance of all tracks in the request array from head.
Step 3: Find a track from requested array which has not been accessed/serviced yet and has
minimum distance from head.
Step 5: Currently serviced track position now becomes the new head position.
Step 6: Go to step 2 until all tracks in request array have not been serviced.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
int queue[100],t[100],head,seek=0,n,i,j,temp;
float avg;
clrscr();
scanf("%d",&n);
125
for(i=0;i<n;i++)
scanf("%d",&queue[i]);
scanf("%d",&head);
for(i=1;i<n;i++)
t[i]=abs(head-queue[i]);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(t[i]>t[j])
temp=t[i];
t[i]=t[j];
t[j]=temp;
temp=queue[i];
queue[i]=queue[j];
queue[j]=temp;
for(i=1;i<n-1;i++)
seek=seek+abs(head-queue[i]);
126
head=queue[i];
avg=seek/(float)n;
return 0;
OUTPUT:
RESULT:
Thus the C program to implement SSTF disk scheduling algorithm was executed and the output is
verified successfully.
127
Ex.No:16
128
Step 3: Pick how to install the operating system.
Select Installer disc if the operating system is in the disc drive. Otherwise, choose Installer disc image
file (iso) if you have a file that contains the OS, like a Windows 10 ISO or an ISO for macOS.
129
If you selected to install the operating system from a disc, choose the correct disc drive from the drop-
down menu. For an ISO install, select Browse and locate the ISO image.
Step 5: Press Next to proceed to the screen where you name the new virtual machine and pick where its
files should be stored. Fill out that information and then select Next again.
130
Be sure to pick a location that can handle the possibly ultra-large files created by the operating system as
you use it. You might end up needing hundreds of gigabytes if you use this VM heavily. Storing it on an
external hard drive is a good idea if your local hard drive doesn’t have the space.
Note: For some operating system setups, you’ll be asked to enter the product key used to activate it. You
should be able to skip through that step if you want to enter the key later.
Step 6: Define how storage should take place with this virtual machine, and then press Next.
131
You can change the maximum size of the virtual hard drive from the small box. From the bottom of this
window are two options: Store virtual disk as a single file and Store virtual disk into multiple files.
Pick the second option if you think you might one day move the VMware hard drive to a different
computer, but take note of the text on that screen that mentions a possible performance reduction of using
multiple files with a large hard drive.
In other words, if you plan to store lots of data in this VM, select the “single file” option, otherwise go
with “multiple files.”
Step 7: Select Customize Hardware and make any necessary changes. You can change details about the
memory, processors, disc drive, network adapter, USB controller, sound card, printer, and display.
132
For example, the Memory section is how you specify how much physical RAM the virtual machine is
allotted. If you later decide that you’ve given too little memory to the VM, it might perform slowly.
Similarly, if you give too much, your host computer will perform sluggishly and will have a difficult time
even using the VM.
VMware Workstation recommends a specific amount based on how much you have installed, but you can
adjust the memory to anything you like (though it’s best to stick to the recommended level). Different
operating systems require different amounts of memory (e.g., Windows 10 needs more than Windows
2000).
Network Adapter is an important component here that you might end up having to adjust later if your
virtual machine doesn’t have internet access. There are multiple options, and some may or may not work
properly depending on how your host computer is set up and how the guest OS (the VM) works. You can
skip this for now to have the default option chosen for you.
133
Step 8: Choose Close to exit the Hardware screen, and then press Finish.
VMware Workstation will create the virtual disk you specified in Step 6 and then turn on the virtual
machine automatically. This process might take a while, but you can watch the progress bar for an
estimation of when it will finish.
Step 9: Follow any on-screen prompts to begin the OS installation. For example, if you see Press any key
to boot from CD or DVD, do that to start the OS setup.
Step 10: Follow the directions for your specific operating system install to add the OS to VMware
Workstation.
134
At any time when the VMware virtual machine is on, you can shut it down or restart it from
the VM > Power menu. This is also how you suspend the VM, which means to pause it so that you can
resume at that exact same point the next time you access it. This is different from powering it on from an
off state where you have to log back in again, open programs and files, etc.
135
RESULT:
136
137