0% found this document useful (0 votes)
33 views

OS Lab Manual - Merged

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

OS Lab Manual - Merged

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Ex No:1 Installation of windows operating system

AIM:
To Install the Microsoft Windows operating system using guidelines.

PROCEDURE:

How to install the Microsoft Windows operating system

Each version of Microsoft Windows is installed on a computer using similar steps. While
there are steps in the installation process that differ between versions of Windows, the
following general steps and guidelines help you install Windows on your computer.

Note

If you're replacing the hard drive in your computer, you need to reinstall Windows again.

If you're replacing the motherboard in your computer, you may need to purchase a new
licensed copy of Windows and install it. Microsoft has designed current versions of Windows
to be tied to the motherboard in the computer when Windows is installed. So if you change
the motherboard, the existing license, or product key, may no longer be valid.

Tip

If you want to upgrade to a newer version of Windows on your computer, the steps on this
page help you with the upgrade process. The Windows installation process should recognize
if you have an older version of Windows already installed on the computer and ask if you
want to upgrade or perform a fresh install. The upgrade process installs the newer Windows
operating system files over the old ones and preserve your files.

The steps below are for all recent versions of Windows, including Windows 98, Windows
ME, Windows 2000, Windows XP, Windows Vista, Windows 7, Windows 8, Windows 10,
and Windows 11. These steps even work for earlier versions (e.g., Windows 95) as long as
you use the disc version. The floppy diskette version is similar, but it requires additional
steps.

Note

The install guidelines for Windows for a server have additional steps based on the type of
server and version of Windows.

Check hardware compatibility

Before installing or upgrading Windows on your computer, check the hardware in the
computer to make sure it's compatible with that version of Windows. Microsoft provides a
Windows Compatible Products List for checking if the hardware in your computer is
compatible with the chosen version of Windows.

If one or more pieces of hardware is not compatible with the chosen Windows version, we
recommend replacing that hardware with compatible hardware or purchasing a new
computer. Having compatible hardware in your computer helps ensure the Windows install or
upgrade process is successful.

Genuine Windows CD, DVD, or USB thumb drive

First, you need a genuine copy of the Microsoft Windows operating system installation CD,
DVD, or USB thumb drive. A genuine Windows product key is included with the installation
disc, which is required to activate Windows after installation. If you have an OEM (original
equipment manufacturer) computer, the Windows product key is often on the back or side of
the computer.

If you have an OEM computer (e.g., Acer, Dell, HP, etc.), the computer will not have a
genuine Windows CD, DVD, or USB thumb drive. Instead, you would reinstall Windows and
the software using a hidden partition or a set of restore discs. The steps mentioned on this
page would still work, but you'd need a copy of Windows. You can borrow a friend's
Windows disc, as long as it's the same version of Windows that came with the computer and
have a product key.

Note

With early versions of Windows, you cannot download a copy of Windows to install on a
computer. You must purchase a physical copy of Windows. If you are installing Windows 10,
you can download the Windows 10 Media Creation Tool to create a bootable disc or USB
thumb drive. For Windows 11, you can download the Windows 11 Installation Assistant.

Warning

Microsoft has Windows 10 and 11 available for download only from their website. Any other
site that claims to have copies of other versions of Windows should not be trusted. These
copies of Windows are pirated software and could contain anything, including spyware or
malware.

Installing or upgrading Windows

To start the Windows install or upgrade process, you need to configure your computer to boot
from a CD or DVD before booting to the hard drive. Changing the boot process forces the
computer to look for the Windows installation disc before booting from the hard drive.

1. Open the CMOS setup.

 How to enter and exit the BIOS or CMOS setup.


 BIOS (basic input/output system) is the program a computer's microprocessor uses to
start the computer system after it is powered on. It also manages data flow between
the computer's operating system (OS) and attached devices, such as the hard disk,
video adapter, keyboard, mouse and printer.
 The full form of CMOS is Complementary Metal-Oxide-Semiconductor. CMOS is an
integrated circuit built on a printed circuit board. It is a battery-powered memory chip
that effortlessly holds the initialisation data. The BIOS uses this data to turn on the
device, i.e., during the bootup process.

2. Change the computer's boot order. Set the CD, DVD, or disc drive as the first boot
device if you are trying to boot from a disc. Or, set the first boot device to your USB
drive if you're trying to boot from a USB thumb drive. If the drive is not shown, keep
the disc is inserted and reboot the computer. With the disc in the drive, BIOS should
recognize and include it in the list.
3. Save the settings change and exit BIOS.

Once you have updated the boot order, you can begin the Windows installation process.

4. Place the Windows disc in the CD/DVD drive or USB thumb drive into the back of
the computer.
5. Turn on or restart the computer. As the computer starts up, it should detect the
installation disc or drive and show a message similar to Press any key to boot from
CD. Press any key on the keyboard to have the computer boot from the Windows disc
or drive.
6. After the Windows install begins, there are several prompts that you need to answer.
Select either Yes or the appropriate option to install Windows.

Install Note

Make sure you select the Full Install option and not the Repair or Upgrade option.

Upgrade Note

If you are upgrading to a newer version of Windows, select the Upgrade option instead of the
Full Install option.

7. When asked which partition to install Windows onto, select the main partition, usually
the C: drive or one labeled "Unallocated partition". If upgrading Windows, select the
existing installation of Windows on the hard drive.
8. You may be asked if you want to erase all contents on the hard drive, then install
Windows. We recommend you choose this option, as it also formats the hard drive to
allow the Windows operating system to be installed.

Tip

You can use the erase all contents option to uninstall an existing version of Windows on the
hard drive, then install Windows again.

9. The computer may need to restart several times during the Windows install process.
The restarts are normal and if prompted to restart, select the Yes option.
10. When the install process is nearly complete, the Windows configuration option
screens are shown. On these screens, you may be asked to select the time zone you
live in, your preferred language, and the account's name you use to access Windows.
Select the appropriate options and enter the appropriate information on each
configuration screen.

The Windows install process is completed when the computer prompts you to log in or when
it loads into Windows.

Final Windows and computer configuration

After Windows is installed on the computer, you need to install the drivers and related
software for the hardware in the computer. You can use the installation discs that came with
the hardware or download the drivers from the hardware manufacturer's website.

 How to install and update a computer driver.

Tip

If you cannot download drivers because your network card is not working after installing
Windows, you can download the drivers on another computer. Then, copy them to a USB
thumb drive, and move them over to your computer.

We strongly recommend you install the latest drivers for each piece of hardware.

To determine which hardware needs drivers to be installed, check the Device Manager and
look for the exclamation mark "!" next to hardware devices. The exclamation point means
drivers are needed for that device.

After installing the necessary hardware device drivers, install any software programs on the
computer that you want to use.

Finally, download and install any available Windows updates. Updating Windows improves
the operating system's performance, the hardware in the computer, and the software programs
you use. It can also improve security by fixing potential security holes and flaws in Windows.

 How to update a Microsoft Windows computer.

Long-term maintenance of Windows

Microsoft frequently releases new updates for Windows, so we recommend you check for
and install available updates. Doing so helps keep Windows running better and keep your
computer protected.

Also, periodically check for updated hardware device drivers from manufacturers' websites.
Keeping hardware drivers updated helps the hardware devices in the computer run at peak
performance and improves compatibility with other computer hardware and software.

RESULT:

Thus the Microsoft Windows operating system installed successfully.


Ex. No: 2 a) BASICS OF UNIX COMMANDS
Aim:
To study the basic different types of shell command in Unix OS.

General Purpose Commands:


S.No Command Explanation Syntax Example
Name
1) Date used to display the current $date Thursday dec
date with 323:33:45:1st 2011.
day of week, month,
time (24 hours clock) and
the year.
2) Calendar used to display the $cal month of $cal 2011.
specified month or year of a year It prints the calendar
calendar. for the entire year

3) Echo used to print the message $echo text. $echo UNIX


on the display UNIX.

4) Who used to display data about $who. $who.


all the users who are User 1 hy 1dec 03
currently into the system 09:30
User 1 hy 3dec 03
09:15

5) WHO AM I this commands lists the $who am i. $who am i.


account name associated User hy dec 24 09:03.
with the current login
6) HEAD Display the first ten lines of $head file $head rati.
FILTER the file name Clever
Calm

7) TAIL Display last ten lines of the $tail filename $tail rati.
FILTER file. Clever
Calm
File Directory
8) CAT cat - display or concatenate $ cat>file $cat>hema
files name It will create a new
takes a copy of a file and file name “hema”.
sends it to the standard
output
9) MV The mv command is used $mv old $mv hema rati
to move or rename files. filename new The file “hema” is
filename renamed as “rati”.
10) LS list directory contents $ls $ls
Lists all the file and
directories.
11) RM The rm command removes $rm filename $rm add.c
(deletes) files or directories. The file “add.c” is
removed from disk.
12) WC It is used to count the $wc filename $wc rati
number of lines,words and nl nw nc filename.
characters in a line.

13) cp - copy a cp file1 file2 $cp add file $cp add sum
file copies the contents of the new file The content of “add”
file file1 into a new file is copied to “sum”.
called file2. cp cannot copy
a file onto itself.

cp file3 file4 dir1


creates copies of file3 and
file4 (with the same
names), within the directory
dir1. dir1 must
already exist for the
copying to succeed.

cp -r dir2 dir3
recursively copies the
directory dir2, together with
its contents and
subdirectories, to the
directorydir3. If dir3 does
not already exist, it is
created by cp, and the
contents and subdirectories
of dir2 are recreated within
it. If dir3 does exist, a
subdirectory called dir2 is
created within it,containing
a copy of all the contents of
the original dir2.
14) NL The line number is $nl filename $nl rati
specified to the file “rati”.
1.clever
2.calm

Result:
Thus, the different UNIX commands are executed successfully
EX. NO: 2 b): SHELL PROGRAMMIG
1. Arithmetic operators
clear
echo
echo” Enter the value of a and b”;
read a
read b
add = $ (( $a + $b ))
sub = $(( $a - $b ))
mul = $ (( $a * $b ))
div = $ (( $a / $b))
echo”Added value is=$add”
echo” Subtracted value is =$sub”
echo”Multiplied value is =$mul”
echo” Divided value is=$div”

Output
$ sh filename.sh
Enter the value of a and b
5
7
Added value is =12
Subtracted value is =2
Multiplied value is =35
Divided value is =0

2. Fibonacci series
clear
echo
echo Fibonacci series
echo
echo ” Enter the number to find Fibonacci series”
read a
i = -1
j=1
k=1
echo The Fibonacci series is
while ($k - le $a )
do
p = $ (( $i +$j ))
echo” $p”
i = $j
j = $p
k = $(($k+1))
done
Output

$ sh filename.sh
Fibonacci series
Enter the number to find Fibonacci series
4
The Fibonacci series is
0
1
1
2
$

3. Swapping of two numbers

clear
echo
echo Enter the two numbers
read a
read b
echo Before swapping A=$a B=$b
a= $ (( $a + $b ))
b= $ (( $a - $b ))
a= $ (( $a - $b ))
echo After swapping A=$a B=$b

Output

$ sh filename.sh
Enter the two numbers
4
5
Before swapping A=4 B=5
After swapping A=5 B=4

4. Greatest of three numbers


clear
echo
echo Enter the three numbers
read a
read b
read c
if ( $a –gt $b -a $a –gt $c )
then
echo $a is big
elif ( $b –gt $c –a $b –gt $a )
then echo $b is big
else
echo $c is big
fi

Output
$ sh filename.sh
Enter the three numbers
7
4
9
9 is big

5. Leap year
clear
echo
echo Enter a year
read y
if [ $ (( $y % 100)) – eq 0 ]
then [$(( $y %400)) – eq 0 ]
then
echo $y is a leap year
else
echo $y is not a leap year
if
else
if [$ (($y%4)) – eq 0]
then
echo $y is leap year
else
echo $y is not a leap year
fi
fi
Output
$ sh filename.sh
Enter a year
2004
2004 is a leap year

RESULT:
Thus the pr ogram was executed and verified successfully
EX. NO: 3) ROGRAMS USING SYSTEM CALLS OF UNIX OPERATING SYSTEM
fork, exec, getpid, exit, wait, close, stat, opendir, readdir

i) fork(),exec(),exit(), wait()
AIM :
To write the program to create a Child Process using system call fork().

ALGORITHM :
Step 1 : Declare the variable pid.

Step 2 : Get the pid value using system call fork().


Step 3 : If pid value is less than zero then print as “Fork failed”.
Step 4 : Else if pid value is equal to zero include the new process in the system’s file using execlp system
call.

Step 5 : Else if pid is greater than zero then it is the parent


process and it waits till the child completes using the system call wait()
Step 6 : Then print “Child complete”.

SYSTEM CALLS USED:


1. fork( )
Used to create new processes. The new process consistsof a copy of the address space
of the original process. The value of process id for the child process is zero, whereas the
value of process id for the parent is an integer value greater than zero.
Syntax : fork( )

2.execlp( )
Used after the fork() system call by one of the two processes to replace the
process‟ memory space with a new program. It loads a binary file into memory destroying

the memory image of the program containing the execlp system call and starts its
execution.The child process overlays its address space with the UNIX command /bin/ls
using the execlp system call.
Syntax : execlp( )

3. wait( )
The parent waits for the child process to complete using the wait system call. The wait
system call returns the process identifier of a terminated child, so that the parent can tell

which of its possibly many children has terminated.


Syntax : wait( NULL)

4. exit( )
A process terminates when it finishes executing its final statement and asks
the operating system to delete it by using the exit system call. At that point, the process
may return data (output) to its parent process (via the wait system call).

Syntax: exit(0)

PROGRAM CODING :
#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("whoami","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

RESULT:
Thus the pr ogram was executed and verified successfully
ii) PROGRAM USING SYSTEM CALLS
getpid() & getppid()

AIM :
To write the program to implement the system calls getpid() and getppid().

ALGORITHM :
Step 1 : Declare the variables pid , parent pid , child id and grand chil id.
Step 2 : Get the child id value using system call fork().
Step 3 : If child id value is less than zero then print as “error at fork() child”.

Step 4 : If child id !=0 then using getpid() system call get the process id.
Step 5 : Print “I am parent” and print the process id.
Step 6 : Get the grand child id value using system call fork().
Step 7 : If the grand child id value is less than zero then print as “error at fork() grand
child”.
Step 8 : If the grand child id !=0 then using getpid system call get the process id.

Step 9 : Assign the value of pid to my pid.


Step 10 : Print “I am child” and print the value of my pid.
Step 11 : Get my parent pid value using system call getppid().
Step 12 : Print “My parent‟s process id” and its value.
Step 13 : Else print “I am the grand child”.
Step 14 : Get the grand child‟s process id using getpid() and print it as “my process id”.
Step 15 : Get the grand child‟s parent process id using getppid() and print it as “my parent‟s

process id

SYSTEM CALLS USED :


1.getpid( )
Each process is identified by its id value. This function is used to get the id value of a
particular process.

2.getppid( )
Used to get particular process parent‟s id value.
3.perror( )
Indicate the process error.

PROGRAM CODING:
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main( )
{

int pid;
pid=fork( ); if(pid==
-1)
{

perror(“fork failed”); exit(0);


}
if(pid==0)
{
printf(“\n Child process is under execution”);
printf(“\n Process id of the child process is %d”, getpid()); printf(“\n
Process id of the parent process is %d”, getppid());

}
else
{
printf(“\n Parent process is under execution”);
printf(“\n Process id of the parent process is %d”, getpid());
printf(“\n Process id of the child process in parent is %d”, pid());

printf(“\n Process id of the parent of parent is %d”, getppid());


}
return(0);
}
OUTPUT:
Child process is under execution

Process id of the child process is 9314


Process id of the parent process is 9313 Parent
process is under execution
Process id of the parent process is 9313
Process id of the child process in parent is 9314 Process
id of the parent of parent is 2825

RESULT:
Thus the program was executed and verified successfully
iii) PROGRAM USING SYSTEM CALLS
opendir( ) readdir( ) closedir()

AIM :
To write the program to implement the system calls opendir( ), readdir( ).

ALGORITHM :
Step 1 : Start.
Step 2 : In the main function pass the arguments.
Step 3 : Create structure as stat buff and the variables as integer.

Step 4 : Using the for loop,initialization

SYSTEM CALLS USED:


1.opendir( )
Open a directory.

2.readdir( )
Read a directory.

3.closedir()
Close a directory.

PROGRAM CODING:
#include<stdio.h>
#include<sys/types.h>
#include<sys/dir.h>
void main(int age,char *argv[])

{
DIR *dir;
struct dirent *rddir;
printf("\n Listing the directory content\n");
dir=opendir(argv[1]);
while((rddir=readdir(dir))!=NULL)

{
printf("%s\t\n",rddir->d_name);
}
closedir(dir);

OUTPUT:
RP
roshi.c
first.c

pk6.c f2
abc FILE1

RESULT:
Thus the program was executed and verified successfully.
EX.NO:4) a CPU SCHEDULING: ROUND ROBIN SCHEDULING
AIM:
To simulate the CPU scheduling algorithm round-robin.
ALGORITHM:
Step 1: Start the process
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
(a) 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)
(b) Turnaround 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
(c) Average waiting time = Total waiting Time / Number of process
(d) Average Turnaround time = Total Turnaround Time / Number of process
Step 8: Stop the process

PROGRAM:
#include<stdio.h>
int ttime,i,j,temp;
main()
{
int pname[10],btime[10],pname2[10],btime2[10];
int n,x,z;
printf("\n ENTER THE NO.OF PROCESS:");
scanf("%d",&n);
printf("\n ENTER THE PROCESS NAME AND BURST TIME FOR PROCESS\n");
for(i=0;i<n;i++)
{
printf("\n ENTER THE PROCESS NAME:");
scanf("%d",&pname2[i]);
printf("\n ENTER BURST TIME FOR THE PROCESS %d:",pname2[i]);
scanf("%d",&btime2[i]);
}
printf("\n PROCESS NAME \t\t BURST TIME\n");
for(i=0;i<n;i++)
printf("%d\t\t\t%d\n",pname2[i],btime2[i]);
z=1;
while(z==1)
{
ttime=0;
for(i=0;i<n;i++)
{
pname[i]=pname2[i];
btime[i]=btime2[i];
}
printf("\nPRESS 1.ROUND ROBIN 2.EXIT\n");
scanf("%d",&x);
switch(x)
{
case 1:
rrobin(pname,btime,n);
break;
case 2:
exit(0);
break;
default:
printf("INVALID OPTION");
break;
}
printf("\n\n IF YOU WANT TO CONTINUE PRESS 1:");
scanf("%d",&z);
}
}
rrobin(int pname[],int btime[],int n)
{
int tslice;
j=0;
printf("\n\tROUND ROBIN SCHEDULING\n\n");
printf("enter the time slice:\n");
scanf("%d",&tslice);
printf("PROCESS NAME\t REMAINING TIME\t TOTAL TIME");
while(j<n)
{
for(i=0;i<n;i++)
{
if(btime[i]>0)
{
if(btime[i]>=tslice)
{
ttime+=tslice;
btime[i]=btime[i]-tslice;
printf("\n%d\t\t%d\t\t%d",pname[i],btime[i],ttime);
if(btime[i]==0)
j++;
}
else
{
ttime+=btime[i];
btime[i]=0;
printf("\n%d\t\t%d\t\t%d",pname[i],btime[i],ttime);
}
}
}
}
}
OUTPUT

ENTER THE NO.OF PROCESS:4


ENTER THE PROCESS NAME AND BURST TIME FOR PROCESS
ENTER THE PROCESS NAME:1
ENTER BURST TIME FOR THE PROCESS 1:8
ENTER THE PROCESS NAME: 2
ENTER BURST TIME FOR THE PROCESS 2:6
ENTER THE PROCESS NAME: 3
ENTER BURST TIME FOR THE PROCESS 3:8
ENTER THE PROCESS NAME: 4
ENTER BURST TIME FOR THE PROCESS 4:6
PROCESS NAME BURST TIME
1 8
2 6
3 8
4 6

PRESS 1.ROUND ROBIN 2.EXIT


1
ROUND ROBIN SCHEDULING

ENTER THE TIME SLICE:


2
PROCESS NAME REMAINING TIME TOTAL TIME
1 6 2
2 4 4
3 6 6
4 4 8
1 4 10
2 2 12
3 4 14
4 2 16
1 2 18
2 0 20
3 2 22
4 0 24
1 0 26
3 0 28
IF YOU WANT TO CONTINUE PRESS 1:1

PRESS 1.ROUND ROBIN 2.EXIT


2

RESULT:
Thus the program was executed and verified successfully
EX.NO:4) b) CPU SCHEDULING: SHORTEST JOB FIRST.
AIM:
To write a program to stimulate the CPU scheduling algorithm Shortest job first (Non-Preemption)

ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
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 highest
burst time.
Step 5: Set the waiting time of the first process as 0 and its turnaround time as its burst time.
Step 6: Sort the processes names based on their Burt time
Step 7 :For each process in the ready queue, calculate

a). Waiting timess(n)= waiting time (n-1) + Burst time (n-1)


b). Turnaround time (n)= waiting time(n)+Burst time(n)
Step 8: Calculate
(d) Average waiting time = Total waiting Time / Number of process
(e) Average Turnaround time = Total Turnaround Time / Number of process
Step 9: Stop the process

PROGRAM:
#include<stdio.h>
int main()
{
int i,j=0,at[10],st[10],wt[10],tat[10],ch,t1=0,t2=0;
printf("\n......NonPreemptive Process Scheduling......");
printf("\n Enter the service time : ");
for(i=0;i<3;i++)
{
scanf("%d",&st[i]);
}
printf("\n.....Menu.....");
printf("\n 1 - SJF"); printf("\n 2 - Exit");
printf("\n Enter your choice ");
scanf("%d",&ch);
switch(ch)
{
case 1:
for(i=0;i<3;i++)
{
for(j=i+1;j<3;j++)
{
if(st[i]>st[j])
{
t1=st[i];
st[i]=st[j];
st[j]=t1;
}
}
}
printf("\n ........... SJF ...........");
printf("\Service Wait Turn Around ");
for(i=0;i<3;i++)
{
if(i==0)
{
wt[i]=0;
tat[i]=st[i];
printf("\n\t %d\t%d\t%d",st[i],wt[i],tat[i]);
}
else
{
wt[i]=tat[i-1];
tat[i]=st[i]+wt[i];
printf("\n\t%d\t%d\t%d", st[i],wt[i],tat[i]);
}
}
break;
case 2:
exit(0);
}
}
OUTPUT
......NonPreemptive Process Scheduling......
Enter the service time: 3
1
2
.....Menu.....
1 – SJF
2 – Exit
Enter your choice: 1
........... SJF...........
Service Wait Turn Around
1 0 1
2 1 3
3 3 6

RESULT:
Thus the pr ogram was executed and verified successfully
EX.NO: 4) C) CPU SCHEDULING: FIRST COME FIRST SERVE
AIM:
To write a C program to simulate the CPU scheduling algorithm First Come First Serve
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process name and the burst time
Step 4: Set the waiting of the first process as ‗0‘and its burst time as its turnaround time
Step 5: for each process in the Ready Q calculate
a). Waiting timess(n)= waiting time (n-1) + Burst time (n-1)
b). Turnaround time (n)= waiting time(n)+Burst time(n)
Step 6: Calculate
(a) Average waiting time = Total waiting Time / Number of process
(b) Average Turnaround time = Total Turnaround Time / Number of process
Step 7: Stop the process
PROGRAM:

#include<stdio.h>
main()
{
int n,a[10],b[10],t[10],w[10],g[10],i,m;
float tt=0,wt=0,awt=0,att=0;
for(i=0;i<10;i++)
{
a[i]=0;
b[i]=0;
w[i]=0;
g[i]=0;
}
printf("ENTER THE NUMBER OF PROCESS");
scanf("%d",&n);
printf("ENTER THE BURST TIMES");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
printf("ENTER THE ARRIVAL TIMES");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
g[0]=0;
for(i=0;i<10;i++)
g[i+1]=g[i]+b[i];
for(i=0;i<n;i++)
{
w[i]=g[i]-a[i];
t[i]=g[i+1]-a[i];
wt=wt+w[i];
tt=tt+t[i];
}
awt=wt/n;
att=tt/n;
printf("\n\t PROCESS \t WAITING TIME \t TRUN ARROUND TIME \n");
for(i=0;i<n;i++)
{
printf("\tp%d\t\t%d\t\t%d\n",i,w[i],t[i]);
}
printf("THE AVERAGE WAITING TIME IS %f\n",awt);
printf("THE AVERAGE TRUN AROUND TIME IS %f\n",att);
}

OUTPUT
ENTER THE NUMBER OF PROCESS:5
ENTER THE BURST TIMES:
10
1
2
1
5
ENTER THE ARRIVAL TIMES0.1
PROCESS WAITING TIME TRUN ARROUND TIME
p0 0 10
p1 10 11
p2 11 13
p3 13 14
p4 14 19

THE AVERAGE WAITING TIME IS 9.600000


THE AVERAGE TRUN AROUND TIME IS 67.000000

RESULT:
Thus the program was executed and verified successfully
EX.NO: 4)d) CPU SCHEDULING: PRIORITY SCHEDULING
AIM:
To write a C program to simulate the CPU scheduling priority algorithm.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Sort the ready queue according to the priority number.
Step 5: Set the waiting of the first process as ‗0‘ and its burst time as its turnaround time
Step 6: Arrange the processes based on process priority
Step 7:For each process in the Ready Q calculate
Step 8: for each process in the Ready Q calculate
a). Waiting timess(n)= waiting time (n-1) + Burst time (n-1)
b). Turnaround time (n)= waiting time(n)+Burst time(n)
Step 9: Calculate
(a) Average waiting time = Total waiting Time / Number of process
(b) Average Turnaround time = Total Turnaround Time / Number of process
Print the results in an order.
Step 10: Stop the process

PROGRAM:

#include<stdio.h>
int main()
{
int i,j,n,temp,temp1,temp2,b[10],t[10],p[10],w[10],pr[10];
float att=0,awt=0;
for(i=0;i<10;i++)
{
b[i]=0;w[i]=0;
}
printf("Enter the no. of process:");
scanf("%d",&n);
printf("\nEnter the burst time");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
p[i]=1;
}
printf("\nEnter the priority:");
for(i=0;i<n;i++)
{
scanf("%d",&pr[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(pr[i]>pr[j])
{
temp=b[i];
temp1=p[i];
temp2=pr[i];
b[i]=b[j];
p[i]=p[j];
pr[i]=pr[j];
b[j]=temp;
p[j]=temp1;
pr[j]=temp2;
}
}
}

w[0]=0;
for(i=0;i<n;i++)
w[i+1]=w[i]+b[i];
for(i=0;i<n;i++)
{
t[i]=w[i]+b[i];
awt=awt+w[i];
att=att+t[i];
}
awt=awt/n;
att=att/n;
printf("\n\t Processing time \t Waiting time \t Turnaround time\t\n");
for(i=0;i<n;i++)
printf("\tp[%d]\t%d\t\t%d\n",p[i],w[i],t[i]);
printf(" Avg waiting time is %f\n",awt);
printf("\n Avg turnaround time is%f",att);
return 1;
getch();
}
OUTPUT
Enter the no. of process: 3
Enter the burst time: 3
2
1
Enter the priority: 1
2
3
Processing time Waiting time Turnaround time
3 0 3
2 3 5
1 5 6
Avg waiting time is 2.666667
Avg turnaround time is 4.666667

RESULT:
Thus the program was executed and verified successfully.
EX.NO: 5) IMPLEMENTATION OF SHARED MEMORY AND IPC
AIM:
To write a C program to implement shared memory and IPC.

ALGORITHM:
Step 1: start the program
Step 2: Server reads from the input file and writes this data in a message using either a pipe, fifo or
message queue.
Step 3: The client reads the data from the IPC channel.
Step 3: The Client again requiring the data to be copied from kernel’s IPC buffer to the client’s buffer.
Step 4: Finally the data is copied from the client’s buffer.
Step 5: Stop the execution.
PROGRAM:
#include<stdio.h>
int main()
{
int fd[2],child;
Char a[10];
Printf(“\n Enter the string to enter in to the pipe:”);
Scanf(“%s”,a);
Pipe(fd);
Child=fork();
if(!child)
{
Close(fd[0]);0
Write(fd[1],a,5);
Wait(0);
}
else
{
Close(fd[1]);
Read(fd[0],a,5);
Printf(“\n The string retrieved from the pipe is %s\n”,a);
}
Return 0;
}
OUTPUT

Enter the string to enter in to the pipe: Hello CSE

The string retrieved from the pipe is Hello CSE

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 6. IMPLEMENTATION OF SEMAPHORE
AIM:
To write a C program to implement the Producer & consumer Problem (Semaphore)

Algorithm:
Step 1: start the program
Step 2: Read number of items to be produced and consumed.
Step 3: Define producer function & Define consumer function.
Step 3: get the choice and Call producer and consumer.
Step 4: display the no of items produced and consumed
Stop the execution.
PROGRAM:
#include<stdio.h>
int p();
int v();
int sem,m,n;
void producer();
void consumer();
main()
{
int ch;
printf("........ Producer Consumer Process........");
printf("\n Enter no. of products ");
scanf("%d",&n);
sem=n;
while(1)
{
printf("\n\n Producer - 1\n Consumer -2 \n Exit - 3");
printf("\n Enter your choice ");
scanf("%d",&ch);
switch(ch)
{
case 1:
producer();
break;
case 2:
consumer();
break;
case 3:
exit(0);
}
}
}
void producer()
{
if(p()==1)
printf(" Producer %d is produced ",n-sem);
else
printf("Products are already present");
}
void consumer()
{
if(v()==1)
printf("Product %d is consumed ",(n+1)-sem);
else
printf("Product not available");
}
int p()
{
if(sem>0)
{
sem=sem-1;
return(1);
}
else
return(0);
}
int v()
{
if(sem<n)
{
sem=sem+1;
return(1);
}
else
return(0);
}
OUTPUT

........ Producer Consumer Process........


Enter no. of products 3
Producer - 1
Consumer -2
Exit - 3

Enter your choice 1


Producer 1 is produced
Producer - 1
Consumer -2
Exit - 3

Enter your choice 1


Producer 2 is produced
Producer - 1
Consumer -2
Exit - 3

Enter your choice 1


Producer 3 is produced
Producer - 1
Consumer -2
Exit - 3
Enter your choice 1
Products are already present
Producer - 1
Consumer -2
Exit - 3
Enter your choice 2
Product 3 is consumed
Producer - 1
Consumer -2
Exit - 3
Enter your choice 2
Product 2 is consumed
Producer - 1
Consumer -2
Exit - 3
Enter your choice 2
Product 1 is consumed
Producer - 1
Consumer -2
Exit - 3
Enter your choice 2
Product not available

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 7) BANKERS ALGORITHM FOR DEADLOCK AVOIDANCE

AIM:
To write a C program to implement Bankers Algorithm for Deadlock Avoidance.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the values of resources and processes.
Step 3: Get the avail value.
Step 4: After allocation find the need value.
Step 5: Check whether it’s possible to allocate.
Step 6: If it is possible then the system is in safe state. Else system is not in safety state.
Step 7: If the new request comes then check that the system is in safety or not if we allow the request.
Step 8: Display the result safe and unsafe Process
Step 9: stop the program.
PROGRAM:

#include<stdio.h>
int alloc[10][10];
int max[10][10];
int cneed[10][10];
int a[10];
int total[10];
void main()
{
int r,p,i,j,k,flag,f,count,x,flag1;
count=0;
flag1=0;
printf(“\nEnter number of resources:”);
scanf(“%d”,&r);
f=r;
printf(“\nEnter total memory of given resources sequentially:”);
for(i=0;i<r;i++)
scanf(“%d”,&total[i]);
printf(“\nEnter number of processes:”);
scanf(“%d”,&p);
printf(“\nEnter Allocated and Maxneed memory…”);
getch();
for(i=0;i<p;i++)
{
for(j=0;j<r;j++)
{
printf(“\nFor Process %d=”,i);
scanf(“%d%d”,&alloc[i][j],&max[i][j]);
//calculating current need
cneed[i][j]=max[i][j]-alloc[i][j];
}
}
printf(“\nSequence of execution is…\n”);
k=0;
for(j=0;j<r;j++)
{
for(i=0;i<p;i++)
{
a[k]+=alloc[i][j];
}
a[k]=total[k]-a[k];
k++;
}
while(count!=p)
{
for(i=0;i<p;i++)
{
flag=0;
if(cneed[i][f]!=1)
{
for(j=0;j<r;j++)
{
total[j]=a[j]-cneed[i][j];
}
for(k=0;k<r;k++)
{
if(total[k]<0)
{
flag=1;
}
}
}
if((flag==0)&&(cneed[i][f]!=1))
break;
}
x=i;
cneed[x][f]=1;
printf(“P%d->”,x);
count++;
for(i=0;i<r;i++)
{
total[i]+=max[x][i];
a[i]=total[i];
}
for(i=0;i<p;i++)
{
if((cneed[i][0]<a[0])&&(cneed[i][f]==0))
flag1=1;
}
if(flag1==0)
break;
}
if(flag1==0)
printf(“\nUnsafe…”);
else
printf(“\nSafe…”);
getchar();
}

Output :
//For Safe condition
Enter number of resources:3
Enter total memory of given resources sequentially:10 5 7
Enter number of processes:5
Enter Allocated and Maxneed memory...
For Process 0=0 7
For Process 0=1 5
For Process 0=0 3
For Process 1=2 3
For Process 1=0 2
For Process 1=0 2
For Process 2=3 9
For Process 2=0 0
For Process 2=2 2
For Process 3=2 2
For Process 3=1 2
For Process 3=1 2
For Process 4=0 4
For Process 4=0 3
For Process 4=2 3
Sequence of execution is...
P1->P3->P0->P2->P4->
Safe...
//For Unsafe condition
Enter number of resources:3
Enter total memory of given resources sequentially:6 5 4
Enter number of processes:3
Enter Allocated and Maxneed memory...
For Process 0=0 7
For Process 0=1 5
For Process 0=0 3
For Process 1=2 3
For Process 1=0 2
For Process 1=0 2
For Process 2=3 9
For Process 2=0 0
For Process 2=2 2
Sequence of execution is...
P1->
Unsafe...

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 8) IMPLEMENTATION OF DEADLOCK DETECTION ALGORITHM
AIM:
To write a C program to implement an algorithm for Deadlock detection.
ALGORITHM:
Step 1: Start the program.
Step 2: Get the values of resources and processes.
Step 3: Get the claim value & allocation value
Step 4: Get the option value
(a) Get the resource vector
(b) Get the allocation vector
Step 5: run the process and the request allocation until the deadlock occurs.
Step 6: if any deadlock occurs in the process it is displayed
Step 7: Stop the program.
PROGRAM:
Program:
#include<stdio.h>
int max[10][10],need[10][10],allocation[10][10],available[10],work[10],finish[10],request[10];
int np,nr,i,j,k,l,m,n,pid;
int ch,cnt=0;
void safety();
void rr();
int main()
{
printf("\nenter the no of processes:");
scanf("%d",&np);
printf("\nenter the no of resources:");
scanf("%d",&nr);
printf("\nenter the max matrix:");
for(i=0;i<np;i++)
{
for(j=0;j<nr;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("\nenter the allocation matrix:");
for(i=0;i<np;i++)
{
for(j=0;j<nr;j++)
{
scanf("%d",&allocation[i][j]);
}
}
printf("\nenter the available matrix:");
for(i=0;i<nr;i++)
{
scanf("%d",&available[i]);
}
do
{
printf("\n1.safety algo:\n2.resource request:\n3.exit:");
scanf("%d",&ch);
switch(ch)
{
case 1: safety();
break;
case 2: rr();
break;
}
}while(ch!=3);
return 0;
}
void safety()
{
int flag=0;
for(i=0;i<nr;i++)
{
work[i]=available[i];
}
for(i=0;i<np;i++)
{
for(j=0;j<nr;j++)
{
need[i][j]=max[i][j]-allocation[i][j];
}
}
for(i=0;i<np;i++)
{
finish[i]=0;
}
algo:
for(i=0;i<np;i++)
{
for(j=0;j<nr;j++)
{
if(need[i][j]<=work[j]&&finish[i]!=1)
{
flag=1;
}
else
{
flag=0;
break;
}
}
if(flag==1)
{
printf("\n process %d is executing",i);
finish[i]=1;
for(k=0;k<nr;k++)
{
work[k]+=allocation[i][k];
}
}
}
for(i=0;i<np;i++)
{
if(finish[i]==0)
{
goto algo;
}
}
printf("\nexecution is completed:");
}
void rr()
{
int flag1=0,flag2=0;
int cnt1=0,cnt2=0;
printf("\nenter the process id :");
scanf("%d",&pid);
printf("\nenter the request:");
for(i=0;i<nr;i++)
{
scanf("%d",&request[i]);
}
for(i=0;i<nr;i++)
{
if(request[i]<=need[pid][i])
{
flag1=1;
}
else
{
flag1=0;
break;
}
}
if(flag1==0)
{
printf("\nerror occured:");
exit(1);
}
for(i=0;i<nr;i++)
{
if(request[i]<=available[i])
{
flag2=1;
}
else
{
flag2=0;
break;
}
}
if(flag2==0)
{
printf("\nprocess should wait:");
exit(1);
}
printf("\nupdating matrices:");
for(i=0;i<nr;i++)
{
available[i]-=request[i];
allocation[pid][i]+=request[i];
need[pid][i]-=request[i];
}
printf("\napplying safety algorithm:");
safety();
}

INPUT:
enter total no. of processes : 4
enter claim matrix :
01001
00101
00001
10101
enter allocation matrix :
10110
11000
00010
00000
enter resource vector :
21121
enter the availability vector :
00001
OUTPUT :
deadlock causing processes are : 1 2

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 9) IMPLEMENTATION OF THREADING & SYNCHRONIZATION APPLICATIONS
AIM:
To write a C program to implement an algorithm for threading & synchronization.

ALGORITHM:
Step 1: Start the Program
Step 2: Obtain the required data through char and in data types.
Step 3: Enter the filename, index block.
Step 4: Print the file name index loop.

Step 5: File is allocated to the unused index blocks


Step 6: This is allocated to the unused linked allocation.
Step 7: Stop the execution

PROGRAM:
#include<stdio.h>
#include<string.h>

#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_t tid[2];
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;
}

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 10) IMPLEMENTATION OF PAGING TECHNIQUE OF MEMORY
MANAGEMENT

AIM:
To write a C program to implement the concept of Paging

ALGORITHM:
Step 1: The Semaphore mutex, full & empty are initialized.
Step 2: In the case of producer process
i) Produce an item in to temporary variable.

ii) If there is empty space in the buffer check the mutex value for enter into the critical
section.
iii) If the mutex value is 0, allow the producer to add value in the temporary variable
to the buffer.
Step 3: In the case of consumer process
i) It should wait if the buffer is empty

ii) If there is any item in the buffer check for mutex value, if the mutex==0, remove
item from buffer
iii) Signal the mutex value and reduce the empty value by 1.
iv) Consume the item.
Step 4: Print the result
PROGRAM CODING
#include<stdio.h>

main()
{
int i,j,arr[100],pt[20],val,pgno,offset,phymem,fs,nf;
printf("\n Memory Management paging\n");
printf("enter the size of physical memory");
scanf("%d",&phymem);

for(i=20,j=0;i<phymem+20,j<phymem;i++,j++)
arr[i]=j;
printf("\n Enter size of frame or page");
scanf("%d",&fs);

nf=phymem/fs;
printf("No of frame available are\t%d",nf);
printf("\n Enter the page table");
for(i=0;i<nf;i++)
{
scanf("%d",&pt[i]);

}
printf("\n Enter the page no");
scanf("%d",&pgno);
printf("\n Enter the offset");
scanf("%d",&offset);
val=(fs*pt[pgno])+offset;

printf("the physical address is:%d\n",arr[val]);


}

RESULT:
Thus the program was executed successfully and the output was verified.
Ex.NO: 11 IMPLEMENTATION OF MEMORY ALLOCATION TECHNIQUES
AIM:
To write a C program to implement Memory Management concept using the technique best fit, worst fit
and first fit algorithms.

ALGORITHM:
1. Get the number of process.
2. Get the number of blocks and size of process.
3. Get the choices from the user and call the corresponding switch cases.
4. First fit -allocate the process to the available free block match with the size of the process
5. Worst fit –allocate the process to the largest block size available in the list
6. Best fit-allocate the process to the optimum size block available in the list
7. Display the result with allocations

PROGRAM:
#include<stdio.h> main()
{
int p[10],np,b[10],nb,ch,c[10],d[10],alloc[10],flag[10],i,j;
printf("\nEnter the no of process:");
scanf("%d",&np);
printf("\nEnter the no of blocks:");
scanf("%d",&nb);
printf("\nEnter the size of each process:");
for(i=0;i<np;i++)
{
printf("\nProcess %d:",i);
scanf("%d",&p[i]);
}
printf("\nEnter the block sizes:");
for(j=0;j<nb;j++)
{
printf("\nBlock %d:",j);
scanf("%d",&b[j]);
c[j]=b[j];d[j]=b[j];
}
if(np<=nb)
{
printf("\n1.First fit 2.Best fit 3.Worst fit");
do
{
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nFirst Fit\n");
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=b[j])
{
alloc[j]=p[i];
printf("\n\nAlloc[%d]",all oc[j]);
printf("\n\nProcess %d of size %d is allocated in block:%d of size:%d",i,p[i],j,b[j]);
flag[i]=0,b[j]=0;
break;
}
else
flag[i]=1;
}
}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size %d is not allocated",i,p[i]);
}
break;
case 2:
printf("\nBest Fit\n");
for(i=0;i<nb;i++)
{
for(j=i+1;j<nb;j++)
{
if(c[i]>c[j])
{
int temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
printf("\nAfter sorting block sizes:");
for(i=0;i<nb;i++)
printf("\nBlock %d:%d",i,c[i]);
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=c[j])
{
alloc[j]=p[i];printf("\n\nAlloc[%d]",all oc[j]);
printf("\n\nProcess %d of size %d is allocated in block %d of size %d",i,p[i],j,c[j]);
flag[i]=0,c[j]=0;
break;
}
Else
flag[i]=1;
}
}
for(i=0;i<np;i++)
{
if(flag[i]!=0)
printf("\n\nProcess %d of size %d is not allocated",i,p[i]);
}
break;
case 3:
printf("\nWorst Fit\n");
for(i=0;i<nb;i++)
{
for(j=i+1;j<nb;j++)
{
if(d[i]<d[j])
{
int temp=d[i];
d[i]=d[j];
d[j]=temp;
}
}
}
printf("\nAfter sorting block sizes:");
for(i=0;i<nb;i++)
printf("\nBlock %d:%d",i,d[i]);
for(i=0;i<np;i++)
{
for(j=0;j<nb;j++)
{
if(p[i]<=d[j])
{
alloc[j]=p[i];
printf("\n\nAlloc[%d]",alloc[j]);
printf("\n\nProcess %d of size %d is allocated in block %d of size %d",i,p[i],j,d[j]

flag[i]=0,d[j]=0;
break;
}
else
flag[i]=1;
}
}
for(i=0;i<np;i++)
{
if(flag[i]!=0){
printf("\n\nProcess %d of size
%d is not allocated",i,p[i]);
}
break;
default:
printf(“Invalid Choice…!”);break;
}
}while(ch<=3);
}
}
OUTPUT:
Enter the no of process:3 Enter the no of blocks:3
Enter the size of each process:
Process 0:100
Process 1:150
Process 2:200
Enter the block sizes:
Block 0:300
Block 1:350
Block 2:200
1.First fit 2.Best fit 3.Worst fit Enter your choice:1
Alloc[100]
Process 0 of size 100 is allocated in block 0 of size 300 Alloc[150]
Process 1 of size 150 is allocated in block 1 of size 350 Alloc[200]
Process 2 of size 200 is allocated in block 2 of size 200 Enter your choice:2
Best Fit
After sorting block sizes are: Block 0:200
Block 1:300
Block 2:350

Alloc[100]
Process 0 of size 100 is allocated in block:0 of size:200 Alloc[150]
Process 1 of size 150 is allocated in block:1 of size:300 Alloc[200]
Process 2 of size 200 is allocated in block:2 of size:350 enter your choice:3
Worst Fit
After sorting block sizes are:
Block 0:350
Block 1:300
Block 2:200 Alloc[100]
Process 0 of size 100 is allocated in block 0 of size 350 Alloc[150]
Process 1 of size 150 is allocated in block 1 of size 300 Alloc[200]
Process 2 of size 200 is allocated in block 2 of size 200 Enter your choice:6
Invalid Choice…!

RESULT:
Thus a UNIX C program to implement memory management scheme using Best fit worst fit and first fit
were executed successfully.
EX.NO: 12. IMPLEMENTATION OF THE FOLLOWING PAGE REPLACEMENT
ALGORITHMS

12. A) FIFO

AIM:
To implement FIFO page replacement technique.
Algorithm:
Step 1: Start the program
Step 2: Read number of pages n
Step 3: Read number of pages no
Step 4: Read page numbers into an array a[i]
Step 5: Initialize p=0 to check page hit
Step 6: Replace the page with circular queue, while re-placing check page availability in
The frame
Step 7: Place p=1 if page is placed in the frame Count Page faults
Step 8: Print the results.
Step 9: Stop the process.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],b[20],p=0,q=0,m=0,h,k,i,q1=1,j,u;
char f='F';
clrscr();
printf("Enter numbers:");
for(i=0;i<12;i++)
scanf("%d",&b[i]);
for(i=0;i<12;i++)
{if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q1==3))
{
printf("-->%c",f);
m++;
}
p=0;
for(k=0;k<q-1;k++)
{
if(b[i+1]==a[k])
p=1;
}
}
printf("\nNo of faults:%d",m);
getch();
}

OUTPUT:

Input:

Enter the Number of Pages: 12


Enter 12 Page Numbers:
232152453252

Output:

2 2-> F
3 23-> F
2 23
1 231-> F
5 531-> F
2 521-> F
4 524-> F
5 524
3 324-> F
2 324
5 354-> F
2 352-> F

No of faults: 9

RESULT:
Thus the program was executed successfully and the output was verified.
12. B) LRU
AIM:
To implement LRU page replacement technique.
ALGORITHM :
1. Start the program
2. Declare the size
3. Get the pages Numbers
4. Declare counter and stack
6. Select the least recently used page by counter value
7. Stack them according the selection.
8. Display the values
9. Stop the process
PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int g=0,a[5],b[20],p=0,q=0,m=0,h,k,i,q1=1,j,u;
char f='F';
clrscr();
printf("Enter no:");
for(i=0;i<12;i++)
scanf("%d",&b[i]);
for(i=0;i<12;i++)
{if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
g=1;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q1==3)&&(g!=1))
{
printf("-->%c",f);
m++;
}
p=0;
g=0;
if(q1==3)
{
for(k=0;k<q-1;k++)
{
if(b[i+1]==a[k])
p=1;
}
for(j=0;j<q1;j++)
{
u=0;
k=i;
while(k>(i-2)&&(k>=0))
{
if(b[k]==a[j])
u++;
k--;
}
if(u==0)
q=j;
}
}
else
{
for(k=0;k<q;k++)
{
if(b[i+1]==a[k])
p=1;
}
}
}
printf("\nNo of faults:%d",m);
getch();

OUTPUT:

Input:

Enter the Number of Pages: 12


Enter 12 Page Numbers:
232152453252
Output:

2 2-> F
3 23-> F
2 23
1 231-> F
5 251-> F
2 251
4 254-> F
5 254
3 354-> F
2 352-> F
5 352
2 352

No of faults: 7

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 13. IMPLEMENTATION OF THE FILE ORGANIZATION TECHNIQUES
AIM:
To implement LFU page replacement technique.
ALGORITHM :
1. Start the program
2. Declare the size
3. Get the pages Numbers
4. Declare counter and stack
6. Select the least frequently used page by counter value
7. Stack them according the selection.
8. Display the values
9. Stop the process

PROGRAM:
#include<stdio.h>
int n;
main()
{
int seq[30],fr[5],pos[5],find,flag,max,i,j,m,k,t,s,pf=0;
int count=1,p=0;
float pfr;
clrscr();
printf("enter max limit of the sequence:");
scanf("%d",&max);
printf("enter the sequence:");
for(i=0;i<max;i++)
scanf("%d",&seq[i]);
printf("enter the no of frames:");
scanf("%d",&n);
fr[0]=seq[0];
pf++;
printf("%d\t",fr[0]);
i=1;
while(count<n)
{
flag=1;
p++;
for(j=0;j<i;j++)
{
if(seq[i]==seq[j])
flag=0;
}
if(flag!=0)
{
fr[count]=seq[i];
printf("%d\t",fr[count] );
count++;
pf++;
}
i++;
}
printf("\n");
for(i=p;i<max;i++)
{
flag=1;
for(j=0;j<n;j++)
{
if(seq[i]==fr[j])
flag=0;
}
if(flag!=0)
{
for(j=0;j<n;j++)
{
m=fr[j];
for(k=i;k<max;k++)
{
if(seq[k]==m)
{
pos[j]=k;
break;
}
else
pos[j]=-1;
}
}
for(k=0;k<n;k++)
{
if(pos[k]==-1)
flag=0;
}
if(flag!=0)
s=findmax(pos);
if(flag==0)
{
for(k=0;k<n;k++)
{
if(pos[k]==-1)
{
s=k;
break;
}
}
}
pf++;
fr[s]=seq[i];
for(k=0;k<n;k++)
printf("%d\t",fr[k]);
printf("\n");

}
}
pfr=(float)pf/(float)max;
printf("\n theno of page faults are:%d",pf);
printf("\n page fault rate:%f",pfr);
getch();
}
int findmax(int a[])
{
int max,i,k=0;
max=a[0];
for(i=0;i<n;i++)
{
if(max<a[i])
{
max=a[i];
k=i;
}
}
return k;
}

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 14. IMPLEMENTATION OF THE FOLLOWING FILE ALLOCATION STRATEGIES
a) Sequential b) Indexed c) Linked

14(a). SEQUENTIAL

AIM:
To write a C program to implement Sequential file allocation strategy.

ALGORITHM:
Step 1: Start the program.
Step 2: Get the starting block and length of the file
Step 3: Allocate the required locations to each in sequential order
Step 4:
a). allocate the starting block of each file
b). Check whether the required locations are free from the selected location.
c). Allocate and set flag=1 to the allocated locations.
if(f[i]==0)
{
f[i]=1;
}
Step 5: Print the results.
Step 6: Stop the program

PROGRAM:

#include<stdio.h>
#include<conio.h>
main()
{
int f[50],i,st,j,len,c,k,count=0;
for(i=0;i<50;i++)
f[i]=0;
printf("Sequential Allocation");
X:
printf("\n enter starting block & length of files");
scanf("%d%d",&st,&len);
printf("\n file not allocated(yes-1/no-0)");
for(k=st;k<(st+len);k++)
if(f[k]==0)
count++;
if(len==count)
{
for(j=st;j<(st+len);j++)
if(f[i]==0)
{
f[j]=1;
printf("\n%d\t%d",,j,f[j]);
if(j==(st+len-1))
printf("\n the file is allocated to disk");
}
}
else
printf("file is not allocated");
count=0;
printf("\n if u want to enter more files(y-1/n-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch();
}

INPUT
Sequential Allocation
Enter starting block & length of files
4
5

OUTPUT
File not allocated (y-1/n-0)
41
51
61
71
81
File is allocated to disk
If u want to enter more files(y-1/n-0)
0

RESULT:
Thus the program was executed successfully and the output was verified.
14(b) INDEXED:

AIM:
To write a C program to implement indexed file allocation strategiy

ALGORITHM:
Step 1: Start the program.
Step 2: Get the number of files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations by selecting a location
a). Check whether the selected location is free .
b). If the location is free allocate and set flag=1 to the allocated locations.
if(f[i]!=1)
{
f[i]=1;
printf("enter no of files on index");
scanf("%d",&n);
}
Step 5: Print the results.
Step 6: Stop the program
PROGRAM:

#include<stdio.h>
#include<conio.h>
main()
{
int f[50],i,k,j,index[50],n,c,count=0;
for(i=0;i<50;i++)
f[i]=0;
printf("Indexed Allocation");
X:
printf("enter index block");
scanf("%d",&i);
if(f[i]!=1)
{
f[i]=1;
printf("enter no of files on index");
scanf("%d",&n);
}
y:
for(i=0;i<n;i++)
scanf("%d",&index[i]);
if(f[index[i]==0)
count++;
if(count==n)
{
for(j=0;j<nj++)
f[index[j]=1;
printf("\nallocated");
printf("\n file indexed");
for(k=0;k<n;k++)
printf("\n%d->%d:%d",i,index[k],f[index[k]);
}
else
{
printf("\n file in the index already allocation");
printf("\nenter another file indexed");
goto y;
}
printf("\n index is already allocated");
count=0;
printf("\n if u enter one more block(1/0)");
scanf("%d",&c);
if(c==1)
goto x;
getch( ); }

INPUT
Indexed Allocation
Enter index block
3
Enter no of files on index
4
5
6
7
8

OUTPUT
Allocated
File indexed
4->5:1
4->6:1
4->7:1
4->8:1
Index is already allocated
If u enter one more block (1/0)
0
RESULT:
Thus the program was executed successfully and the output was verified.
14(c) LINKED
AIM:
To write a C program to implement linked file allocation strategiy

ALGORTHIM:
Step 1: Start the program.
Step 2: Get the number of files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations by selecting a location.
a). Check whether the selected location is free .
b). If the location is free allocate and set flag=1 to the allocated locations.
While allocating next location address to attach it to previous location
if(f[st]==0)
{
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;
}}
}
Step 5: Print the results.
Step 6: Stop the program

PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int f[50],p,i,j,k,a,st,len,n;
for(i=0;i<50;i++)
f[i]=0;
printf("Linked Allocation");
printf("enter how many blocks already allocated");
scanf("%d",&p);
printf("\nenter the blocks nos");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("enter index sarting block & length");
scanf("%d%d",&st,&len);
k=len;
if(f[st]==0)
{
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{
f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already allocated",j);
k++;
}}
}
else
printf("\nif u enter one more (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto X;
else
exit();
getch( );
}
INPUT
Linked Allocation
Enter how many blocks already allocated
5
Enter block nos
3
7
9
10
14
Enter index starting block & length
4
10

OUTPUT
4->1
5->1
6->1
7->file is already allocated
8->1
9->file is already allocated
10->file is already allocated
11->1
12->1
13->1
14->file is already allocated
15->1
16->1
17->1

RESULT:
Thus the program was executed successfully and the output was verified.
EX.NO: 15 DISK SCHEDULING ALGORITHMS
AIM:
Write a C program to simulate disk scheduling algorithms
a) FCFS b) SCAN c) C-SCAN

DESCRIPTION
One of the responsibilities of the operating system is to use the hardware efficiently. For the disk drives,
meeting this responsibility entails having fast access time and large disk bandwidth. Both the access time
and the bandwidth can be improved by managing the order in which disk I/O requests are serviced which
is called as disk scheduling. The simplest form of disk scheduling is, of course, the first-come, first-
served (FCFS) algorithm. This algorithm is intrinsically fair, but it generally does not provide the fastest
service. In the SCAN algorithm, the disk arm starts at one end, and moves towards the other end,
servicing requests as it reaches each cylinder, until it gets to the other end of the disk. At the other end,
the direction of head movement is reversed, and servicing continues. The head continuously scans back
and forth across the disk. C-SCAN is a variant of SCAN designed to provide a more uniform wait time.
Like SCAN, C-SCAN moves the head from one end of the disk to the other, servicing requests along the
way. When the head reaches the other end, however, it immediately returns to the beginning of the disk
without servicing any requests on the return trip

PROGRAM

FCFS DISK SCHEDULING ALGORITHM


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

OUTPUT
Enter no.of tracks:9
Enter track position:55 58 60 70 18 90 150 160 184

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.888889

SCAN DISK SCHEDULING ALGORITHM


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

OUTPUT
Enter no.of tracks:9
Enter track position:55 58 60 70 18 90 150 160 184 Tracks traversed
Difference between tracks
150 50

160 10
1841 24
90 94

70 20
60 10

58 2
55 3
18 37
Average header movements: 27.77
C-SCAN DISK SCHEDULING ALGORITHM
#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();
}
OUTPUT
Enter the track position: 55 58 60 70 18 90 150 160 184 Enter starting
position : 100
Tracks traversed Difference Between tracks
150 50
160 10

184 24
18 240
55 37
58 3
60 2
70 10

90 29
Average seek time : 35.7777779

RESULT:
Thus the program to implement disk Scheduling algorithm has been executed and verified
Ex No:16 Install any guest operating system like Linux using VMware

AIM:

To Install guest operating system like Linux using VMware using guidelines.

PROCEDURE:

How to Install Linux in Windows With a VMware Virtual Machine

Use a PC That Supports Virtualization

You've tried Linux from a live CD. Now you want to install it, but you're unsure about dual
booting. The sensible option is to install your chosen Linux operating system in a virtual
machine (VM).

A virtual machine is a software environment that replicates the conditions of a hardware


environment: a personal computer. The environment is based on the hardware of your
physical PC and limited only by the components within. For instance, you couldn't have a
virtual four core CPU on a processor with two cores.

However, while virtualization can be achieved on many systems, the results will be far
superior on computers equipped with a CPU that supports it.

Several VM tools make it easy to install Linux operating systems (OS). VMware produces
the most accomplished virtual machine applications. Let's find out how to install Linux in
Windows with VMware Workstation Player.

Install VMware Workstation Player

To start, head to the VMware website and download the latest version of their Workstation
Player tool. We're using VMware Workstation 15 Player, which is around 150MB to
download.

VMware Workstation Player is free and available for non-commercial, personal, and home
use. Students and non-profit organizations can also benefit from the free version. In terms of
functionality, VMware Workstation Player includes everything you could need for the
standard virtual machine tasks.

However, VMware offers a wide selection of virtualization solutions aimed at businesses of


all levels. You can find out more about their solutions on the website's product page.

Once VMware Workstation Player has downloaded, launch the installer and follow the
installation wizard. You'll see the option to install an Enhanced Keyboard Driver---while you
won't need this initially, it's worth having.
Choose Your Preferred Linux OS

You probably know which Linux OS you want to try. Some Linux distros are particularly
suited to running in a VM, but others are not. All 32-bit and 64-bit distros work in a virtual
machine. However, you cannot run Linux distros for ARM architecture (such as the
Raspberry Pi) in VMware.

Create Your Linux Virtual Machine

While your Linux ISO downloads, it's a good time to start configuring your VM. Start by
launching VMware Workstation Player. When you're ready to create a VM:

1. Click Create a New Virtual Machine


2. Select the default option, Installer disc image file (iso)
3. Click Browse to find the ISO file

4. With "guest" OS selected, click Next


5. Select Linux as the Guest operating system type
6. Under Version, scroll through the list and select the OS
7. Click Next to proceed and if necessary, input a Virtual machine name
8. Confirm the storage Location and change if needed

With the operating system selected and configured, it's time to build the virtual machine.

1. Under Specify Disk Capacity adjust Maximum disk size if required (the default
should be enough)
2. Select Split virtual disk into multiple files as this makes moving the VM to a new
PC easy
3. Click Next then confirm the details on the next screen
4. If anything seems wrong click Back, otherwise click Finish

Your Linux virtual machine will be added to VMware Workstation Player.

Customize Your Virtual Hardware

In some cases, you might need to customize the virtual machine before installing Linux.
Alternatively, you might install the OS and find there is something missing.

To fix this, right-click your virtual machine in VMware Workstation Player and select
Settings.
Here, you can tweak the virtual machine's hardware in other ways beyond the HDD. You
have options for the Memory, Processors, Network Adaptor configuration, and much more.

It's worth taking a look at the Processors screen. In the right-hand pane, you'll spot a
reference to a Virtualization engine. By default, this works automatically, but for
troubleshooting set Intel VT-x or AMD-V, depending on your CPU.

You can address performance issues in the Memory screen. Here you'll spot an illustration of
the suggested RAM size, as well as recommended options for your virtual machine. It's a
good idea to stick to these recommendations. Going too small will prove a problem, while
setting the RAM too high will impact on your PC's performance, slowing everything from
standard system tasks to running the VM software!

Finally, spare a moment to check the Display settings. Default settings should be fine but if
there is an issue with the display you can toggle 3D acceleration. Multiple monitors can be
used and custom resolution set, but note that some modes will clash with some desktops.

Click OK to confirm changes, then select the virtual machine and click the Play button to
begin.
Download and Install VMware Tools

On the first boot of your virtual machine, you'll be prompted to Download and Install
VMware Tools for Linux. Agree to this, then wait as it is downloaded.

VMware Tools will enhance the performance of the virtual machine while enabling shared
folders between host and guest machines.

How to Install Linux in VMware

When the ISO boots in the virtual machine, it will boot into the live environment. This is a
temporary Linux that exists only on the boot media and in the system memory. To ensure the
environment persists, use the Install option on the desktop.

From this point, the installation will continue as if you're installing an OS on a physical
machine. Progress through the installation wizard, creating a user account and setting other
options when prompted.

Once the installation is complete, you'll be able to log into the Linux virtual machine and start
using the guest OS. It's that simple!

RESULT:

Thus the guest operating system like Linux using VMware installed
successfully.

You might also like