0% found this document useful (0 votes)
7 views103 pages

OS Lab Manual

This document provides a comprehensive guide on installing the Windows operating system, including steps for creating installation media, verifying product keys, and executing UNIX commands. It also includes programming examples for shell scripting, process management using system calls, and CPU scheduling algorithms like Round Robin and Shortest Job First. The document serves as a laboratory manual for students in the Information Technology department.

Uploaded by

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

OS Lab Manual

This document provides a comprehensive guide on installing the Windows operating system, including steps for creating installation media, verifying product keys, and executing UNIX commands. It also includes programming examples for shell scripting, process management using system calls, and CPU scheduling algorithms like Round Robin and Shortest Job First. The document serves as a laboratory manual for students in the Information Technology department.

Uploaded by

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

A.C.

S Nagar(Irumbedu), Arni,
T.V.Malai Dt.-632 317.

Department
Of
Information Technology
CS3461-Operating System Laboratory
1.INSTALLATION OF WINDOWS OPERATING SYSTEM

Step 1: Creating an Installation Disc or Drive

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.

Step 2: Make sure you have a product key.


If you bought Windows 10 through Microsoft using your Microsoft
account, your product key is already linked to your account. If you
bought Windows 10 from another retailer, you'll have a 25-character
product key that you'll need to have handy to activate Windows.
 If you don't have a product key or you're installing Windows
10 on a new hard drive, make sure you've linked your
Windows 10 digital license to your Microsoft account
before you start the installation. Head to Settings > Update
& Security > Activation from the current installation—if
the activation status says Windows is activated with a
digital license, click Add an account and follow the on-
screen instructions to link your Microsoft account.
 If you're upgrading from an earlier version and your PC
qualifies for a free upgrade, you won't need a product key.

Step 3: Go to https://www.microsoft.com/en-us/software-
download/windows10%20.
This is official download website for Windows 10

Step 4: Click Download tool now.


This is a blue button in the middle of the page. This downloads the Media
Creation Tool, which you'll use to create your installation media (or start
your upgrade).

Step 5: Double-click the downloaded file.


Its name begins with "MediaCreationTool" and ends with ".exe." You'll
find it in your default download folder, which is usually called
Downloads.
 Click Yes when prompted to allow the installer to run.
Step 6: Click Accept to accept the license.

It's in the bottom-right corner of the window.

Step 7: Select "Create installation media" and click OK.


This option lets you create a Windows installation disc or drive that will
work on any compatible PC, not just the one you're using now.
 If you're updating your PC from an earlier version of
Windows, select Upgrade this PC now instead, and then
follow the on-screen instructions to install Windows 10.
You're done!
Step 8: Select your preferences and click Next.
If you're installing Windows on the current PC, you can keep the default
options. If you need to install on a different PC, make sure you choose the
language and edition for which you have a license, and select the
architecture (64-bit or 32-bit) that matches the PC you're going to install
on.
 If you're not sure about the architecture, you can
choose Both from the menu.

Step 9: Choose an installation type and click Next.


An ISO file is a type of file that can be burned to a DVD, so choose that
option if you plan to create a DVD. Otherwise, choose the USB flash
drive option.

Step 10: Create your installation media.


The steps are a little different depending on what you're doing:
 Flash drive: Select your flash drive from the list, click Next,
and wait for the installation files to install. When the
process is complete, click Finish.
 DVD/ISO: Click Save to save the ISO file to your
computer—it may take a while because the file is large and
has to be downloaded. Once downloaded, you'll see a
progress screen that monitors the download. When the
download is complete, click Open DVD burner on the
"Burn the ISO file to a DVD" screen, select your DVD
burner, and then click Burn to create your DVD.
2. UNIX COMMANDS
Aim

To study and execute Unix commands.

Login

Type telnet server_ipaddress in run window. User has to authenticate


himself by providing username and password. Once verified, a greeting
and $ prompt appears.

General commands Command Function Date Used to display the current


system date and time. date

+%D Displays date only date

+%T Displays time only date

+% Y Displays the year part of date date

+% H Displays the hour

part of time Cal Calendar of the current month cal year Displays calendar
for all months of

The commands can be combined using the pipeline (|) operator. For
example, number of users logged in can be obtained as. who | wc -l

Finally to terminate the unix session execute the command exit or logout.
Output

$ date Sat Apr 9 13:03:47 IST 2011

$ date +%D 04/09/11

$ date +%T 13:05:33

$ date +%Y 2011

$ date +%H 13

$ cal 08 1998 August 1998 Su Mo Tu We Th Fr Sa 12 3 4


5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
30 31

$ who root :0 Apr 9 08:41 vijai pts/0 Apr 9 13:00 (scl-64)


cse4001 pts/3 Apr 9 13:18 (scl-41.smkfomra.com)

$ uname Linux

$ uname -r 2.4.20-8smp

$ uname -n localhost.localdomain

$ echo $HOME /home/vijai

$ echo $USER vijai

$ bc 3+5 8

$ pwd /home/vijai/shellscripts/loops

$ mkdir filter $ ls filter list.sh regexpr shellscripts

$ cd shellscripts/loops/ $

$ cd $

$ cd / [vijai@localhost /]$

[vijai@localhost /]$ cd /home/vijai/shellscripts/loops/ $ cd ..


[vijai@localhost shellscripts]$

$ rmdir filter $ ls list.sh regexpr shellscripts


$ cat > greet hi cse wishing u the best

$ cat greet hi ece-a wishing u the best

$ cat >> greet bye $ cat greet hi cse wishing u the best bye

$ ls greet list.sh regexpr shellscripts

$ ls -a . .bash_logout .canna .gtkrc


regexpr .viminfo.tmp .. .bash_profile .emacs .kde
shellscripts .xemacs .bash_history .bashrc greet list.sh .viminfo

$ ls -l -rw-rw-r-- 1 vijai vijai 32 Apr 11 14:52 greet -rw-rw-r--


1 vijai vijai 30 Apr 4 13:58 list.sh drwxrwxr-x 2 vijai vijai
4096 Apr 9 14:30 regexpr

$ cp greet ./regexpr/ $ ls greet list.sh regexpr shellscripts $ ls ./regexpr


demo greet

$ cp -i greet ./regexpr/ cp: overwrite 'greet'? n

$ mv greet greet.txt $ ls greet.txt list.sh regexpr shellscripts

$ mv greet.txt ./regexpr/ $ ls list.sh regexpr shellscripts

$ rm -i *.sh rm: remove regular file 'fact.sh'? y rm: remove regular file
'prime.sh'? y $ ls list.sh regexpr shellscripts

$ wc list.sh 4 9 30 list.sh $ wc -l list.sh 4 list.sh

$ cmp list.sh fact.sh list.sh fact.sh differ: byte 1, line 1

$ ls -l list.sh -rw-rw-r-- 1 vijai vijai 30 Apr 4 13:58 list.sh

$ chmod ug+x list.sh

$ ls -l list.sh -rwxrwxr-- 1 vijai vijai 30 Apr 4 13:58 list.sh


$ chmod 740 list.sh $ ls -l list.sh -rwxr----- 1 vijai vijai 30 Apr
4 13:58 list.sh
2.SHELL PROGRAMING

2.A. EVEN OR ODD

PROGRAM:
echo "enter the number"
read num
echo "enter the number”

read num
if [ `expr $num % 2` -eq 0 ]
then
echo "number is even"
else
echo "number is odd"
fi

OUTPUT:

enter the number: 5


the number is odd.
2.B. BIGGEST OF TWO NUMBERS

PROGRAM:
echo "enter the number"
read a b
if [ $a -gt $b ]
then
echo "A is big"
else
echo "B is big"
fi

OUTPUT:

Enter The Two Number:


23 67
B is Big.
2.C. BIGGEST OF THREE NUMBERS

PROGRAM:
echo "enter three numbers"
read a b c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "A is big"
else if [ $b -gt $c ]
then
echo "B is big"
else
echo "C is big"
fi

OUTPUT:

ENTER THREE NUMBERS:


23 54 78
C IS BIG.
2.D. FACTORIAL OF NUMBER
PROGRAM:
echo "enter the number"
read n
fact=1
i=1
while [ $i -le $n ]
do
fact=`expr $i \* $fact`
i=`expr $i + 1`
done
echo "the fcatorial number of $ni is $fact

OUTPUT:
Enter the number :
4
The factorial of 4 is 24.
2.E. FIBONACCI SERIES

PROGRAM:
echo " ENTER THE LIMIT FOR FIBONNACI SERIES"
read lim
n1=0
n2=1
var=0
echo "FIBONACCI SERIES IS "
echo "$n1"
echo "$n2"
while [ $var -lt `expr $lim - 2` ]
do
n3=`expr $n1 + $n2 `
n1=`expr $n2 `
n2=`expr $n3 `
var=`expr $var + 1 `
echo "$n2"
done

OUTPUT :

enter the limit for Fibonacci:


5
The Fibonacci series is:
0
1
1
2
3
3.PROCESS MANAGEMENT USING SYSTEM CALLS
FORK AND GETPID
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
void main(int argc,char *arg[])
{
int pid;
pid=fork();
if(pid<0)
{
printf("fork failed");
exit(1);
}
else if(pid==0)
{
execlp("who am i","ls",NULL);
exit(0);
}
Else
{
printf("\n Process id is -%d\n",getpid());
wait(NULL);
exit(0);
}
}

OUTPUT:
cse6@localhost Pgm]$ cc prog4a.c [cse6@localhost Pgm]$ ./a.out
4.A. CPU SCHEDULING: ROUND ROBIN SCHEDULING

PROGRAM:
#include<studio.h>
void main()

int i,tbt=0,nop,ts=0,flag[20],
rem[20];
int from,wt[20],tt[20],b[20],
twt=0,ttt=0;
int dur;
float awt,att;

printf("Enter no. of
Processes: ");
scanf("%d",&nop);

printf("Enter the time


slice: ");
scanf("%d",&ts);

printf("Enter the Burst


times..\n");
for(i=0;i<nop;i++)

wt[i]=tt[i]=0; printf("P%d\t: ",i+1);


scanf("%d",&b[i]); rem[i]=b[i];
tbt+=b[i];

flag[i]=0;
}
from=0;
i=0;
printf("\n\t Gantt Chart");

printf("\n ProcessID\tFrom Time\tTo Time\n");


while(from<tbt)

{
if(!flag[i])
{
if(rem[i]<=ts)
{
dur=rem[i];
flag[i]=1;

tt[i]=dur+from; wt[i]=tt[i]-b[i];
}

else dur=ts;

printf("%7d%15d%15d\n",i+1, from,from+dur); rem[i] -=


dur;

from += dur;
}
i=(i+1)%nop;
}
for(i=0;i<nop;i++)
{
twt+=wt[i];
ttt+=tt[i];
}

printf("\n\n Process ID \t Waiting Time \t Turn Around Time");


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

{
printf("\n\t%d\t\t%d\t\t%d",i+1,wt[i],tt[i]);
}
awt=(float)twt/(float)nop;
att=(float)ttt/(float)nop;

printf("\nTotal Waiting Time:%d",twt);


printf("\nTotal Turn Around Time:%d",ttt);
printf("\nAverage Waiting Time:%.2f",awt);
printf("\nAverage Turn Around Time:%.2f\n",att);

}
OUTPUT:
Enter no. of Processes: 3
Enter the time
slice: 3
Enter the Burst times.. P1 : 24
P2 : 5
P3 : 3

Gantt Chart
ProcessID From Time To Time
1 0 3
2 3 6
3 6 9
1 9 12
2 12 14
1 14 17
1 17 20
1 20 23
1 23 26
1 26 29
1 29 32

Turn Around
Process ID Waiting Time Time
1 8 32
2 9 14
3 6 9
Total Waiting Time:23
Total Turn Around
Time:55
Average Waiting
Time:7.67

Average Turn Around Time:18.33


4. B. SHORTEST JOB FIRST

PROGRAM :

#include<stdio.h>

int main()

int n,w[100],tot[100],i,j,awt,atot; float avwt,avtot;

struct

int p,bt;

}sjf[10],temp;

printf("Enter the number of Processes:");

scanf("%d",&n); for(i=1;i<=n;i++)

printf("Enter the Burst time for Process%d : ",i);

scanf("%d",&sjf[i].bt);

sjf[i].p=i;

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

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

if(sjf[j].bt>sjf[i].bt)

temp=sjf[i];

sjf[i]=sjf[j];
sjf[j]=temp;

w[1]=0;

tot[1]=sjf[1].bt;

for(i=2;i<=n;i++) tot[i]=tot[i-1]+sjf[i].bt; awt=0;

atot=0;

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

w[i]=tot[i]-sjf[i].bt; awt+=w[i];

atot+=tot[i];

avwt=(float)awt/n;

avtot=(float)atot/n;

printf("\n\nProcessId\tWaiting time\t TurnaroundTime");

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

printf("\n\t%d\t\t%d\t\t%d",sjf[i].p,w[i],tot[i]);

printf("\n\nTotal Waiting Time :%d",awt);

printf("\n\nTotal Turnaround Time :%d",atot);

printf("\n\nAverage Waiting Time :%.2f",avwt);

printf("\n\nAverage Turnaround Time :%.2f",avtot);

}
OUTPUT:

[cse6@localhost Pgm]$ cc prog9b.c

[cse6@localhost Pgm]$ ./a.out

Enter the number of Processes:3

Enter the Burst time for Process1 : 24

Enter the Burst time for Process2 : 5

Enter the Burst time for Process3 : 3

ProcessId Waiting time TurnaroundTime

3 0 3

2 3 8

1 8 32

Total Waiting Time :11

Total Turnaround Time :43

Average Waiting Time :3.67

Average Turnaround Time :14.33 [cse6@localhost Pgm]$


4.C. CPU SCHEDULING: FIRST COME FIRST SERVE

PROGRAM

#include<stdio.h>
int main()
{
int n,b[10],t=0,i,w=0,r=0,a=0; float avg,avg1;
printf("\nEnter number of processes:");
scanf("%d",&n);
printf("\nEnter the burst times : \n");
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("\n Gantt chart ");
for(i=1;i<=n;i++)
printf("P%d\t",i);
printf("\n\nProcess BurstTime WaitingTime TurnaroundTime\n");
for(i=1;i<=n;i++)
{
t=t+w;
r=r+b[i];
printf("P%d\t\t%d\t\t%d\t\t%d\t\t\n",i,b[i],w,r);
w=w+b[i];
a=a+r;
}
avg=(float)t/n;
avg1=(float)a/n;
printf("\n Average WaitingTime is %f",avg);
printf("\n Average TurnaroundTime is %f\n",avg1);
return(0);
}
OUTPUT:

[cse6@localhost Pgm]$ cc prog9a.c -o prog9a.out [cse6@localhost


Pgm]$ ./prog9a.out

Enter number of processes : 3


Enter the burst times :
24
5
3

Gantt chart P1 P2 P3
Process BurstTime WaitingTime TurnaroundTime
P1 24 0 24
P2 5 24 29
P3 3 29 32

Average WaitingTime is 17.666666


Average TurnaroundTime is 28.333334 [cse6@localhost Pgm]$
4.D. PRIORITY SCHEDULING

PROGRAM :

#include<stdio.h>
int main()
{
int n,temp=0,w[20],b[20], p[20], t2[20],j,t1,d[20],i, te=0,b1[20],t3=0;
float t,r; w[1]=0;
printf("\nEnter no. of processes:");
scanf("%d",&n);
printf("\nEnter the burst times : ");
for(i=1;i<=n;i++)
{
printf("P%d : ",i);
scanf("%d",&b[i]);
d[i]=i;
}
printf("Enter the priorities:");
for(i=1;i<=n;i++)
{
printf("P%d : ",i);
scanf("%d",&p[i]);
}
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(p[i]<p[j])
{
temp=p[i];
t1=d[i];
te=b[i];
p[i]=p[j];
d[i]=d[j];
b[i]=b[j];
p[j]=temp;
d[j]=t1;
b[j]=te;
}
printf("\nGantt Chart : "); for(i=1;i<=n;i++) printf("P%d\t",d[i]);
printf("\nProcess \t Priority\tBurst Time\t Waiting Time\t Turnaround
Time");
for(i=1;i<=n;i++)
{
t=d[i];
w[i+1]=w[i]+b[i];
t2[i]=b[i]+w[i];
t3+=t2[i];
printf("\nP%d\t\t%d\t\t%d\t\t%d\t\t%d",d[i],p[i],b[i],w[i],t2[i]);
}
temp=0;
for(i=1;i<=n;i++)
temp+=w[i];
t=(float)temp/n;
r=(float)t3/n;
printf("\nAverage Waiting time : %.2f",t); printf("\nAverage Turnaround
time : %.2f",r);
}
OUTPUT:

[cse6@localhost Pgm]$ cc prog10a.c [cse6@localhost Pgm]$ ./a.out

Enter the no. of processes : 3


Enter the burst times
P1 : 24
P2 : 5
P3 : 3

Enter the priorities

P1 : 2
P2 : 1
P3 : 3
Gantt Chart : P2 P1P3
ProcessID Priority BurstTime WaitingTime TurnaroundTime
P2 1 5 0 5
P1 2 24 5 29
P3 3 3 29 32

Average Waiting Time : 11.33

Average Turnaround Time : 22.00

[cse6@localhost Pgm]$
5.IMPLEMENTATION OF INTER PROCESS COMMUNICATION
PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<string.h>
main()
{
int p1[2],p2[2],p3[2],p4[2];
int i,j=0,k=0,l=0;
char r[10],s[10],t[10],u[10];
printf("\t PROCESS 1.ENTER THE STRING");
scanf("%s",r);
pipe(p1);
pipe(p2);
write(p1[1],r,sizeof(r));
write(p2[1],r,sizeof(r));
int a=fork();
if(a==0)
{
printf("\n\t PROCESS 2:it splits the given string\n");
read(p1[0],r,sizeof(r));
int n=strlen(r);
for(i=0;i<n/2;i++)
{
s[i]=r[i];
}
for(i=n/2;i<=n;i++)
{
t[j++]=r[i];
}
pipe(p3);
pipe(p4);
write(p3[1],s,sizeof(s));
write(p4[1],t,sizeof(t));
int b=fork();
if(b==0)
{
printf("p4 %d\t",getpid());
printf("p2 %d\n",getppid());
read(p3[0],s,sizeof(s));
printf("\t PROCESS 4:sub string \t %s \t",s);
printf("no of char=%d \n",strlen(s));
}
else
{
int c=fork();
if(c==0) {
printf("p5 %d\t",getpid());
printf("p2 %d\n",getppid());
read(p4[0],t,sizeof(t));
printf("\t PROCESS 5:sub string \t %s \t",t);
printf("no of char=%d \n",strlen(t));
}
else
{
wait();
printf("p2 %d\t",getpid());
printf("p1 %d\n",getppid());
}
}
}
else
{
wait();
int d=fork();
if(d==0)
{
printf("p3 %d\t",getpid());
printf("p1 %d\n",getppid());
read(p2[0],r,sizeof(r));
for(i=strlen(r)-1;i>=0;i--)
{
u[l++]=r[i];
}
for(i=0;i<strlen(r);i++)
{
if(u[i]==r[i])
k++;
else
continue;
}
if(k==strlen(r))
printf("\t PROCESS 3: the given string is palindrome\n");
else
printf("\t PROCESS 3: the given string is not palindrome\n");
}
else
{
printf("p1 %d\t",getpid());
printf("kernal %d\t\n",getppid());
}
}
}

OUTPUT:
Process 1: enter the string ARUN
Process 2: it splits the string
P4 8137 p2 8136
Process 3: sub string a r no of char=2
P5 8138 p2 8136
Process 4; substring u n no of char=2
P2 8136 p1 8132
P3 8139 p1 8132
Process 3: the given string is not palindrome
Process 1: enter the string MADAM
Process 2: it splits the string
P4 8137 p2 8136
Process 4: sub string m a no of char=2
P5 8138 p2 8136
Process 5: sub string dam no of char=3
P2 8136 p1 8132
P3 8139 p1 8132
Process 3: the given string is palindrome
6. IMPLEMENT MUTUAL EXCLUSION BY SEMAPHORE

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

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

}
OUTPUT:

[cse6@localhost Pgm]$ cc ex11.c -o ex11.out [cse6@localhost


Pgm]$ ./ex11.out

Produced element a

Consumed element a

Produced element b

Consumed element b

Produced element c

Consumed element c

Produced element d

Consumed element d

Produced element e

Consumed element e

Produced element f

Consumed element f

Produced element g

Consumed element g

Produced element h

Consumed element h
7.IMPLEMENTATION BANKERS ALGORITHM FOR DEAD
LOCK AVOIDANCE

PROGRAM:

#include<stdio.h>

Void main()

int n,i,j,c,p[20],av[20],max[20][20],all[20][20],all1[20][20],

int need[20][20];

printf(“\n Enter the number of process:”);

scanf(“%d”,&n);

printf(“\n Enter the process nos:”);

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

scanf(“%d”,&p[i]);

printf(“\n Enter the instances “);

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

scanf(“%d”,&av[i]);

printf(“\n Enter max of each :”);

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

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

{
scanf(“%d”,&max[i][j]);

printf(“\n”);

Printf(“\n Enter the allocation of each:”);

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

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

scanf(“%d”,&alli][j]);

printf(“\n”);

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

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

all1[i][j]=all[i][j];

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

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

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

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

c=0;

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

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

av[i]=av[i]-c;

printf(“\n NEED MATRIX”);

printf(“\n A \t B \t C \n”);

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

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

printf(“%d \t”need[i][j]);

printf(“\n”);

Printf(“\n AVAILABLE”);

for(i=0;<3;i++)
{

printf(“%d\t”av[j]);

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

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

if(need[i][j]<=av[j])

all[i][j]=all1[i][j]+need[i][j];

av[j]=all1[i][j]+av[j];

else

printf(“\n Process not allowed”);

exit(0);

printf(“\n***SUCCESS***);

printf(“\n***ALLOCATED MATRIX***);

printf(“\n A \t B \t C \n);

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

{
for(j=0;j<3;j++)

Printf(“%d \t”,all[i][j]);

printf(“\n”);

printf(“\n INSTANCE AT LAST”);

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

Printf(“\n %d”,av[j]);

Output:

Enter the no of process: 5

Enter the process : p1 p1 p3 p4 p5

Enter the allocation: 010 200 302 211 002

Enter the max : 753 322 902 222 433

Enter available : 332

Safe Sequence :

p2 p4 p5 p1 p3

Need matrix :
743

122

600

011

431
8. IMPLEMENTATION OF DEADLOCK DETECTION ALGORITHM

PROGRAM:

#include <stdio.h>

#include <conio.h>

void main()

int found,flag,l,p[4][5],tp,tr,c[4][5],i,j,k=1,m[5],r[5],a[5],temp[5],sum=0;

clrscr();

printf("Enter total no of processes");

scanf("%d",&tp);

printf("Enter total no of resources");

scanf("%d",&tr);

printf("Enter claim (Max. Need) matrix\n");

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

printf("process %d:\n",i);

for(j=1;j<=tr;j++)

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

printf("Enter allocation matrix\n");

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

printf("process %d:\n",i);

for(j=1;j<=tr;j++)
scanf("%d",&p[i][j]);

printf("Enter resource vector (Total resources):\n");

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

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

printf("Enter availability vector (available resources):\n");

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

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

temp[i]=a[i];

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

sum=0;

for(j=1;j<=tr;j++)

sum+=p[i][j];

if(sum==0)

m[k]=i;

k++;
}

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

for(l=1;l<k;l++)

if(i!=m[l])

flag=1;

for(j=1;j<=tr;j++)

if(c[i][j]<temp[j])

flag=0;

break;

if(flag==1)

m[k]=i;

k++;

for(j=1;j<=tr;j++)

temp[j]+=p[i][j];

printf("deadlock causing processes are:");


for(j=1;j<=tp;j++)

found=0;

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

if(j==m[i])

found=1;

if(found==0)

printf("%d\t",j);

getch();

OUTPUT:

Enter total no. of processes : 4

Enter total no. of resources : 5

Enter claim (Max. Need) matrix : 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1

Enter allocation matrix : 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0

Enter resource vector (Total resources) : 2 1 1 2 1

Enter availability vector (available resources) : 0 0 0 0 1

deadlock causing processes are : 2 3


9.IMPLEMENTATION OF THREADING
PROGRAM :
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
#include<stdio.h>
int counter;
void* doSomeThing(void *arg)
{
unsigned long i = 0;
counter += 1;
printf("\n Job %d started\n", counter);
for(i=0; i<(0xFFFFFFFF);i++);
printf("\n Job %d finished\n", counter);
return NULL;
}
int main(void)
{
int i = 0;
int err;
while(i < 2)
{
err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
i++;
}
pthread_join(tid[0], NULL);
pthread_join(tid[1], NULL);
return 0;
}

OUT PUT:
Job 1 started
Job 2 started
Job 2 finished
Job 2 finished
10. PAGING TECHNIQUE OF MEMORY MANAGEMENT

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;

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();

OUTPUT:

memory management using paging

enter the size of physical address:16

enter the size of logical memory:8

enter the partition:2

the physical memory is divided into 8 no.of frames

the logical memory is divided into 4 no.of pages

enter the frame number where page 0 must be placed:5

enter the frame number where page 1 must be placed:6

enter the frame number where page 2 must be placed:7

enter the frame number where page 3 must be placed:2

PAGE TABLE
page address frame no .presentBit

0 5 1

1 6 1

2 7 1

3 2 1

FRAME TABLE

FRAME ADDRESS PAGE NO

0 32555

1 32555

2 3

3 32555

4 32555

5 0

6 1

7 2

process to create the physical address

Enter the base address:1000

Enter the logic address:3

The physical address where the instruction present:1013


11. IMPLEMENTATION OF THE FOLLOWING MEMORY
ALLOCATION METHODS FOR FIXED PARTITION

(A) FIRST FIT:

PROGRAM:

#include<stdio.h>

struct process

int ps;

int flag;

} p[50];

struct sizes

int size;

int alloc;

s[5];

int main()

int i=0,np=0,n=0,j=0;

printf("\n first fit");

printf("\n");

printf("enter the number of blocks \t");

scanf("%d",&n);

printf("\t\t\n enter the size for %d blocks\n",n);

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

printf("enter the size for %d block \t",i);

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

printf("\n\t\t enter the number of process\t",i);

scanf("%d",&np);

printf("enter the size of %d processors !\t",np);

printf("/n");

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

printf("enter the size of process %d\t",i);

scanf("\n%d",&p[i].ps);

printf("\n\t\t Allocation of blocks using first fit is as follows\n");

printf("\n\t\t process \t process size\t blocks\n");

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

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

if(p[i].flag!=1)

if(p[i].flag!=1)

if(p[i].ps<=s[j].size)
{

if(!s[j].alloc)

p[i].flag=1;

s[j].alloc=1;

printf("\n\t\t %d\t\t\t%d\t%d\t",i,p[i].ps,s[j].size);

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

if(p[i].flag!=1)

printf("sorry !!!!!!!process %d must wait as there is no sufficient


memory");

}
OUTPUT:

first fit

enter the number of blocks 4

enter the size for 4 blocks

enter the size for 0 block 3

enter the size for 1 block 2

enter the size for 2 block 5

enter the size for 3 block 10

enter the number of process 4

enter the size of 4 processors !

enter the size of process 0 2

enter the size of process 1 6

enter the size of process 2 7

enter the size of process 3 9

Allocation of blocks using first fit is as follows

process process size blocks

023

1 6 10
(B) BESTFIT:

PROGRAM:

#include<stdio.h>

#define MAX 20

int main()

int bsize[MAX],fsize[MAX],nb,nf;

int temp,low=10000;

static int bflag[MAX],fflag[MAX];

int i,j;

printf("\n enter the number of blocks");

scanf("%d",&nb);

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

printf("Enter the size of memory block % d",i);

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

printf("\n enter the number of files");

scanf("%d",&nf);

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

{
printf("\n enetr the size of file %d",i);

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

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

for(j=1;j<=nb;j++)

if(bflag[j]!=1)

temp=bsize[j]-fsize[i];

if(temp>=0)

if(low>temp)

fflag[i]=j;

low=temp;

bflag[fflag[i]]=1;

low=10000;

printf("\n file no \t file.size\t block no \t block size");


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

printf("\n \n %d \t\t%d\t\t%d\t\t%d",i,fsize[i],fflag[i],bsize[fflag[i]]);

OUTPUT:

Enter the number of blocks5

Enter the size of memory block 1 10

Enter the size of memory block 2 12

Enter the size of memory block 3 10

Enter the size of memory block 4 5

Enter the size of memory block 5 7

enter the number of files 5

enetr the size of file 1 5

enetr the size of file 2 6

file no file.size block no block size

1545

2657

3 7 1 10

4 10 3 10

5 12 2 12
(C) . WORST FIT

PROGRAM:

#include<stdio.h>

#include<conio.h>

#define max 25

void main()

int frag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;

static int bf[max],ff[max];

clrscr();

printf("\n\tMemory Management Scheme - Worst Fit");

printf("\nEnter the number of blocks:");

scanf("%d",&nb);

printf("Enter the number of files:");

scanf("%d",&nf);

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) //if bf[j] is not allocated

temp=b[j]-f[i];

if(temp>=0)

if(highest<temp)

ff[i]=j;

highest=temp;

frag[i]=highest;

bf[ff[i]]=1;

highest=0;

printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");

for(i=1;i<=nf;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);

getch();

OUTPUT:

Memory Management Schema -Worst Fit

Enter the number of blocks:3

Enter the number of blocks:2

Enter the size of the blocks:-

Block 1:5

Block 2:2

Block 3:7

Enter the size of the files:-

File 1:1

File 2:4

File_no: File_size: Block_no: Block_size: Fragment:

1 1 3 7 6

2 4 1 5 1
12.A. PAGE REPLACEMENT ALGORITHMS – FIFO

PROGRAM

#include<stdio.h>

#include<conio.h>

int ssize,fsize,frame[10],rstring[30];

int main()

int i,cs=0,pf=0,y,k,z=0;

int found(int x);

void display();

clrscr();

printf("\n\t\t FIFO PAGE REPLACEMENT ALGORITHM\n");

printf("\t\t -------------------------------");

printf("\n\t Enter the size of frame:");

scanf("%d",&fsize);

printf("\n\t Enter the number of reference strings:");

scanf("%d",&ssize);

printf("\n\t Enter the strings:");

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

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

for(k=0;k<=fsize;k++)

frame[k]=-3;
for(i=0;i<ssize;i++)

y=found(rstring[i]);

if(y==0)

pf++;

if(cs>=fsize)

frame[z%fsize]=rstring[i];

z++;

else if(cs<fsize)

frame[z++]=rstring[i];

cs++;

display();

printf("\n\n\t\t Page fault:%d",pf);

getch();

int found(int x)

int i,val=0;

for(i=0;i<fsize;i++)
{

if(x==frame[i])

val=1;

break;

return(val);

void display()

int i;

printf("\n");

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

if(frame[i]>=0)

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

else

printf("\t");

}
OUTPUT:

Enter the frame size:3

Enter the reference string size:5

Enter the reference string :5

5 5 5 3

8 8 8

4 4

Page fault:4
12. B. PAGE REPLACEMENT ALGORITHMS - LRU

PROGRAM:

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

int fsize,ssize,f,frame[10],arrive[30],rstring[30];

int main()

int i,lfi,idx,cs=0,f,ls=0,pf=0,j=0,y,k,z=0,time=0;

int pagefound (int x);

void display();

int leastused();

int pagelocation(int x);

clrscr();

printf("\n\n\t\t LRU PAGE REPLACEMENT");

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

printf("\n\n\t Enter the frame size:");

scanf("%d",&fsize);

printf("\n\t Enter the reference string size:");

scanf("%d",&ssize);

printf("\n\t Enter the reference string:");

for(i=0;i<ssize;i++)
scanf("%d",&rstring[i]);

for(k=0;k<fsize;k++)

frame[k]=-3;

arrive[k]=0;

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

y=pagefound(rstring[i]);

if(y==0)

pf++;

if(cs>=fsize)

lfi=leastused();

frame [lfi]=rstring[i];

arrive [lfi]=++time;

else if (cs<fsize)

frame[cs]=rstring[i];

arrive [cs]=++time;

}
else

idx=pagelocation(rstring[i]);

arrive [idx]=++time;

cs++;

display();

printf("\n Page fault=%d",pf);

int pagefound(int x)

int i,val=0;

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

if(x==frame[i])

val=1;

break;

return(val);

void display()
{

int i;

printf("\n");

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

if(frame[i]>=0)

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

else

printf("\t");

int leastused()

int i,min=0,n=0;

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

if(arrive[i]<arrive[min])

min=i;

n++;

}
if(n==0)

return(0);

else

return(min);

int pagelocation(int pageno)

int i,flag=0;

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

if(frame[i]==pageno)

flag=1;

break;

return(i);

getch();

}
OUTPUT:

Enter the frame size:3

Enter the reference string size:7

Enter the reference string :1

1 1 1 1 1 5

2 2 4 4 4

3 3 3 3

Page fault:5
12.C. PAGE REPLACEMENT ALGORITHMS – LFU(optimal):

PROGRAM

#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\t\t\t OPTIMAL PAGE REPLACEMENT ALGORTHIM");

printf("\n.........................");

printf("\nEnter the no.of.frames");

scanf("%d",&nof);

printf("\n enter no.of reference string..");

scanf("%d",&nor);

printf("\n enter reference string..");

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

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

clrscr();

printf("\n OPTIMAL PAGE REPLACEMENT ALGORTHIM");

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;

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;

OUTPUT:

OPTIMAL PAGE REPLACEMENT ALGORITHM

...................................

Enter the no.of frames 3

Enter the no.of reference string 6

Enter the reference string 6


5

OPTIMAL PAGE REPLACEMENT ALGORTHIM

...................................

The given string

................

654214

ref no 6-> 6 -1 -1

ref no 5-> 6 5 -1

ref no 2-> 6 5 4

ref no 1-> 2 5 4

ref no 4-> 1 5 4

Number of page faults: 5


13.A. FILE ORGANIZATION TECHNIQUES - SINGLE
LEVEL DIRECTORY

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 directories:”);

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”);

OUTPUT:

Enter number of directories:2

Enter names of directories:cse it

Enter size of directories:3 4

Enter file names:aaa

bbb

ccc

ddd

eee

fff
ggg

Directory size filenames

cse 3 aaa

bbb

Ccc

it 4 ddd

eee

fff

ggg
13.B. FILE ORGANIZATION TECHNIQUES : TWO LEVEL
DIRECTORY

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\t\t");

}
OUTPUT:

enter number of directories:2

enter directory 1 names:cse

enter size of directories:2

enter subdirectory name and size:os 2

enter file name:aaa

enter file name:bbb

enter subdirectory name and size:cn 2

enter file name:xyz

enter file name:mih

enter subdirectory name and size:pqt 2

enter file name:anh

enter file name:kkk

enter subdirectory 2 names:ece

enter subdirectory name and size:ct 2

enter file name:aav

enter file name:vcs

enter subdirectory name and size:dc 2

enter file name:afs

enter file name:ged

dirname size subdirname size files

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

cse 3 os 2 aaa bbb


cn 2 xyz mih

pqt 2 anh kkk

ece 2 ct 2 aav vcs

dc 2 afs ged
14.A. FILE ALLOCATION TECHNIQUE-SEQUENTIAL
ALLOCATION

PROGRAM:

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

int st[20],b[20],b1[20],ch,i,j,n,blocks[20][20],sz[20];

char F[20][20],S[20];

clrscr();

printf("\n Enter no. of Files ::");

scanf("%d",&n);

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

printf("\n Enter file %d name ::",i+1);

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

printf("\n Enter file%d size(in kb)::",i+1);

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

printf("\n Enter Starting block of %d::",i+1);

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

printf("\n Enter blocksize of File%d(in bytes)::",i+1);

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

for(i=0;i<n;i++)
b1[i]=(sz[i]*1024)/b[i];

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

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

blocks[i][j]=st[i]+j;

do

printf("\nEnter the Filename ::");

scanf("%s",S);

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

if(strcmp(S,F[i])==0)

printf("\nFname\tStart\tNblocks\tBlocks\n");

printf("\n---------------------------------------------\n");

printf("\n%s\t%d\t%d\t",F[i],st[i],b1[i]);

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

printf("%d->",blocks[i][j]);

printf("\n---------------------------------------------\n");

printf("\nDo U want to continue ::(Y:n)");

scanf("%d",&ch);
if(ch!=1)

break;

}while(1);

OUTPUT:

Enter no. of Files ::2

Enter file 1 name ::x.c

Enter file1 size(in kb)::4

Enter Starting block of 1::100

Enter blocksize of File1(in bytes)::512

Enter file 2 name ::y.c

Enter file2 size(in kb)::2

Enter Starting block of 2::500

Enter blocksize of File2(in bytes)::256

Enter the Filename ::y.c

Fname Start Nblocks Blocks

---------------------------------------------

y.c 500 8 500->501->502->503->504->505->506->507->

---------------------------------------------

Do U want to continue ::(Y:n) n


14.B. FILE ALLOCATION TECHNIQUE-INDEXED ALLOCATION

PROGRAM:

#include<stdio.h>

void main()

char a[10];

int i,ib,cib[10];

printf("\n enter the file name:");

scanf("%s",a);

printf("\n index block:");

scanf("%d",&ib);

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

printf("\n enter the child of index block %d:",i);

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

printf("\n the list of files\t index block\n");

printf("%s\t\t %d",a,ib);

printf("\n the above file utiltization index block of child blocks


followin\t");

printf("\n");

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

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

}
printf("\n");

OUTPUT:

Enter the name:Testing

Index block:19

Enter the child of index block 1:9

Enter the child of index block 2:16

Enter the child of index block 3:1

Enter the child of index block 4:10

Enter the child of index block 5:25

The list of files index block

Testing 19

The above file utilization index block of child blocks following:

9 16 1 10 25
14.C. FILE ALLOCATION TECHNIQUE-LINKED ALLOCATION

PROGRAM :

#include<stdio.h>

void main()

char a[10];

int i,sb,eb,fb1[10];

printf("\n enter the file name:");

scanf("%s",a);

printf("\n Enter the starting block:");

scanf("%d",&sb);

printf("Enter the ending Block:");

scanf("%d",&eb);

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

printf("Enter the free block %d",i+1);

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

printf("\n File name \t Starting block \t Ending block \n");

printf("%s \t\t %d\t\t %d",a,sb,eb);

printf("\n %s File Utilization of Linked type of following blocks:",a);

printf("\n %d->",sb);

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

printf("%d->",fb1[i]);

printf("%d\n",eb);

}
OUTPUT:

Enter the filename:binary

Enter the starting block:19

Enter the ending block:25

Enter the free block:1:12

Enter the free block:2:34

Enter the free block:3:21

Enter the free block:4:18

Enter the free block:5:35

ending

File name starting block block

Binary 19 25

Binary file utilization of linked type of the following blocks: 19 12 34 21


18 35 25
15.IMPLEMENTATION OF VARIOUS DISK SCHEDULING

A) FCFS DISK SCHEDULING ALGORITHM

PROGRAM:

#include<stdio.h>

main()

int t[20], n, I, j, tohm[20], tot=0; float avhm;

clrscr();

printf(“enter the no.of tracks”);

scanf(“%d”,&n);

printf(“enter the tracks to be traversed”);

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

scanf(“%d”,&t*i+);

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

tohm[i]=t[i+1]-t[i];

if(tohm[i]<0)

tohm[i]=tohm[i]*(-1);

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

tot+=tohm[i];

avhm=(float)tot/n;

printf(“Tracks traversed\tDifference between tracks\n”);

for(i=1;i<n+1;i++)
printf(“%d\t\t\t%d\n”,t*i+,tohm*i+);

printf("\nAverage header movements:%f",avhm);

getch();

}
INPUT

Enter no.of tracks:9

Enter track position:55 58 60 70 18 90 150 160 184

OUTPUT

Tracks traversed Difference between tracks

55 45

58 3

60 2

70 10

18 52

90 72

150 60

160 10

184 24

Average header movements:30.8888889


B) SCAN DISK SCHEDULING ALGORITHM
PROGRAM:
#include<stdio.h>
main()
{
int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum=0;
clrscr();
printf("enter the no of tracks to be traveresed");
scanf("%d'",&n);
printf("enter the position of head");
scanf("%d",&h);
t[0]=0;
t[1]=h;
printf("enter the tracks");
for(i=2;i<n+2;i++)
scanf("%d",&t[i]);
for(i=0;i<n+2;i++)
{
for(j=0;j<(n+2)-i-1;j++)
{
if(t[j]>t[j+1])
{
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp;
}
}
}
for(i=0;i<n+2;i++)
if(t[i]==h)
j=i;
k=i;
p=0;
while(t[j]!=0)
{
atr[p]=t[j];
j--;
p++;
}
atr[p]=t[j];
for(p=k+1;p<n+2;p++,k++)
atr[p]=t[k+1];
for(j=0;j<n+1;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("\nAverage header movements:%f",(float)sum/n);
getch();
}

INPUT
Enter no.of tracks:9
Enter track position:55 58 60 70 18 90 150 160 184
OUTPUT
TRACKS TRAVERSED DIFFERENCE BETWEEN TRACKS
150 50

160 10

184 24

90 94

70 20

60 10

58 2

55 3

18 37

Average header movements: 27.77


C) C-SCAN DISK SCHEDULING ALGORITHM
PROGRAM:
#include<stdio.h>
main()
{
int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum=0;
clrscr();
printf("enter the no of tracks to be traveresed");
scanf("%d'",&n);
printf("enter the position of head");
scanf("%d",&h);
t[0]=0;
t[1]=h;
printf("enter total tracks:”);
scanf("%d",&tot);
t[2]=tot-1;
printf("enter the tracks");
for(i=3;i<=n+2;i++)
scanf("%d",&t[i]);
for(i=0;i<=n+2;i++)
for(j=0;j<=(n+2)-i-1;j++)
if(t[j]>t[j+1])
{
temp=t[j];
t[j]=t[j+1];
t[j+1]=temp
}
for(i=0;i<=n+2;i++)
if(t[i]==h);
j=i;
break;
p=0;
while(t[j]!=tot-1)
{
atr[p]=t[j];
j++;
p++;
}
atr[p]=t[j];
p++;
i=0;
while(p!=(n+3) && t[i]!=t[h])
{
atr[p]=t[i];
i++;
p++;
}for(j=0;j<n+2;j++)
{
if(atr[j]>atr[j+1])
d[j]=atr[j]-atr[j+1];
else
d[j]=atr[j+1]-atr[j];
sum+=d[j];
}
printf("total header movements%d",sum);
printf("avg is %f",(float)sum/n);
getch();
}

INPUT
Enter the track position : 55 58 60 70 18 90 150 160 184
Enter starting position : 100
OUTPUT
Tracks traversed Difference Between tracks
150 50
160 10
184 24
18 240
55 37
58 3
60 2
70 10
90 20

Average seek time : 35.7777779


16.INSTALL ANY GUEST OPERATING SYSTEM LIKE
LINUX USING VMWARE

STEP 1: Install The Oracle VM VirtualBox and Config the Setting As per
User Requierments

STEP 2: After the Installation Open The Homepage of a Oracle VM


VirtualBox
STEP 3: Click The New Option then Give a Name ,Folder path,Type of
OS,Version Of the OS ,Because the Linux Have Different Version Like
Ubuntu
STEP 4: Now We Can Allocate the Memory Size its a Necessary one.

You might also like