0% found this document useful (0 votes)
34 views66 pages

OS Lab - Odt

Uploaded by

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

OS Lab - Odt

Uploaded by

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

EX.

NO: 1 INSTALLATION OF WINDOWS OPERATING SYSTEM


DATE:

AIM:
To install Windows Operating System.
DESCRIPTION:
Windows XP is a versatile O.S. which took over various laggings in the earlier O.S
given by Microsoft. One major component which really improves the performance and working
is the availability of various device drivers which really make device operation as simple as
plug-n-play. If the minimum system requirement is not fulfilled then you will not be able to
install this O.S. on to your machine, however, Windows 98 might serve the purpose. Windows
XP is in huge demand globally, let us learn how to load it before making us to work on it.
System Requirements
System Requirements Minimum Recommended
Processor 233MHz 300 MHz or higher
Memory 64 MB RAM 128 MB RAM or higher
Video adapter and Monitor Super VGA (800 x 600) or higher resolution
Hard drive disk free space 1.5 GB or higher
Drives CD-ROM drive or DVD drive
Input Devices Keyborad, Microsoft Mouse
Sound Speakers. Sound card, Head Phones

Installation Steps
The following step by step procedure will help you to install Windows XP. The installation
procedure is shown with the figure appears on your screen after doing a step.
1) Insert the Windows XP CD into your computer and restart.
2) If prompted to start from the CD, press SPACEBAR. If you miss the prompt (it only
appears for a few seconds), restart your computer to try again.

3) Windows XP Setup begins. During this portion of setup, your mouse will not work, so
you must use the keyboard. On the Welcome to Setup page, press ENTER.
4) On the Windows XP Licensing Agreement page, read the licensing agreement. Press the
PAGE DOWN key to scroll to the bottom of the agreement. Then press F8.
5) Next page enables you to select the hard disk drive on which Windows XP will be
installed. Once you complete this step, all data on your hard disk drive will be removed and
cannot be recovered. It is extremely important that you have a recent backup copy of your
files before continuing. When you have a backup copy, press D, and then press L when
prompted. This deletes your existing data.
6) Press ENTER to select Unpartitioned space, which appears by default.
7) Press ENTER again to select Format the partition using the NTFS file system, which
appears by default.
8) Windows XP erases your hard disk drive using a process called formatting and then copies
the setup files. You can leave your computer and return in 20 to 30 minutes

9) Windows XP restarts and then continues with the installation process. From this point
forward, you can use your mouse. Eventually, the Regional and Language Options page
appears. Click Next to accept the default settings. If you are multilingual or prefer a language
other than English, you can change language settings after setup is complete.
10) On the Personalize Your Software page, type your name and your organization name.
Some programs use this information to automatically fill in your name when required. Then,
click Next.
11) On the Your Product Key page, type your product key as it appears on your Windows XP
CD case. The product key is unique for every Windows XP installation. Then, click Next.
12) On the Computer Name and Administrator Password page, in the Computer name box,
type a name that uniquely identifies your computer in your house, such as FAMILYROOM
or TOMS. You cannot use spaces or punctuation. If you connect your computer to a network,
you will use this computer name to find shared files and printers. Type a strong password
that you can remember in the Administrator password box, and then retype it in the Confirm
password box. Write the password down and store it in a secure place. Click Next.

13) On the Date and Time Settings page, set your computer’s clock. Then, click the Time
Zone down arrow, and select your time zone. Click Next.
14) Windows XP will spend about a minute configuring your computer. On the Networking
Settings page, click Next.
15) On the Workgroup or Computer Domain page, click Next.

16) Windows XP will spend 20 or 30 minutes configuring your computer and will
automatically restart when finished. When the Display Settings dialog appears, click OK.
17) When the Monitor Settings dialog box appears, click OK.
18) The final stage of setup begins. On the Welcome to Microsoft Windows page, click Next.

19) On the Help protect your PC page, click Help protect my PC by turning on Automatic
Updates now. Then, click Next
20) Windows XP will then check if you are connected to the Internet:
If you are connected to the Internet, select the choice that describes your network connection
on the Will this computer connect to the Internet directly, or through a network? page. If
you’re not sure, accept the default selection, and click Next.
21) If you use dial-up Internet access, or if Windows XP cannot connect to the Internet, you
can connect to the Internet after setup is complete. On the How will this computer connect to
the Internet? page, click Skip.
22) Windows XP Setup displays the Ready to activate Windows? page. If you are connected
to the Internet, click Yes, and then click Next. If you are not yet connected to the Internet,
click No, click Next, and then skip to step 24. After setup is complete, Windows XP will
automatically remind you to activate and register your copy of Windows XP.
23) On the Ready to register with Microsoft page, click Yes, and then click Next
24) On the Collecting Registration Information page, complete the form. Then, click Next.
25) On the Who will use this computer? page, type the name of each person who will use the
computer. You can use first names only, nicknames, or full names. Then click Next. To add
users after setup is complete or to specify a password to keep your account private, read
Create and customize user accounts.
26) On the Thank you! page, click Finish.
27) Congratulations! Windows XP setup is complete. You can log on by clicking your name
on the logon screen. If you’ve installed Windows XP on a new computer or new hard disk
drive, you can now use the File and Settings Transfer Wizard to copy your important data to
your computer or hard disk drive.

RESULT
Thus the Windows Operating System is installed and Executed successfully.
EX. NO: 2 a STUDY OF BASIC UNIX COMMANDS
DATE :
AIM:
To study the basic commands in UNIX.

COMMANDS:
1. WORKING WITH DIRECTORIES:
 Create a Directory:
COMMAND : mkdir
SYNTAX : mkdir DirectoryName
EXPLANATION : Used to create a new directory with the specified name.
EXAMPLE : mkdir student.
 Changing the Working Directory:
COMMAND : cd
SYNTAX : cd DirectoryName.
EXPLANATION : Used to switch from one directory to another.
EXAMPLE : cd UnixLab
OPTIONS
 cd . .  helps to move one level up.
 cd \  helps to go to the root directory.
 Current Working Directory:
COMMAND : pwd
SYNTAX : pwd
EXPLANATION : Used to know the current working directory.
 Removing a directory:
COMMAND : rmdir (or) rd
SYNTAX : rmdir DirectoryName
EXPLANATION : Used to remove the specified directory.
EXAMPLE : rmdir UnixLab.

2. WORKING WITH FILES:


 Creating a File:
COMMAND : cat
SYNTAX : cat > FileName
EXPLANATION : Used to create a new file with the specified file name.
EXAMPLE : cat > One
After finished entering the contents for a file press Ctrl+d to save and end the file.
 Displaying the content of a File:
COMMAND : cat
SYNTAX : cat FileName
EXPLANATION : Used to display the contents of the specified file.
EXAMPLE : cat One
 Append content of a File:
COMMAND : cat
SYNTAX : cat >> FileName
EXPLANATION : Used to display the contents of the specified file.
EXAMPLE : cat >> One
 Copying a File:
COMMAND : cp
SYNTAX : cp SourceFileName DestinationFileName.
EXPLANATION : Used to produces a copy of the source file and is stored in
the specified destination file by overwriting its previous
contents.
EXAMPLE : cp One Two
OPTIONS
 cp -r source destination Copies directory with all its Files and sub-
directories.
 cp -i source destination Warns user with prior information to
overwrite the destination file.
 Moving a File:
COMMAND : mv
SYNTAX : mv SourceFileName DestinationFileName
EXPLANATION : Used to move the contents of source file into destination file.
EXAMPLE : mv One Two
OPTIONS
 mv File1 File2 File3 DirectoryName  Moves multiple files to an existing
Directory.
 mv -v source destination  Displays name of each file moved.
 Removing a File:
COMMAND : rm
SYNTAX : rm FileName
EXPLANATION : Used to remove a specified File.
EXAMPLE : rm Two

3. LISTING FILES AND DIRECTORIES:


COMMAND : ls
SYNTAX : ls
EXPLANATION : Used to displays all the files and directories of the system.
OPTIONS
 ls -a list all the files and directories in the current directory including hidden
files.

4. WRAP LINES:
COMMAND : fold
SYNTAX : fold FileName
EXPLANATION : Used to wraps each line in an input file to fit a specified
width and prints it to the standard output..
OPTIONS
 fold -b FileName : It is used to limit the width of the output by the number of
bytes.
 fold -s FileName : It is used to break the lines on spaces.

5. DISPLAYING USER DETAILS:


 Displaying details of all users:
COMMAND : who
SYNTAX : who
EXPLANATION : List the information about all the users who have logged in.
 Displaying current user details:
COMMAND : who
SYNTAX : who am i
EXPLANATION : used to display information about the current user.
 Displaying detailed information about users:
COMMAND : finger
SYNTAX : finger [email protected]
EXPLANATION : It usually lists the login name, the full name, and other
details about the user you are fingering. These details may include login time, idle
time, time mail was last read, etc.

6. CLEAR COMMAND:
COMMAND : clear
SYNTAX : clear
EXPLANATION : Used to clear the terminal screen.

7. MAN COMMAND:
COMMAND : man
SYNTAX : man CommandName
EXPLANATION : Used to display the manual of a specific command.
EXAMPLE : man mkdir

8. ALIAS COMMAND:
COMMAND : alias
SYNTAX : alias UnixCommand=’new name’
EXPLANATION : Used to create a shortcut to reference a command.
EXAMPLE : alias rm= 'rm -i'
UNALIAS : Removing an existing alias is known as unaliasing.
COMMAND : unalias
SYNTAX : unalias AliasName

9. DISPLAYING SYSTEM DISK DETAILS:


 Displaying Free Disk space:
COMMAND : df  stands for Disk Free
SYNTAX : df
EXPLANATION : It displays the amount of free disk space available on the file
system in a Linux system.
OPTIONS
 df - View entire file system disk space usage
 df –h - Display file system disk usage in human readable format
 Displaying used disk space:
COMMAND : du
SYNTAX : du
EXPLANATION : used to display how much disk space is being used by the files
and folders.

10. DISPLAYING PROCESS DETAILS:


 Displaying Information about Process:
COMMAND : ps
SYNTAX : ps
EXPLANATION : It displays information about the processes that are running
in the system.
 Displaying summary Information about Process:
COMMAND : top
SYNTAX : top -n 10
EXPLANATION : It shows the summary information of the system and the list
of processes or threads which are currently managed by the Linux Kernel.
ATTRIBUTES
 PID: Shows task’s unique process id.
 PR: Stands for priority of the task.
 SHR: Represents the amount of shared memory used by a task.
 VIRT: Total virtual memory used by the task.
 USER: User name of owner of task.
 %CPU: Represents the CPU usage.
 TIME+: CPU Time.
 %MEM: Shows the Memory usage of task.

11. MIDNIGHT COMMANDER COMMAND:


. COMMAND : mc
SYNTAX : mc
EXPLANATION : Midnight commander is a user interface. It supports mouse
when you are running it.

12. LP COMMAND:
. COMMAND : lp
SYNTAX : lp FileName
EXPLANATION : It submits files for printing or alters a pending job.
EXAMPLE:
1. lp -c -n30 -d Devicename FileName
To print 30 copies of the given File Name using a copy of the file.
2. lp -c -m -n30 -d Devicename FileName
To print 30 copies of the given File Name using a copy of the file, and to
notify the user that the job is completed using mail.

13. PASSWD COMMAND:


. COMMAND : passwd
SYNTAX : passwd
EXPLANATION : It is used to change the user account passwords.

14. TAR COMMAND:


COMMAND : tar  (tape archive )
SYNTAX : tar FileName
EXPLANATION : It is used for creating archive of multiple files and folders
into a single archive file. Tar command is used to take backup
by archiving multiple files and directory into a single tar or
archive file.
COMMANDS:
 Create a tar archive file: tar -cvf Flowers.txt demo.tar
 List the contents of tar archive file: ls -l demo.txt
 Extracting files and directories from tar file: tar -tvf demo.tar

15. COMMUNICATION COMMANDS:


 File Transfer Protocol (FTP):
COMMAND : ftp  (File Transfer Protocol)
EXPLANATION : It is used to connect and login to a remote ftp server for
downloading and uploading files
STEPS:
 Establishing an FTP connection
To connect to the FTP server, type in the terminal window 'ftp' and then
the domain name 'domain.com' or IP address of the FTP server.
Syntax: ftp domain.com
 Login with User and Password
Most FTP servers logins are password protected, so the server will ask us
for a 'username' and a 'password'.
 Downloading files with FTP
Before downloading a file, FTP file download directory must be set
using 'lcd' command:
Syntax: lcd DirectoryName
 Uploading Files with FTP
File upload from the local directory can be done using 'put' command.
Syntax: put FileName
 Closing the FTP connection
Once FTP work is done then close the connection for security reasons using
any one of the three commands.
Syntax: bye (or) exit (or) quit
 Telnet:
COMMAND : telnet
EXPLANATION : It is used to connect to a remote Linux computer and run
programs remotely and conduct administration
SYNTAX : telnet hostname=" Name "

16. HISTORY COMMAND:


. COMMAND : history
SYNTAX : history
EXPLANATION : Used to to view the previously executed command.

17. DATE COMMAND:


. COMMAND : date
SYNTAX : date
EXPLANATION : Used to display the current date with day of week, month,
day, time and the year.

18. DISPLAYING CALENDER:


COMMAND : cal
SYNTAX : cal
EXPLANATION : Used to display the calendar of the current month.
OPTIONS:
 cal year  used to display the calendar of the specified year on the screen.
OPTIONS EXPLANATIONS
$ date + % m Used to display the current month on the screen.
Used to display the name of the current month on the
$ date + % b
screen.
$ date + % d Used to display the current system day on the screen.
$ date + % y Used to display the last two digits of the year.
Used to display the the current system hour on the
$ date + % H
screen.
Used to display the current system minute on the
$ date + % M
screen.
Used to display the current system second on the
$ date + % s
screen.
19. ECHO COMMAND:
COMMAND : echo
SYNTAX : echo “message”
EXPLANATION : Used to print the message on the screen

RESULT
Thus the basic Unix Commands was studied and executed successfully.
EX: NO: 2 b IMPLEMENTATION OF SHELL PROGRAMS
DATE :
AIM:
To implement simple Shell Programs to do basic Arithmetic operations,
Conditional Statements and Looping Statements.

Shell program to perform arithmetic operations


ALGORITHM
Step 1: Read the two Numbers.

Step 2: Give the expressions for Sum, Difference, Product and Quotient and solve them.

Step 3: Print the Result


PROGRAM:
echo "Enter the two numbers : "
read a
read b
c1=`expr $a + $b`
echo "Sum = $c1"
c2=`expr $a - $b`
echo "Difference = $c2"
c3=`expr $a \* $b`
echo "Product = $c3"
c4=`expr $a / $b`
echo "Quotient = $c4"

OUTPUT:
ponjesly@ponjesly-desktop:~$ sh arith.sh
Enter two numbers
20
5
Sum = 25
Difference = 15
Product = 100
Quotient = 4

Shell program to find the sum of n numbers


ALGORITHM:
Step 1:Get N (Total Numbers).
Step 2. Get N numbers using loop.
Step 3. Calculate the sum.
Step 4. Print the result.
PROGRAM
echo "Enter Size(N)"
read n
i=1
sum=0
echo "Enter Numbers"
while [ $i -le $n ]
do
read num
sum=`expr $sum + $num`
i=`expr $i + 1`
done
echo “Sum of given $n numbers is $sum”

OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh sum1.sh
Enter Size(N)
5
Enter Numbers
1
2
3
4
5
Sum of given 5 Numbers is 15

Shell program to find the factorial of a given number


ALGORITHM:
Step 1: Read the value of n.
Step 2: Assign the value of fact as 1
Step 3: If the value of i is greater than n then calculate fact=`expr $fact * $i` and i=$((i + 1))
Step 4: Print the factorial of the given number.
PROGRAM:
echo "Enter a number"
read n
i=1
fact=1
while [ $i -le $n ]
do
fact=`expr $fact * $i`
i=$((i + 1))
done
echo "The factorial of $n is $fact"

OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh factorial.sh
Enter a number
5
Enter Numbers
The factorial of 5 is 120

Shell program to find the given number is odd or even

ALGORITHM:.
Step 1: Read the value of num.
Step 2: Calculate r=expr $num%2
Step 3: If the value of rem equals 0 then print the number is even
Step 4: If the value of rem not equal to 0 then print the number is odd.
PROGRAM:
echo "Enter a number : "
read num
rem=`expr $num % 10`
if [ $rem -eq 0 ]
then
echo "$num is an Even Number"
else
echo "$num is an Odd Number"
fi

OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh odd.sh
Enter a values :
12
12 is an Even Number

ponjesly@ponjesly-desktop:~/geetha$ sh odd.sh
Enter a values :
25
12 is an Odd Number

Shell program to find the greatest among the given three numbers
ALGORITHM:
Step 1: Take three inputs from the user
Step 2: In if-else condition, check which is the greatest
Step 3: Also check with the third number
Step 4: Find the result
Step 5: print the result
PROGRAM:
echo "Enter 3 values :"
read a b c
if [ $a -gt $b -a $a -gt $c ]
then
echo "A is the Biggest number"
elif [ $b -gt $c ]
then
echo "B is the Biggest number"
else
echo "C is the Biggest number"
fi

OUTPUT:
ponjesly@ponjesly-desktop:~/geetha$ sh big.sh
Enter 3 values :
12 45 8
B is the Biggest number

ponjesly@ponjesly-desktop:~/geetha$ sh big.sh
Enter 3 values :
56 23 17
A is the Biggest number

ponjesly@ponjesly-desktop:~/geetha$ sh big.sh
Enter 3 values :
12 56 89
C is the Biggest number

RESULT:
Thus the above Shell programs was executed successfully.
EX: NO: 3 PROCESS MANAGEMENT USING SYSTEM CALLS
DATE :

AIM:
To implement UNIX System calls in C.
ALGORITHM:
1. Create a child process using fork system call.
2. If return value is -1 then Print "Process creation failure"
Terminate using exit system call.
3.If pid>0 Print "Parent process"
Print process id of the parent using getpid system call
Print even number
4. Otherwise Print "Child process" Print process id of the child using getpid system call
Print odd number
5. Stop
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
main()
{
int i;
pid_t pid;
pid = fork();
if (pid < 0)
{
printf("\nProcess creation failure\n");
exit(-1);
}
else if(pid > 0)
{
wait(NULL);
printf ("\nParent starts ");
printf("\nProcess id of child is %d", getpid());
printf ("\nEven Nos: ");
for (i=2;i<=10;i+=2)
printf ("%3d",i);
printf ("\nParent ends\n");
}
else
{
printf ("Child starts ");
printf("\nChild Process id is %d", getpid());
printf ("\nOdd Nos: ");
for (i=1;i<10;i+=2)
printf ("%3d",i);
printf ("\nChild ends\n");
}
close(pid);
}
OUTPUT:
Child starts
Child Process id is 4275
Odd Nos: 1 3 5 7 9
Child ends

Parent starts
Process id of child is 4274
Even Nos: 2 4 6 8 10
Parent ends
RESULT:
Thus the above programs implement UNIX System calls C was written and executed
successfully.

EX: NO:4 a IMPLEMENTATION OF FIRST COME FIRST SERVE (FCFS) CPU SCHEDULING
DATE :
AIM:
To implement First Come First Serve (FCFS) CPU Scheduling in C language.
ALGORITHM:
• Get the Number of Process and CPU burst time for all the processes.
• Calculate the waiting time according to the process that was first entered and then
the next it continued all the processes get executed.
• Calculate the turnaround time.
• Find the average waiting time and average turnaround time.
• Display all the details for each process.
PROGRAM:
#include<stdio.h>
int main( )
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("Enter total number of processes: ");
scanf("%d",&n);
printf("\nEnter Process Burst Time\n");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
wt[0]=0; //waiting time for first process is 0
for(i=1;i<n;i++) //calculating waiting time
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++) //calculating turnaround time
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\n%d\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("\n\nAverage Waiting Time:%d",avwt);
printf("\nAverage Turnaround Time:%d",avtat);
return 0;
}
OUTPUT:
Enter total number of processes: 4
Enter Process Burst Time
3
6
4
2
Process Burst Time Waiting Time Turnaround Time
1 3 0 3
2 6 3 9
3 4 9 13
4 2 13 15
Average Waiting Time:6
Average Turnaround Time:10

RESULT:
Thus the program implement First Come First Serve (FCFs) CPU Scheduling was done
and executed successfully.

EX: NO:4 b IMPLEMENTATION OF SHORTEST JOB FIRST(SJF) CPU SCHEDULING

DATE:

AIM:
To implement Shortest Job First (SJF) CPU Scheduling in C language.
ALGORITHM:
• Get the Number of Process and CPU burst time for all the processes.
• Calculate the waiting time such that the process with the shortest CPU burst time is
executed first and the processes with the largest CPU burst time is executed last.
• Calculate the turnaround time.
• Find the average waiting time and average turnaround time.
• Display all the details for each process.
PROGRAM:
#include<stdio.h>
void main( )
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
printf("\nEnter Burst Time:\n");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
p[i]=i+1; //contains process number
}
//sorting burst time in ascending order using selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0; //waiting time for first process will be zero
//calculate waiting time
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=(float)total/n; //average waiting time
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n; //average turnaround time
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}
OUTPUT:
Enter number of process: 4
Enter Burst Time:
3
6
4
2
Process Burst Time Waiting Time Turnaround Time
p4 2 0 2
p1 3 2 5
p3 4 5 9
p2 6 9 15

Average Waiting Time=4.000000


Average Turnaround Time=7.750000

RESULT:
Thus the program implement Shortest Job First (SJF) CPU Scheduling was done and
executed successfully.

EX: NO:4 c IMPLEMENTATION OF PRIORITY CPU SCHEDULING


AIM:
DATE:
To implement Priority CPU Scheduling in C language.
ALGORITHM:
 Get the Number of Process their CPU burst time, and priority for all the processes.
 Calculate the waiting time such that the process with the lowest priority is executed
first and the process with the highest priority process complete the execution last.
 Calculate the turn around time.
 Find the average waiting time and average turn around time.
 Display all the details for each process.
PROGRAM:
#include<stdio.h>
int main( )
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total=0,pos,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);
printf("\nEnter Burst Time and Priority\n");
for(i=0;i<n;i++)
{
printf("\nProcess %d \n",i+1);
printf("Burst Time:");
scanf("%d",&bt[i]);
printf("Priority:");
scanf("%d",&pr[i]);
p[i]=i+1; //contains process number
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0; //waiting time for first process is zero
for(i=1;i<n;i++) //calculate waiting time
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=total/n; //average waiting time
total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\n%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=total/n; //average turnaround time
printf("\n\nAverage Waiting Time=%d",avg_wt);
printf("\nAverage Turnaround Time=%d\n",avg_tat);
return 0;
}
OUTPUT:
Enter Total Number of Process:4
Enter Burst Time and Priority
Process 1
Burst Time:3
Priority:2
Process 2
Burst Time:6
Priority:4
Process 3
Burst Time:4
Priority:1
Process 4
Burst Time:2
Priority:3
Process Burst Time Waiting Time Turnaround Time
3 4 0 4
1 3 4 7
4 2 7 9
2 6 9 15
Average Waiting Time=5
Average Turnaround Time=8

RESULT:
Thus the program implement Priority CPU Scheduling was done and executed successfully.

EX: NO:4 d IMPLEMENTATION OF ROUND ROBIN (RR) CPU SCHEDULING


DATE:
AIM:
To implement Round Robin (RR) CPU Scheduling in C language.
ALGORITHM:
 Get the number of process and quantum time.
 Get the CPU burst time and Arrival time for all the processes.
 Calculate the waiting time according to the basic of round robin scheduling (i.e.)
every process that arrives in order and executed a quantum period then the next
processes continues and goes on.
 If the process is not completed the execution within a particular quantum time it
stop the execution and give way to next process execute.
 Calculate the turnaround time.
 Find the average waiting time and average turnaround time.
 Display all the details for each process.
PROGRAM:
#include<stdio.h>
int main( )
{
int count, j, n, time, remain, flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process:\t ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\tTurnaround TimeWaiting Time\n\n");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("%d\t\t%d\t\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-ar/*at[count]*/-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);
return 0;
}
OUTPUT:
Enter Total Process: 5
Enter Arrival Time and Burst Time for Process Process Number 1 :0 10
Enter Arrival Time and Burst Time for Process Process Number 2 :1 1
Enter Arrival Time and Burst Time for Process Process Number 3 :2 2
Enter Arrival Time and Burst Time for Process Process Number 4 :1 1
Enter Arrival Time and Burst Time for Process Process Number 5 :2 5
Enter Time Quantum: 2

Process Turnaround Time Waiting Time

2 2 1
3 3 1
4 5 4
5 13 8
1 19 9

Average Waiting Time= 4.600000


Avg Turnaround Time = 8.400000
RESULT:
Thus the program implement Round Robin (RR) CPU Scheduling was done and executed
successfully.

EX: NO:5 INTER PROCESS COMMUNICATION USING SHARED MEMORY


DATE :

AIM:
To implement interprocess communication using shared memory.
ALGORITHM:
 Create the child process using fork( ).
 Create the shared memory for parent process using shmget( ) system call.
 Now allow the parent process to write in shared memory using shmget pointer which is
return type of shmat( ).
 Now across and attach the same shared memory to the child process.
 The data in the shared memory is read by the child process.
 Now detach and rebase the shared memory.
PROGRAM:
#include<stdio.h>
#include<sys/shm.h>
#include<sys/ipc.h>
void main( )
{
int child,shmid,i;
char *shmptr;
child=fork( );
if(!child)
{
shmid=shmget(2041,32,0666|IPC_CREAT);
shmptr=shmat(shmid,0,0);
printf("\n\tINTERPROCESS COMMUNICATION USING SHARED MEMORY\n");
printf("\n\t*******************************************\n");
printf("\nParent Writing:");
for(i=0;i<25;i++)
{
shmptr[i]='a'+i;
putchar(shmptr[i]);
}
wait(NULL);
}
else
{
shmid=shmget(2041,32,0666);
shmptr=shmat(shmid,0,0);
printf("\n\nChild is Reading:");
for(i=0;i<25;i++)
putchar(shmptr[i]);
printf("\n\n");
shmdt(NULL);
shmctl(shmid,IPC_RMID,NULL);
}
}
OUTPUT:
Child is Reading:abcdefghijklmnopqrstuvwxy
INTERPROCESS COMMUNICATION USING SHARED MEMORY
*******************************************
Parent Writing:abcdefghijklmnopqrstuvwxy

CONCLUSION:
Thus the program to implement the interprocess communication using shared
memory was executed successfully.

EX: NO:6 IMPLEMENTATION OF MUTUAL EXCLUSION BY SEMAPHORE


DATE:
AIM:
To write a program to implement Produce-Consumer relationship using Semaphore.

ALGORITHM:
 Initialize the Semaphore mutex, full & empty.
 In the case of producer process, Produces a value.
i) If there is empty space in the buffer check the mutex value.
ii) If the mutex value is 0, allow the producer to add value to the buffer.
iii) Signal the mutex value and increment the full value by 1.
 In the case of consumer process, Consumes a value
i) If there is any value in the buffer check for mutex value.
ii) If the mutex value is 0, remove value from buffer
iii) Signal the mutex value and increment the empty value by 1.
 Print the result.
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
void producer( );
void consumer( );
int wait(int);
int signal(int);
int mutex=1,full=0,empty=3,x=0;
void main( )
{
int n;
printf("\n1.Producer\n2.Consumer\n3.Exit\n");
while(1)
{
printf("\nEnter your 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("\nProduced value %d",x);
mutex=signal(mutex);
}
void consumer( )
{
mutex=wait(mutex);
full=wait(full);
empty=signal(empty);
printf("\nConsumed value %d",x);
x--;
mutex=signal(mutex);
}
OUTPUT:
1.Producer
2.Consumer
3.Exit

Enter your Choice1


Produced value 1

Enter your Choice1


Produced value 2

Enter your Choice1


Produced value 3

Enter your Choice1


buffer is full

Enter your Choice2


Consumed value 3

Enter your Choice2


Consumed value 2

Enter your Choice2


Consumed value 1

Enter your Choice2


buffer is empty

Enter your Choice3

RESULT:
Thus the above program to implement Produce-Consumer relationship using
Semaphore was done successfully.

EX: NO:7 IMPLEMENTATION OF DEADLOCK AVOIDANCE USING BANKERS ALGORITHM

DATE:

AIM:
To implement Deadlock Avoidance using Banker’s Algorithm in C language.
ALGORITHM:
 Get the number of Processes and Resources.
 Get the Allocation and Max Matrix.
 Get the Available vector.
 Find the Need Matrix using, Need=Max-Allocation
 Use Banker’s Algorithm to check Need<=work is True for all processes.
 If it is true for all process then the system is in safe state. So print the Safe Sequence.
 Otherwise system is not in safe state.
PROGRAM:
#include <stdio.h>
void main( )
{
int n, m, i, j, k, ind = 0;
int alloc[10][10], max[10][10], avail[10], f[n], ans[n];
printf("Enter the No. of Process "); scanf("%d",&n);
printf("Enter the No. of Resources "); scanf("%d",&m);
printf("Enter the values for Allocation Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the values for Max Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&max[i][j]);
}
}
printf("Enter Available vector");
for(i=0;i<m;i++)
{
scanf("%d",&avail[i]);
}
for (k = 0; k < n; k++)
{
f[k] = 0;
}
int need[n][m];
printf("Need Matrix\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
need[i][j] = max[i][j] - alloc[i][j];
printf("%d\t",need[i][j]);
}
printf("\n");
}
int y = 0;
for (k = 0; k < 5; k++)
{
for (i = 0; i < n; i++)
{
if (f[i] == 0)
{
int flag = 0;
for (j = 0; j < m; j++)
{
if (need[i][j] > avail[j])
{
flag = 1;
break;
}
}
if (flag == 0)
{
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
printf("The Safe Sequence is: ");
for (i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}
OUTPUT:
Enter the No. of Process 5
Enter the No. of Resources 3
Enter the values for Allocation Matrix
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2
Enter the values for Max Matrix
7 5 3
3 2 2
9 0 2
2 2 2
4 3 3
Enter Available vector
3 3 2
Need Matrix
7 4 3
1 2 2
6 0 0
0 1 1
4 3 1
The Safe Sequence is: P1 -> P3 -> P4 -> P0 -> P2

RESULT:
Thus the program implement Deadlock Avoidance using Banker’s Algorithm was
done and executed successfully.

EX: NO:8 IMPLEMENTATION OF DEADLOCK DETECTION ALGORITHM

DATE:

AIM:
To implement Deadlock Detection Algorithm in C language.

ALGORITHM:
 Get the number of Processes and Resources.
 Get the Allocation and Request Matrix.
 Get the Available vector.
 Use Deadlock Detection Algorithm to check Request<=work is True for all processes.
 If it is true for all process then the system is in safe state.
 Otherwise system is not in safe state.
PROGRAM:
#include <stdio.h>
void main( )
{
int n, m, i, j, k, y = 0, ind=0;
int alloc[10][10], req[10][10], avail[10], f[n], ans[n];
printf("Enter the No. of Process ");
scanf("%d",&n);
printf("Enter the No. of Resources ");
scanf("%d",&m);
printf("Enter the values for Allocation Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&alloc[i][j]);
}
}
printf("Enter the values for Request Matrix ");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&req[i][j]);
}
}
printf("Enter Available vector");
for(i=0;i<m;i++)
{
scanf("%d",&avail[i]);
}
for (k = 0; k < n; k++)
{
f[k] = 0;
}
for (k = 0; k < 5; k++)
{
for (i = 0; i < n; i++)
{
if (f[i] == 0)
{
int flag = 0;
for (j = 0; j < m; j++)
{
if (req[i][j] > avail[j])
{
flag = 1;
break;
}
}
if (flag == 0)
{
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
printf("The Safe Sequence is: ");
for (i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}
OUTPUT:
Enter the No. of Process 5

Enter the No. of Resources 3

Enter the values for Allocation Matrix


0 1 0
2 0 0
3 0 3
2 1 1
0 0 2

Enter the values for Request Matrix


0 0 0
2 0 2
0 0 0
1 0 0
0 0 2

Enter Available vector


0 0 0

The Safe Sequence is: P0 -> P2 -> P3 -> P4 -> P1

RESULT:
Thus the program implement Deadlock Detection was done and executed
successfully.

EX: NO:9 IMPLEMENTATION OF THREADING


DATE:
AIM:
To write a C program to implement threading.
ALGORITHM:
 Include pthread header file to use pthread Library.
 Include the header file semaphore to do synchronization.
 Initialize binary semaphore “mutex”.
 Create new threads ti and t2 using pthread_create( ).
 Using pthread_join make the threads to run in parallel.
 Display the output.

PROGRAM:
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
sem_t mutex;
static int count;
void* thread(void* arg)
{
sem_wait(&mutex);
count++;
printf("\nThread %d Created",count);
sleep(4);
printf("\nThread %d Exited",count);
sem_post(&mutex);
}
void main( )
{
sem_init(&mutex, 0, 1);
pthread_t t1, t2;
pthread_create(&t1,NULL,thread,NULL);
sleep(2);
pthread_create(&t2,NULL,thread,NULL);
pthread_join(t1,NULL);
pthread_join(t2,NULL);
sem_destroy(&mutex);
}

OUTPUT:
Thread 1 Created
Thread 1 Exited
Thread 2 Created
Thread 2 Exited

RESULT:
Thus the above program to implement threading was done successfully.

EX: NO:10 IMPLEMENTATION OF PAGING MEMORY MANAGEMENT

DATE:

AIM:

To write a program to implement Paging Memory management.


ALGORITHM:

 Declare the needed variables.


 Get the number of Pages.
 Enter the Page size.
 Find the starting address of memory using malloc( ) function.
 Display the Page number and starting address size of the pages.
PROGRAM:

#include<stdio.h>
main()
{
int np,ps,i;
int *sa;
printf("Enter Number of pages: ");
scanf("%d",&np);
printf("Enter Page size: ");
scanf("%d",&ps);
sa=(int*)malloc(2*np);
for(i=0;i<np;i++)
{
sa[i]=(int)malloc(ps);
printf("Page No %d\tAddress - %d\n",i+1,sa[i]);
}
}

OUTPUT:
Enter Number of pages: 5
Enter Page size: 3
Page No 1 Address - 3308800
Page No 2 Address - 3308832
Page No 3 Address - 3308864
Page No 4 Address - 3308896
Page No 5 Address - 3308928

RESULT:
Thus the program to implement Paging Memory management was done successfully.

EX: NO:11 IMPLEMENTATION OF MEMORY MANAGEMENT METHODS

DATE:
AIM:

To write a program to implement Memory Management methods using First Fit, Best Fit
and Worst Fit.

ALGORITHM:

 Get the number of blocks and size of each block as input.

 Get number of files and size of each files as input.

 In best fit, allocate the elements in the smallest hole that is being enough.

 In the first fit, allocate the first hole that is big enough.

 In the worst fit, allocate the largest hole.

 Display the allocation of files in memory block and the remaining amount of memory.

PROGRAM: 11 (a) First Fit

#include<stdio.h>
#define max 25
void main( )
{
int frag[max],b[max],f[max],i,j,nb,nf,temp;
static int bf[max],ff[max];
printf("\nFirst Fit Memory Management");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
{
ff[i]=j;
break;
}
}
}
frag[i]=temp;
bf[ff[i]]=1;
}
printf("\nFile No\tFile Size\tBlock No\tBlock Size\tFragment");
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]);
}

OUTPUT:
First Fit Memory Management
Enter the number of blocks: 3
Enter the number of files: 3

Enter the size of the blocks:


Block 1: 20
Block 2: 50
Block 3: 30
Enter the size of the files:
File 1: 20
File 2: 30
File 3: 20

File No File Size Block No Block Size Fragment


1 20 1 20 0
2 30 2 50 20
3 20 3 30 10

PROGRAM: 11 (b) Best Fit


#include<stdio.h>
#define max 25
void main( )
{
int frag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;
static int bf[max],ff[max];
printf("\nBest Fit Memory Management");
printf("\nEnter the number of blocks:");
scanf("%d",&nb);
printf("Enter the number of files:");
scanf("%d",&nf);
printf("\nEnter the size of the blocks:-\n");
for(i=1;i<=nb;i++)
{
printf("Block %d:",i);
scanf("%d",&b[i]);
}
printf("Enter the size of the files :-\n");
for(i=1;i<=nf;i++)
{
printf("File %d:",i);
scanf("%d",&f[i]);
}
for(i=1;i<=nf;i++)
{
for(j=1;j<=nb;j++)
{
if(bf[j]!=1)
{
temp=b[j]-f[i];
if(temp>=0)
if(lowest>temp)
{
ff[i]=j;
lowest=temp;
}
}
}
frag[i]=lowest;
bf[ff[i]]=1;
lowest=10000;
}
printf("\nFile No\tFile Size\tBlock No\tBlock Size\tFragment");
for(i=1;i<=nf && ff[i]!=0;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);
}

OUTPUT:
Best Fit Memory Management
Enter the number of blocks: 3
Enter the number of files: 3

Enter the size of the blocks:


Block 1: 20
Block 2: 10
Block 3: 40
Enter the size of the files:
File 1: 10
File 2: 20
File 3: 30

File No File Size Block No Block Size Fragment


1 10 2 10 0
2 20 1 20 0
3 30 3 40 10

PROGRAM: 11 (C) Worst Fit


#include<stdio.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];
printf("\nWorst Fit Memory Management");
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\tFragment");
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]);
}

OUTPUT:
Worst Fit Memory Management
Enter the number of blocks: 3
Enter the number of files: 3

Enter the size of the blocks:


Block 1: 30
Block 2: 60
Block 3: 50
Enter the size of the files:
File 1: 20
File 2: 10
File 3: 15

File No File Size Block No Block Size Fragment


1 20 2 60 40
2 10 3 50 40
3 15 1 30 15

RESULT:
Thus the above program to implement Memory Management methods using First Fit,
Best Fit and Worst Fit was done successfully.

EX: NO:12 IMPLEMENTATION OF PAGE REPLACEMENT ALGORITHMS


DATE:

AIM:
To write a program to implement Page Replacement algorithms using FIFO, LRU and
LFU using C Programs.

ALGORITHM:
 Declare the needed variables.
 Get the number of page reference.
 Get the reference string as input.
 Get the number of frames needed.
 Using the page replacement algorithms find the page faults.
 FIFO – Replace the first inserted page.
 LRU – Replace the page that was used most recently.
 LFU – Replace the page that was having least frequency count.
 Finally replace the total number of page faults.

PROGRAM: 12(a) - (First In First Out - FIFO)


#include<stdio.h>
main( )
{
int i, j, k, f, pf=0, count=0, rs[25], m[10], n;
printf("\nEnter the length of reference string ");
scanf("%d",&n);
printf("\nEnter the reference string ");
for(i=0;i<n;i++)
scanf("%d",&rs[i]);
printf("\nEnter no. of frames ");
scanf("%d",&f);
for(i=0;i<f;i++)
m[i]=-1;
printf("\nThe Page Replacement Process is\n");
for(i=0;i<n;i++)
{
for(k=0;k<f;k++)
{
if(m[k]==rs[i])
break;
}
if(k==f)
{
m[count++]=rs[i];
pf++;
}
for(j=0;j<f;j++)
printf("%d\t",m[j]);
printf("\n");
if(count==f)
count=0;
}
printf("\nThe number of Page Faults using FIFO is %d",pf);
}

OUTPUT:
Enter the length of reference string 7
Enter the reference string 1
3
0
3
5
6
3
Enter no. of frames 3
The Page Replacement Process is
1 -1 -1
1 3 -1
1 3 0
1 3 0
5 3 0
5 6 0
5 6 3
The number of Page Faults using FIFO is 6

PROGRAM: 12(b) - Least Recently Used (LRU)


main( )
{
int i, j , k, min, rs[25], m[10], count[10], flag[25], n, f, pf=0, next=1;
printf("Enter the length of reference string ");
scanf("%d",&n);
printf("Enter the reference string ");
for(i=0;i<n;i++)
{
scanf("%d",&rs[i]);
flag[i]=0;
}
printf("Enter the number of frames ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
count[i]=0;
m[i]=-1;
}
printf("\nThe Page Replacement process is \n");
for(i=0;i<n;i++)
{
for(j=0;j<f;j++)
{
if(m[j]==rs[i])
{
flag[i]=1;
count[j]=next;
next++;
}
}
if(flag[i]==0)
{
if(i<f)
{
m[i]=rs[i];
count[i]=next;
next++;
}
else
{
min=0;
for(j=1;j<f;j++)
if(count[min] > count[j])
min=j;
m[min]=rs[i];
count[min]=next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t", m[j]);
printf("\n");
}
printf("\nThe number of page faults using LRU is %d",pf);
}

OUTPUT:
Enter the length of reference string 7
Enter the reference string 1
3
0
3
5
6
3
Enter the number of frames 3
The Page Replacement process is
1 -1 -1
1 3 -1
1 3 0
1 3 0
5 3 0
5 3 6
5 3 6
The number of page faults using LRU is 5

PROGRAM: 12(c) - Least Frequently Used (LFU)


#include<stdio.h>
main( )
{
int rs[50], i, j, k, m, f, cntr[20], a[20], min, pf=0;
printf("\nEnter number of page references ");
scanf("%d",&m);
printf("\nEnter the reference string ");
for(i=0;i<m;i++)
scanf("%d",&rs[i]);
printf("\nEnter the number of frames ");
scanf("%d",&f);
for(i=0;i<f;i++)
{
cntr[i]=0;
a[i]=-1;
}
printf("\nThe Page Replacement Process is \n");
for(i=0;i<m;i++)
{
for(j=0;j<f;j++)
if(rs[i]==a[j])
{
cntr[j]++;
break;
}
if(j==f)
{
min = 0;
for(k=1;k<f;k++)
if(cntr[k]<cntr[min])
min=k;
a[min]=rs[i];
cntr[min]=1;
pf++;
}
for(j=0;j<f;j++)
printf("%d\t",a[j]);
printf("\n");
}
printf("\nThe number of page faults using LFU is %d",pf);
}
OUTPUT:
Enter number of page references 7
Enter the reference string 1
3
0
3
5
6
3
Enter the number of frames 3
The Page Replacement Process is
1 -1 -1
1 3 -1
1 3 0
1 3 0
5 3 0
6 3 0
6 3 0
The number of page faults using LFU is 5

RESULT:
Thus the program to implement Page Replacement algorithms using FIFO, LRU and LFU
was done successfully.

Ex No: 13 IMPLEMENTATION OF FILE ORGANIZATION METHODS


DATE:

AIM:
To write a program to implement different File Organization Methods.

ALGORITHM:
 The directory structure is the organization of files into a hierarchy of folders.
 In a single-level directory system, all the files are placed in one directory called as
root directory.
 In the two-level directory system, each user has own user file directory (UFD). The
system maintains a master block that has one entry for each user. UFD’s present
under the system's master file directory (MFD).
Program: 13(a)- SINGLE LEVEL DIRECTORY STRUCTURE
#include<stdio.h>
#include<stdlib.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir;
void main( )
{
int i,ch;
char f[30];
dir.fcnt = 0;
printf("\nEnter name of directory: ");
scanf("%s", dir.dname);
while(1)
{
printf("\n1. Create File\n2. Display Files\n3. Exit\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter the name of the file: ");
scanf("%s",dir.fname[dir.fcnt]);
dir.fcnt++;
break;
case 2:
if(dir.fcnt==0)
printf("\nDirectory Empty");
else
{
printf("\nThe Files are: ");
for(i=0;i<dir.fcnt;i++)
printf("\t%s",dir.fname[i]);
}
break;
default:
exit(0);
}
}
}

OUTPUT:

Enter name of directory: abcd

1. Create File
2. Display Files
3. Exit
Enter your choice: 1
Enter the name of the file: Flowers

1. Create File
2. Display Files
3. Exit
Enter your choice: 1
Enter the name of the file: Fruits

1. Create File
2. Display Files
3. Exit
Enter your choice: 1
Enter the name of the file: Vegetables

1. Create File
2. Display Files
3. Exit
Enter your choice: 2

The Files are: Flowers Fruits Vegetables

1. Create File
2. Display Files
3. Exit
Enter your choice: 3

Program: 13(b) - TWO LEVEL DIRECTORY STRUCTURE


#include<stdio.h>
#include<stdlib.h>
struct
{
char dname[10],fname[10][10];
int fcnt;
}dir[10];
void main( )
{
int i,ch,dcnt,k;
char f[30], d[30];
dcnt=0;
while(1)
{
printf("\n1. Create Directory\n2. Create File\n3.Display\n4. Exit\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter name of directory: ");
scanf("%s", dir[dcnt].dname);
dir[dcnt].fcnt=0;
dcnt++;
printf("Directory created");
break;
case 2:
printf("\nEnter name of the directory: ");
scanf("%s",d);
for(i=0;i<dcnt;i++)
if(strcmp(d,dir[i].dname)==0)
{
printf("Enter name of the file: ");
scanf("%s",dir[i].fname[dir[i].fcnt]);
dir[i].fcnt++;
printf("File created");
break;
}
if(i==dcnt)
printf("Directory %s not found",d);
break;
case 3:
if(dcnt==0)
printf("\nNo Directory's ");
else
{
printf("\nDirectory\tFiles");
for(i=0;i<dcnt;i++)
{
printf("\n%s\t",dir[i].dname);
for(k=0;k<dir[i].fcnt;k++)
printf("\t%s",dir[i].fname[k]);
}
}
break;
default:
exit(0);
}
}
}

OUTPUT:
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 1
Enter name of directory: One
Directory created

1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 1
Enter name of directory: Two
Directory created

1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 2
Enter name of the directory: One
Enter name of the file: Subjects
File created

1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 2
Enter name of the directory: One
Enter name of the file: Crafts
File created

1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 2
Enter name of the directory: Two
Enter name of the file: Fruits
File created

1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 3
Directory Files
One Subjects Crafts
Two Fruits
1. Create Directory
2. Create File
3.Display
4. Exit
Enter your choice: 4

RESULT:
Thus the program to implement different File Organization methods was done
successfully.

EX: NO:14 IMPLEMENTATION OF FILE ALLOCATION METHODS


DATE:

AIM:

To write a program to implement different File Allocation methods.

ALGORITHM:
 Declare the needed variables.
 Get the number of files
 Get the total no. of blocks that needed for each file.
 Allocate the memory for each file continuously.
 Display the file name, start address and size of the file.

PROGRAM: 14(a) - CONTIGUOUS FILE ALLOCATION


#include<stdio.h>
void main()
{
int i,j,n,block[20],start;
printf("Enter the no. of file:\n");
scanf("%d",&n);
printf("Enter the number of blocks needed for each file:\n");
for(i=0;i<n;i++)
scanf("%d",&block[i]);
start=0;
printf("\tFile name\tStart Block\tSize of file\t\n");
printf("\n\tFile 1\t\t%d\t\t%d\n",start,block[0]);
for(i=2;i<=n;i++)
{
start=start+block[i-2];
printf("\tFile %d\t\t%d\t\t%d\n",i,start,block[i-1]);
}
}
OUTPUT:
Enter the no. of file:
5
Enter the number of blocks needed for each file:
5
3
7
8
10
File name Start Block Size of file
File 1 0 5
File 2 5 3
File 3 8 7
File 4 15 8
File 5 23 10

PROGRAM: 14(b) - INDEXED FILE ALLOCATION


#include<stdio.h>
void main()
{
int i,j,n,index,block[20],start;
char name[10];
printf("Enter File Name");
scanf("%s",name);
printf("Enter the Index Block number:\n");
scanf("%d",&index);
printf("Enter the total number of blocks:\n");
scanf("%d",&n);
printf("Enter the block numbers:\n");
for(i=0;i<n;i++)
scanf("%d",&block[i]);
start=0;
printf("File name is %s\n", name);
printf("Index Block Number is %d\n",index);
printf("File %s is allocated in block numbers\n",name);
for(i=0;i<n;i++)
{
printf("%d-> ",block[i]);
}
}
OUTPUT:
Enter File Name Demo
Enter the Index Block number:
45
Enter the total number of blocks:
5
Enter the block numbers:
23
78
92
345
67
File name is Demo
Index Block Number is 45
File Demo is allocated in block numbers
23-> 78-> 92-> 345-> 67

PROGRAM: 14(C) - LINKED ALLOCATION METHOD


#include<stdio.h>
#include<conio.h>
struct file
{
char fname[10];
int start,size,block[10];
}f[10];
void main( )
{
int i,j,n;
printf("IMPLEMENTATION OF FILE USING LINKED ALLOCATION\n");
printf("==============================================\n");
printf("\nEnter No.of files to be allocated : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter File Name : ");
scanf("%s",&f[i].fname);
printf("\nStarting Block Number for File : %s is: ",f[i].fname);
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
printf("\nEnter No.of Blocks Occupied by File : %s is: ",f[i].fname);
scanf("%d",&f[i].size);
printf("\nEnter the %d blocks to be allocated for File : %s are: ",f[i].size,f[i].fname);
for(j=1;j<=f[i].size;j++)
{
scanf("%d",&f[i].block[j]);
}
printf("**********************\n");
}
printf("FILE NAME\tSTARTING BLOCK\tALLOCATED BLOCKS\n");
printf("=========\t==============\t================\n");
for(i=0;i<n;i++)
{
printf("\n%s\t\t%d\t\t%d\n\n",f[i].fname,f[i].start,f[i].size);
for(j=1;j<f[i].size;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]);
printf("\n\n");
}
}

RESULT:
Thus the program to implement different File Allocation methods was done successfully.

EX: NO:15 IMPLEMENTATION OF VARIOUS DISK SCHEDULING ALGORITHMS


DATE:

AIM:

To write a program to implement different Disk Scheduling Algorithms

ALGORITHM:
 Start the program
 Get the Start head position
 Enter movements
 Process it and display the result
 Stop the program
PROGRAM: 15(a) – FCFS DISK SCHEDULING
#include<stdio.h>
#include<stdlib.h>
void main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
for(i=0;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
printf("Total head moment is %d",TotalHeadMoment);
}
OUTPUT:
Enter the number of Request
8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Total head movement is 644

PROGRAM: 15(b) – SSTF DISK SCHEDULING


#include<stdio.h>
#include<stdlib.h>
void main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
while(count!=n)
{
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{
min=d;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
RQ[index]=1000;
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
}
OUTPUT:
Enter the number of Request
8
Enter Request Sequence
95 180 34 119 11 123 62 64
Enter initial head Position
50
Total head movement is 236
PROGRAM: 15(c) – SCAN DISK SCHEDULING
#include<stdio.h>
#include<stdlib.h>
void main()
{
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(RQ[j]>RQ[j+1])
{
int temp;
temp=RQ[j];
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
}
}
}
int index;
for(i=0;i<n;i++)
{
if(initial<RQ[i])
{
index=i;
break;
}
}
if(move==1)
{
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
TotalHeadMoment=TotalHeadMoment+abs(size-RQ[i-1]-1);
initial = size-1;
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}
else
{
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
initial =0;
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}
printf("Total head movement is %d",TotalHeadMoment);
}
OUTPUT:
Enter the number of Request
8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Enter total disk size
200
Enter the head movement direction for high 1 and for low 0
1
Total head movement is 337

PROGRAM: 15(d) – LOOK DISK SCHEDULING


#include<stdio.h>
#include<stdlib.h>
void main()
{
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(RQ[j]>RQ[j+1])
{
int temp;
temp=RQ[j];
RQ[j]=RQ[j+1];
RQ[j+1]=temp;
}
}
}
int index;
for(i=0;i<n;i++)
{
if(initial<RQ[i])
{
index=i;
break;
}
}
if(move==1)
{
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}
else
{
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}
printf("Total head movement is %d",TotalHeadMoment);
}
OUTPUT:
Enter the number of Request
8
Enter the Requests Sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Enter the head movement direction for high 1 and for low 0
1
Total head movement is 299

RESULT:
Thus the program to implement different disk allocation algorithms was done
successfully.

EX: NO:16 INSTALLATION OF GUEST OPERATING SYSTEM USING VM WARE


DATE:
AIM :
To install Guest Operating system using VM Ware
PROCEDURE
STEPS TO BE FOLLOWED ARE
1. Save the ISO image file in any location accessible to your host. For example:
Windows: C:\Temp or %TEMP%
2. Linux: /tmp or /usr/tmp
Create a new virtual machine. Go to File > New > Virtual Machine.
3. Select Typical to accept Workstation's recommendations for various settings (such as
processors, RAM, and disk controller type). Select Custom if you want to select these options
yourself.
4. On the Guest Operating System Installation screen, when prompted where to install from,
select Installer disc image file (iso).
5. Click Browse, and navigate to the location where you saved the ISO image file.
6. Click Next, and proceed through the new virtual machine wizard.
7. Before you click Finish, to create the virtual machine, deselect Power on this virtual
machine after creation.
8. Edit the virtual machine settings so that its virtual CD/DVD device is configured to use the
ISO image rather than the physical CD/DVD drive:
i. Select the tab for the virtual machine you just created.
ii. Click Edit virtual machine settings.
iii. On the Hardware tab, select the CD/DVD drive.
iv. On the right side:
a. Select Connect at power on.
b. Select Use ISO image file.
c. Click Browse and navigate to where you saved the ISO image file.

RESULT
Thus the VMWare is installed successfully

You might also like