CS3461-OS Lab Record
CS3461-OS Lab Record
Regulation - 2021
RECORD
Name :
Reg. No :
Year/ Semester :
P.T.Lee Chengalvaraya Naicker
College of Engineering & Technology
(Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai)
Vallal P.T.Lee Chengalvaraya Naicker Nagar, Oovery,
Kanchipuram – 631 502.
BONAFIDE CERTIFICATE
RegNo:
Certified that this is a bonafide record of work done by the Candidate
Mr\Mrs. in CS3461-Operating
System Laboratory during for academic year .
PAGE
EX.NO DATE NAME OF THE PROGRAM SIGN
NO
THREADING &
9
SYNCHRONIZATION
APPLICATIONS
PAGING TECHNIQUE OF
10
MEMORY
MANAGEMENT
Aim
To install the windows 10 operating System.
Procedure
Creating an Installation Disc or Drive
Connect a blank USB flash drive or insert a blank writable DVD. You can install Windows 10 by
creating a bootable USB flash drive or DVD that contains the Windows 10 installation files. You'll
need a USB flash drive that's at least 8GB, or any blank DVD to get started.
If you already have Windows 10 installed on the PC and just want to reinstall it, it'll be easiest to
reinstall it from within Windows 10 instead of creating installation media.
If you want to upgrade from Windows 7 or Windows 8.1, you won't need to create an installation disc
or drive. However, you will need to follow most of this method to start the upgrade.
Boot the PC into the BIOS. If your PC is not already set up to boot from your flash or optical drive,
rebooting from your installation media won't work. You'll need to make a quick change inyour BIOS
to change the boot order.
Reboot the PC and immediately start pressing (over and over again) the F12 key required by your PC
to enter "Setup," or the BIOS.
Go to the Boot tab. You'll use the arrow keys to select it.
The Boot tab may instead say Boot Options or Boot Order, depending on your computer's
manufacturer.
1
Select a device from which to boot. You have a couple of options here:For a
For a disc installation, select the CD-ROM Drive or Optical Drive option.
Press the + key until your boot option is first. Once either Removable Devices or CD-ROM Driveis
at the top of the list, your computer will select your choice as its default boot option.
On some computers, you'll instead press one of the function keys (e.g., F5 or the arrow keys tonavigate an
option up to the top of the menu.
Save your settings. You should see a key prompt (e.g., F10 at the bottom of the screen thatcorrelates to
"Save and Exit". Pressing it will save your settings and restart your computer.
2
Wait for your computer to restart. Once your computer finishes restarting, you'll see a window here
with your geographical data. You're now ready to begin setting up your Windows 10 installation.
3
Click Next when prompted. You can also change the options on this page (e.g., the setuplanguage)
before continuing if need be.
4
Enter your Windows 10 key, then click Next. If you don't have a Windows 10 key, instead click Skip
in the bottom-right corner of the screen.
If you've already installed Windows 10 on this PC and were signed in with your Microsoft account,
your key should be linked to your account. When prompted, just sign in with your Microsoft account
and Windows will locate your key.[4]
If you've changed hardware in the PC, such as replacing the motherboard, you can activate Windows
after installing by going to Settings > Update & Security > Activation > Troubleshoot >I changed
hardware on this device recently. Sign in with your Microsoft account when prompted, choose This is
the device I'm using right now, and then click Activate.
Follow the on-screen instructions to install Windows 10. You'll be asked to perform a few tasks, such
as connecting to Wi-Fi and choosing some preferences. Once the installation is complete, you'll have
a fresh new installation of Windows 10.
5
If you're upgrading from an earlier version of Windows, you'll be asked if you want to upgrade the
current operating system or do a custom install. If you choose Upgrade, you'll preserve existing apps
and files.
Result
Thus the windows 10 operating system was successfully installed.
6
Ex No : 2A
BASICS OF UNIX COMMANDS
Date :
Aim
To study about the basics of UNIX Commands.
UNIX:
It is a multi-user operating system. Developed at AT & T Bell Industries, USA in 1969.
Ken Thomson along with Dennis Ritchie developed it from MULTICS (Multiplexed
Information and Computing Service) OS. By1980, UNIX had been completely rewritten using C
language.
LINUX:
It is similar to UNIX, which is created by Linus Torualds. All UNIX commands works in
Linux. Linux is a open source software. The main feature of Linux is coexisting with other OS such as
windows and UNIX.
UNIX KERNEL:
Kernel is the core of the UNIX OS. It controls all tasks, schedule all Processes and carries out
all the functions of OS. Decides when one programs tops and another starts.
SHELL:
Shell is the command interpreter in the UNIX OS. It accepts command from the user and
analyses and interprets them.
UNIX COMMANDS
7
Syn:$date
Syn:$echo “text”
d) ls
–used to list the files.
Syn: $lsls–s
All files (include files with prefix)
ls– u Sort by access time (or show when last accessed together with –l)ls–s
ls–f Mark directories with /,executable with* , symbolic links with @, local sockets with =,
named pipes(FIFOs)with
ls–s Show file size ls– h“ Human Readable”, show file size in Kilo Bytes & Mega Bytes (h can be
used together with –l or)
ls[a-m]*List all the files whose name begin with alphabets From „a‟ to „m‟ls[a]*List
Eg:$ls>my list Output of „ls‟ command is stored to disk file named „my list‟
8
Syn:$lp filename
f) man –used to provide manual help on every UNIX commands.
g) who & whoami –it displays data about all users who have logged into the system currently.
The next command displays about current user only.
Syn: $who
$whoami
h) uptime –tells you how long the computer has been running since its last reboot or power-off.
Syn:$uptime
i) uname –it displays the system information such as hardware platform, system name and
processor, OS type.
Syn:$uname–a
j) hostname –displays and set system host name
Syn:$ hostname
k) bc –stands for „best calculator‟
9
FILE MANIPULATION COMMANDS
a) cat–this create, view and concatenate files.
Creation:
Syn:$cat>filenam
eViewing:
Syn:$cat filename
Add text to an existing file:
Syn:$cat>>file
name
Concatenate:
Syn:$cat file1 file2>file3
b) grep–used to search a particular word or pattern related to that word from the file.
filenameEg:$grep anu
student
c) rm–deletes a file from the file system
Syn:$rm filename
d) touch–used to create a blank file.
stud
10
f) mv–to rename the file or directory
Syn:$cut<option><filename
$cut–c1-10emp
$cut–f 3,6emp
-c cutting columns
-f cutting fields
Syn:$head
filename
Eg:$head
student
To display the top two lines:
Syn:$head-2student
Syn:$tail
filename
Eg:$tail
student
To display the bottom two lines;
11
File–are used to assign or remove permission all
$chmodg=rwx student
Assigns absolute permission for groups of all read, write and execute permissionsk)wc
It counts the number of lines, words, character in a specified file(s) with the options as –l,-w,-c
$wc–c filename
RESULT
12
Ex No : 2B PROGRAM- SHELL PROGRAM TO CHECK THE GIVEN
Date :
NUMBER ISEVEN OR ODD
read n
r=`expr $n % 2`
if [ $r -eq 0 ]
then
else
OUTPUT
RESULT
Thus the above shell program for check the given number is even or odd has been verifiedand
executed successfully.
13
Ex No : 2C PROGRAM- SHELL PROGRAM TO CHECK THE GIVEN
YEAR ISLEAP YEAR OR NOT
Date :
read y
b=`expr $y % 4`
if [ $b -eq 0 ]
then
else
OUTPUT
RESULT
Thus the above shell program for check the given year is leap year or not has been verified andexecuted
successfully.
14
Ex No : 2D PROGRAM- SHELL PROGRAM TO FIND THE
FACTORIAL OF ANUMBER
Date :
read n
i=`expr $n - 1`
p=1
while [ $i -ge 1 ]
do
n=`expr $n \* $i
` i=`expr $i - 1`
done
OUTPUT
RESULT
Thus the above shell program for factorial of a number has been verified and executed
successfully.
15
Ex No : 2E PROGRAM- SHELL PROGRAM TO SWAP THE TWO
INTEGERS
Date :
PROGRAM:
read a b
temp=$a
a=$b
b=$temp
echo $a $b
OUTPUT
RESULT
Thus the above shell program for swapping of two integers has been verified and executed
successfully.
16
Ex No : 3A PROGRAM- SYSTEM CALLS (OPENDIR, READDIR, CLOSEDIR)
Date :
PROGRAM:
#include<stdio.h>
#include<dirent.h>
#include<stdlib.h>
struct dirent *dptr;
int main(int argc, char *argv[])
{
char buff[100];
DIR *dirp;
printf(“\n\n ENTER DIRECTORY NAME”);
scanf(“%s”, buff);
if((dirp=opendir(buff))==NULL)
{
printf(“The given directory does not exist”);exit(1);
}
while(dptr=readdir(dirp))
{
printf(“%s\n”,dptr->d_name);
}
closedir(dirp);
}
17
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
18
Ex No : 3B PROGRAM- SYSTEM CALLS (FORK, GETPID, EXIT)
Date :
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main()
int pid,pid1,pid2;
pid=fork();
if(pid==-1)
exit(1);
if(pid!=0)
{ pid1=getpid();
else
pid2=getpid();
19
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
20
Ex No : 4A PROGRAM- FCFS SCHEDULING
Date :
PROGRAM:
#include<stdio.h>
wt[0] = 0;
void findTurnAroundTime( int processes[], int n, int bt[], int wt[], int tat[])
i++)tat[i] = bt[i] +
wt[i];
printf(" %d ",(i+1));
printf("\n");
int main()
0;
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
22
Ex No : 4B PROGRAM - SJF SCHEDULING
Date :
PROGRAM:
#include <stdio.h>
int main()
int A[100][4];
scanf("%d", &n);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;
{index = i;
if (A[j][1] <
A[index][1])index = j;
temp = A[i][1];
A[i][1] =
A[index][1];
A[index][1] = temp;
temp = A[i][0];
23
A[i][0] = A[index][0];
A[index][0] = temp;
A[0][2] = 0;
{A[i][2] = 0;
for (j = 0; j < i;
j++)A[i][2] +=
A[j][1];
total += A[i][2];
avg_wt = (float)total / n;
total = 0;
printf("P BT WT
TAT\n");for (i = 0; i
< n; i++) {
total += A[i][3];
avg_tat = (float)total / n;
24
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
25
Ex No : 4C PROGRAM - PRIORITY SCHEDULING
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
typedef struct
int pno;
int pri;
int btime;
int wtime;
}sp;
int main()
int i,j,n=0;
int tbm=0,totwtime=0,totttime=0;sp
*p,t;
scanf("%d",&n);
p=(sp*)malloc(sizeof(sp));
for(i=0;i<n;i++)
printf("process%d:”,i+1);
scanf("%d%d",&p[i].btime,&p[i].pri);
p[i].pno=i+1;
26
p[i].wtime=0;
}
for(i=0;i<n-
1;i++)
for(j=i+1;j<n;j++
if(p[i].pri>p[j].pri)
t=p[i];
p[i]=p[j];
p[j]=t;
for(i=0;i<n;i++)
totwtime+=p[i].wtime=tbm;
tbm+=p[i].btime;
printf("\n%d\t\t%d",p[i].pno,p[i].btime);
printf("\t\t%d\t\t%d",p[i].wtime,p[i].wtime+p[i].btime);
totttime=tbm+totwtime;
27
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
28
Ex No : 4D PROGRAM - ROUND ROBIN SCHEDULING
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
struct rr
int pno,btime,sbtime,wtime,lst;
}p[10];
int main()
int pp=-1,ts,flag=0,count=0,ptm=0,i,n,twt=0,totttime=0;
printf("enter no of processes:");
scanf("%d",&n);
scanf("%d",&ts); printf("enter
for(i=0;i<n;i++)
printf("\n process%d\t",i+1);
scanf("%d",&p[i].btime);
p[i].wtime=p[i].lst=0;
p[i].pno=i+1;
p[i].sbtime=p[i].btime;
29
do
{
flag=0;
for(i=0;i<n;i++
count=p[i].btime;
if(count>0)
flag=-1;
count=(count>=ts)?ts:count;
printf("from%d",ptm);
ptm+=count; printf("to%d",ptm);
p[i].btime-=count;
if(pp!=i)
pp=i;
p[i].wtime+=ptm-p[i].lst-count;
p[i].lst=ptm;
}while(count>0);
30
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
31
Ex No : 5 PROGRAM- IPC USING SHARED MEMORY
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<sys/types.h>
int shmid,cntr;
*segptr;
key=ftok(".",'s');
if((shmid=shmget(key,SEGSIZE,0))==-1)
perror("shmget");
exit(1);
Else
{
32
printf("Creating a new shared memory seg \n");
printf("SHMID:%d",shmid);}
system("ipcs –m");
if((segptr=(char*)shmat(shmid,0,0))==(char*)-1)
perror("shmat");
exit(1);
strcpy(segptr,buff);
printf("DONE\n");
printf("DATA:-%s\n",segptr);
printf("DONE\n");
if(shmctl(shmid,IPC_RMID,0)== -1)
else
printf("Removed Successfully");
33
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
34
Ex No : 6 PROGRAM- PRODUCER CONSUMER PROBLEM
USINGSEMAPHORES
Date :
PROGRAM:
#include<stdio.h>
int mutex=1,full=0,empty=3,x=0;
void main()
int n;
void producer();
void consumer();
int wait(int);
int signal(int);
printf("\n1.PRODUCER\n2.CONSUMER\n3.EXIT\n");
while(1) {
printf("\nENTER YOUR
CHOICE\n");scanf("%d",&n);
switch(n)
{ case 1:
if((mutex==1)&&(empty!=0))
producer();
else
printf("BUFFER IS FULL");
break;
case 2:
if((mutex==1)&&(full!=0)
)consumer();
else
35
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);
x++;
mutex=signal(mutex); }
void consumer() {
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
-;
mutex=signal(mutex);
}
36
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
37
Ex No : 7 BANKERS ALGORITHM FOR DEADLOCK
AVOIDANCE
Date :
PROGRAM:
#include<stdio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n,r;
void input();
void show();
void cal();
int main()
int i,j;
input();
show();
cal();
return 0;
void input()
int i,j;
scanf("%d",&n);
for(j=0;j<r;j++)
scanf("%d",&max[i][j]);
for(i=0;i<n;i++) {
for(j=0;j<r;j++) {
scanf("%d",&alloc[i][j])
for(j=0;j<r;j++) {
scanf("%d",&avail[j]);
void show()
int i,j;
for(i=0;i<n;i++)
printf("\nP%d\t ",i+1);
39
for(j=0;j<r;j++)
printf("%d ",alloc[i][j]);
printf("\t");
for(j=0;j<r;j++
printf("%d ",max[i][j]);
printf("\t");
if(i==0) {
for(j=0;j<r;j++
printf("%d ",avail[j]);
void cal()
int finish[100],temp,need[100][100],flag=1,k,c1=0;int
safe[100];
int i,j;
for(i=0;i<n;i++)
{finish[i]=0; }
for(i=0;i<n;i++)
{for(j=0;j<r;j++)
40
need[i][j]=max[i][j]-alloc[i][j];}
printf("\n");
while(flag)
flag=0;
for(i=0;i<n;i++
int c=0;
for(j=0;j<r;j++
if((finish[i]==0)&&(need[i][j]<=avail[j]))
c++
if(c==r)
for(k=0;k<r;k++) {
avail[k]+=alloc[i][j]
;finish[i]=1;
flag=1; }
printf("P%d->",i);
if(finish[i]==1)
i=n;
}}}}}}
41
for(i=0;i<n;i++){
if(finish[i]==1)
c1++;
else
printf("P%d->",i);
if(c1==n)
else
42
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
43
Ex No : 8
PROGRAM- ALGORITHM FOR DEADLOCK DETECTION
Date :
PROGRAM:
#include<stdio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n,r;
void input();
void show();
void cal();
int main()
int i,j;
input();
show();
cal();
return 0;
void input ()
int i , j;
44
scanf ("%d", &r);
printf ("Enter the Max Matrix \n");for (i=0 ; i<n;i++)
{
for(i=0;i<n;i++)
scanf("%d",&alloc[i][j]);
scanf("%d",&avail[j]);
}}
void show ()
int i,j;
for(j=0;j<r;j++)
{
45
printf ("%d ",alloc[i][j]);
for(j=0;j<r;j++
printf(" \t");
if(i==0)
for(j=0;j<r;j++)
printf("%d ",avail[j]);
void cal ()
int finish[100],temp,need[100][100],flag=1,k,cl=0;int
dead[100];
int safe[100];
int
i,j;for(i=0;i<n
;i++)
finish[i]=0;
46
for(i=0;i<n;i++)
{for(j=0;j<r;j++)
need[i][j]=max[i][j]-alloc[i][j];
}}
while(flag)
flag=0;
for(i=0;i<n;i++
int c=0;
for(j=0;j<r;j++
if((finish[i]==0)&&(need[i][j]<=avail[j]))
c++
if(c==r)
for(k=0;k<r;k++)
avail[k]+=alloc[i][j]
;finish[i]=1;
flag=1;
if(finish[i]==1)
47
{
i=n;
}}}}
}}
j=0;
flag=0;
for(i=0;i<n;i++
if(finish[i]==0)
dead[j]=i;
j++;
flag=1;
if(flag==1)
for(i=0;i<n;i++)
printf("P%d\t",dead[i]);
Else
{
printf("\nNo Deadlock Occur");
48
}
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
49
Ex No : 9 THREADING & SYNCHRONIZATIONAPPLICATIONS
Date :
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
id = pthread_self();
if(pthread_equal(id ,tid[0]))
else
for(i=0; i<(0xFFFFFFFF);i++)
return NULL;
int main(void)
int i = 0;
50
int err;
while(i < 2)
if (err != 0)
i++;
sleep(5);
return 0;
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
51
Ex No : 10 PAGING TECHNIQUE OF MEMORY
MANAGEMENT
Date :
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
int counter;
pthread_mutex_t lock;
pthread_mutex_lock(&lock);
unsigned long i = 0;
counter += 1;
return NULL;
int main(void)
int i = 0;
int err;
if (pthread_mutex_init(&lock, NULL) != 0)
{
printf("\n mutex init failed\n");return 1;
}
52
while(i < 2)
{
if (err != 0)
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
pthread_mutex_destroy(&lock);
return 0;
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
53
Ex No : 11A MEMORY ALLOCATION METHODS FOR FIXED
PARTITION -FIRST FIT
Date :
PROGRAM:
#include<stdio.h>
#define max 25
void main()
clrscr();
scanf(“%d”,&nb);
scanf(“%d”,&nf);
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++)
54
{
for(j=1;j<=nb;j++)
{
if(bf [j]!=1)
if(temp>=0)
ff
[i]=j;
break;
frag [i]=temp;
printf(“\nFile_no:\tFile_size:\tBlock_no:\tBlock_size:\tFragement”);
for(i=1;i<=nf;i++)
55
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
56
Ex No : 11B MEMORY ALLOCATION METHODS FOR FIXED
PARTITION - WORST FIT
Date :
PROGRAM:
#include<stdio.h>
#define max 25
void main()
clrscr();
scanf(“%d”,&nf);
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++)
{
57
for(j=1;j<=nb;j++)
{
if(bf [j]!=1)
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();
58
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
59
Ex No : 11C MEMORY ALLOCATION METHODS FOR FIXED
PARTITION - BEST FIT
Date :
PROGRAM:
#include<stdio.h>
#define max 25
void main()
int frag[max],b[max],f[max],I,j,nb,nf,temp,lowest=10000;
clrscr();
scanf(“%d”,&nb);
scanf(“%d”,&nf);
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+);
}
60
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
temp=b[j] – f[j];
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_Size\tFragement”);
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();
61
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
62
Ex No : 12A PAGE REPLACEMENT ALGORITHMS- FIFO
Date :
PROGRAM:
#include<stdio.h>
int main()
int pageFaults = 0;
int frames = 3;
int m, n, s, pages;
pages = sizeof(incomingStream)/sizeof(incomingStream[0]);
int temp[frames];
temp[m] = -1;
s = 0;
if(incomingStream[m] == temp[n])
s++;
pageFaults--;
}
63
}
pageFaults++;
{
temp[m] = incomingStream[m];
else if(s == 0)
printf("\n");
printf("%d\t\t\t",incomingStream[m]);
if(temp[n] != -1)
else
printf(" - \t\t\t");
return 0;
64
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
65
Ex No : 12B PAGE REPLACEMENT ALGORITHMS- LRU
Date :
PROGRAM:
#include<stdio.h>
int main()
int m, n, position, k, l;
int a = 0, b = 0, page_fault = 0;
int total_frames = 3;
int frames[total_frames];
int temp[total_frames];
frames[m] = -1;
a = 0, b = 0;
if(frames[m] == pages[n])
a = 1;
b = 1;
break;
66
}
if(a == 0)
{
if(frames[m] == -1)
frames[m] = pages[n];
b = 1;
page_fault++;
break;
if(b == 0)
temp[m] = 0;
if(frames[m] == pages[k])
{
temp[m] = 1;
67
}
if(temp[m] == 0)
position = m;
frames[position] = pages[n];
page_fault++;
printf("%d\t", frames[m]);
printf("\n");
return 0;
68
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
69
Ex No : 12C PAGE REPLACEMENT ALGORITHMS- LFU
Date :
PROGRAM:
#include<stdio.h>
int main()
int f,p;
int pages[50],frame[10],hit=0,count[50],time[50];int
i,j,page,flag,least,minTime,temp; printf("Enter no
of frames : ");
scanf("%d",&f);
scanf("%d",&p);
for(i=0;i<f;i++)
frame[i]=-1;
for(i=0;i<50;i++)
count[i]=0;
for(i=0;i<p;i++)
scanf("%d",&pages[i]);
printf("\n");
for(i=0;i<p;i++)
70
{
count[pages[i]]++;time[pages[i]]=i; flag=1; least=frame[0]; for(j=0;j<f;j++)
{
if(frame[j]==-1 || frame[j]==pages[i])
{
if(frame[j]!=-1)
hit++;
flag=0;
frame[j]=pages[i];
break;
if(count[least]>count[frame[j]])
least=frame[j]; }}
if(flag) {
minTime=50;
for(j=0;j<f;j++) {
temp=j;
minTime=time[frame[j]];
}}
count[frame[temp]]=0;
frame[temp]=pages[i];
for(j=0;j<f;j++)
printf("%d ",frame[j]);
71
}
printf("\n");}
return 0;
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
72
Ex No : 13A FILE ORGANIZATION TECHNIQUE -SINGLE
LEVEL DIRECTORY
Date :
PROGRAM:
import os
def create_file(filename):
if not os.path.exists(filename):
def main():
not os.path.exists(directory):
os.makedirs(directory)
os.chdir(directory)
while True:
command == "create":
create_file(filename)
print(os.listdir())
break
else:
print("Invalid command.")
main()
73
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
74
Ex No : 13B FILE ORGANIZATION TECHNIQUE- TWO LEVEL
DIRECTORY
Date :
PROGRAM:
import os
top_level_dir = "Projects"
if not os.path.exists(top_level_dir):
os.mkdir(top_level_dir)
subdir in subdirs:
not os.path.exists(subdir_path):
os.mkdir(subdir_path)
i, subdir in enumerate(subdirs):
file in files:
75
file_path = os.path.join(subdir_path, file)with
open(file_path, "w") as f:
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
76
Ex No : 14A FILE ALLOCATION STRATEGIES- SEQUENTIAL
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
for(i=0;i<50;i++)
f[i]=0;
x: count=0;
scanf("%d%d", &st,&len);
for(k=st;k<(st+len);k++)
if(f[k]==0)
count++;
if(len==count)
for(j=st;j<(st+len);j++)
if(f[j]==0)
f[j]=1;
printf("%d\t%d\n",j,f[j]);
if(j!=(st+len-1))
77
printf("The file is allocated to disk\n");
else
scanf("%d", &c);
if(c==1)
goto x;
else
exit;
getch();
78
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
79
Ex No : 14B FILE ALLOCATION STRATEGIES- LINKED
Date :
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
for(i=0;i<50;i++)
f[i]=0;
scanf("%d",&p);
for(i=0;i<p;i++)
scanf("%d",&a);
f[a]=1;
scanf("%d%d", &st,&len);
k=len;
if(f[st]==0
for(j=st;j<(st+k);j++)
80
if(f[j]==0)
{
f[j]=1;
else
k++;
else
if(c==1
)goto x;
else
exit(0);
getch();
81
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
82
Ex No : 14C FILE ALLOCATION STRATEGIES- INDEXED
Date :
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
f[i]=0;
scanf("%d",&ind);
if(f[ind]!=1)
printf("Enter no of blocks needed and no of files for the index %d on the disk : \n", ind);scanf("%d",&n);
else
x;
y: count=0;
for(i=0;i<n;i++
scanf("%d", &index[i]);
83
if(f[index[i]]==0)
count++;
if(count==n)
for(j=0;j<n;j++)
f[index[j]]=1;
printf("Allocated\n");
printf("File Indexed\n");
for(k=0;k<n;k++)
else
goto y;
scanf("%d", &c);
if(c==1
)goto x;
else
exit(0);
getch();}
84
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
85
Ex No : 15A PROGRAM- FCFS SCHEDULING
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,n,TotalHeadMoment=0,initial;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
for(i=0;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
86
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
87
Ex No : 15B PROGRAM- SSTF SCHEDULING
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
int min=1000,d,index;
for(i=0;i<n;i++)
d=abs(RQ[i]-initial);
if(min>d)
min=d;
index=i;
88
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
RQ[index]=1000;
count++;
return 0;
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
89
Ex No : 15C PROGRAM –SCAN SCHEDULING
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(j=0;j<n-i-1;j++)
if(RQ[j]>RQ[j+1
])
90
int temp;
temp=RQ[j];
RQ[j]=RQ[j+1
];
RQ[j+1]=temp;
int index;
for(i=0;i<n;i++
if(initial<RQ[i])
index=i;
break;
if(move==1)
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
91
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1); initial
= size-1;
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
initial =0;
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
92
printf("Total head movement is %d",TotalHeadMoment);
return 0;
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
93
Ex No : 15D PROGRAM –LOOK SCHEDULING
Date :
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
int main()
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
scanf("%d",&initial);
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(j=0;j<n-i-1;j++)
if(RQ[j]>RQ[j+1
])
94
int temp;
temp=RQ[j];
RQ[j]=RQ[j+1
];
RQ[j+1]=temp;
int index;
for(i=0;i<n;i++
if(initial<RQ[i])
index=i;
break;
if(move==1)
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for(i=index-1;i>=0;i--)
95
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
else
for(i=index-1;i>=0;i--)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
for(i=index;i<n;i++)
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
return 0;
96
OUTPUT
RESULT
Thus the above program has been verified and executed successfully.
97
Ex No : 16
INSTALLATION OF GUEST OPERATING SYSTEM LIKE LINUX USING VMWARE
Date :
AIM
To install the Guest OS like linux using VMware workstation.
PROCEDURE
What is a guest operating system (guest OS)?
A guest operating system is the operating system installed on either a virtual machine (VM) or
partitioned disk. It is usually different from the host operating system. Simply put, a host OS runs on
hardware, while a guest OS runs on a VM.
1. Save the ISO image file in any location accessible to your host. For
Note: For best performance, place this image on the host computer's hard drive. However, to make the
ISO image accessible to multiple users, you can also place the ISO image on a networkshare drive
(Windows) or exported filesystem (Linux). If your OS install spans multiple discs, youneed to use an
ISO image of each disc and place them all of them in a location accessible to the host.
2. Create a new virtual machine. Go to File > New > Virtual Machine.
98
4. On the Guest Operating System Installation screen, when prompted where to install
from,select Installer disc image file (iso).
5. Click Browse, and navigate to the location where you saved the ISO image file.
6. Click Next, and proceed through the new virtual machine wizard.
7. Before you click Finish, to create the virtual machine, deselect Power on this virtual
machineafter creation.
8. Edit the virtual machine settings so that its virtual CD/DVD device is configured to
use theISO image rather than the physical CD/DVD drive:
i.Select the tab for the virtual machine you just created.
image file.
c.Click Browse and navigate to where you saved the ISO image file.
v. Click OK.
The virtual machine boots from the ISO image, which contains the installation software for your
guest OS. Follow the installation procedure for your guest OS.
Note: If the guest OS asks for the second CD/DVD, repeat step 8 to point the virtual CD/DVD
device to the second ISO image.
When you are finished installing the guest OS, you can edit the virtual machine settings so that it
is once more set to use the host computer's physical drive. You do not need to leave the drive set
to connect at power on.
RESULT
Thus the guest OS like Linux using VMware workstation was successfully installed.
99
100