0% found this document useful (0 votes)
16 views94 pages

OS - 2nd Year 4th Sem - Last Sem

The document outlines the installation process for Windows XP, detailing system requirements and step-by-step instructions for installation. It also includes examples of UNIX commands for file management and basic shell programming tasks such as calculating factorials, finding the greatest of two numbers, generating Fibonacci series, and calculating the area and circumference of a circle. Each section concludes with a confirmation of successful execution of the tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views94 pages

OS - 2nd Year 4th Sem - Last Sem

The document outlines the installation process for Windows XP, detailing system requirements and step-by-step instructions for installation. It also includes examples of UNIX commands for file management and basic shell programming tasks such as calculating factorials, finding the greatest of two numbers, generating Fibonacci series, and calculating the area and circumference of a circle. Each section concludes with a confirmation of successful execution of the tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 94

EX.

NO: 1
INSTALLATION OF WINDOWS XP OPERATING SYSTEM

DATE:

Aim:
To install Windows XP 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 Super VGA (800 x 600) or higher resolution


Monitor

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)-1
Illustrate UNIX Commands
DATE:

Aim:
Unix commands for Creating a directory, Creating a file, View the file contents, Word Count in a
file , List the directory, To remove a directory and Remove a file.

To create a directory:
Syntax:
mkdir directory_name
Example:
mkdir iiit

To create a file:
Syntax:
cat >file_name.txt
Example:
cat >newfile.txt
Hello World!
Information Technology
Then press ctrl +c

View the file contents:


Syntax:
cat file_name.txt
Example:
cat newfile.txt
Hello World!
Information Technology

Word Count in a file:


Syntax:
wc file_name.txt
Example:
wc newfile.txt
2 4 36 newfile.txt
 First column shows number of lines present in a five specified, second column shows
number of words present in the file, third column shows number of characters present in a
file and fourth column itself is the file name which are given as argument.
List the directory:
Syntax:
ls
Example:
command.c newfile.txt ls public st.c videos

To remove a directory:
Syntax:
rmdir directory_name
Example:
rmdir iiit

To remove a file:
Syntax:
rm file_name
Example:
rm newfile

Result:
Thus the Unix commands for Creating a directory, Creating a file, View the file contents, Word
Count in a file , List the directory, To remove a directory and Remove a file was executed
successfully and verified.
EX.NO:2(a)-2 UNIX Commands: date, cal, cat

DATE:

Aim:
Illustrate the following UNIX Commands: date, cal, cat

CONTENT:
Note: Syn->Syntax
(a) date –used to check the date and time
Syn:$date

Format Purpose Example Result

+%m To display only month $date+%m 06


+%h To display month name $date+%h June
+%d To display day of month $date+%d O1
+%y To display last two digits of years $date+%y 09
+%H To display hours $date+%H 10
+%M To display minutes $date+%M 45
+%S To display seconds $date+%S 55

b) cal –used to display the calendar Syn:$cal 2 2009

c)cat–this create, view and concatenate files.

Creation:
Syn:$cat>filename

Viewing:
Syn:$cat filename

Add text to an existing file:


Syn:$cat>>filename

Concatenate:
Syn:$catfile1file2>file3
$catfile1file2>>file3 (no over writing of file3)

RESULT:
Thus the UNIX Commands: date, cal, cat was executed successfully and verified.
EX.NO:2(a)-3 UNIX Command to display the date in dd/mm/yyyy format.

DATE:

AIM:

To illustrate the UNIX Command to display the date in dd/mm/yyyy format.

ALGORITHM:

1. Start the command line interface.


2. Execute `date` command with formatting option to display the date in dd/mm/yyyy format.

COMMAND:

date +'%d/%m/%Y'

OUTPUT:

17/06/2024

RESULT:
Thus the UNIX Command to display the date in dd/mm/yyyy format was executed successfully and verified.
EX.NO:2(a)-4 UNIX Command ls with attributes.
DATE:

AIM:

To illustrate the UNIX Command ls with attributes.

ALGORITHM:

1. Start the command line interface.


2. Execute ls command with specific options to display file attributes.

COMMAND:

d)ls

–used to list the files. Your files are kept in a directory.

Syn:$lsls–s

1. ls
- Used to list files in a directory.
2. ls -l
- Detailed listing, provides file statistics.
3. ls -t
- Orders files by creation time.
4. ls -u
- Sorts files by access time (or shows when last accessed, typically used with -l).
5. ls -s
- Orders files by size.
6. ls -r
- Lists files in reverse order.
7. ls -f
- Marks directories with /, executables with *, symbolic links with @, local sockets with =, named pipes
(FIFOs) with |.
8. ls -h
- Human-readable format, shows file sizes in kilobytes and megabytes (can be used together with -l).
9. ls [a-m
- Lists all files whose names begin with alphabets from 'a' to 'm'.
10. ls [a
- Lists all files whose names begin with 'a' or 'A'.
11. ls > mylist
- Redirects the output of the `ls` command to a disk file named 'mylist'.

RESULT:

Thus the UNIX Command ls with attributes was executed successfully.


EX.NO:2(b)-1 FACTORIAL OF A NUMBER

DATE:

AIM:

To Write a Shell program to find the factorial of a number

ALGORITHM:

SEPT 1: Start the program.


STEP 2: Read the value of n.
STEP 3: Calculate „i=expr $n-1‟.
STEP 4: If the value of i is greater than 1 then calculate „n=expr $n \* $i‟ and „i=expr $i – 1‟
STEP 5: Print the factorial of the given number.

PROGRAM:

echo "Enter a Number"


read n
i=`expr $n - 1`
p=1
while [ $i -ge 1 ]
do
n=`expr $n \* $i`
i=`expr $i - 1`
done
echo "The Factorial of the given Number is $n"

OUTPUT:

Enter a Number
5
The Factorial of the given Number is 120

RESULT:

Thus To Write a Shell program to find the factorial of a number was executed successfully and
verified
EX.NO:2(b)-2
GREATEST OF TWO NUMBERS
DATE:

AIM:

To Write a shell program to find greatest of 2 numbers.

ALGORITHM:

 Prompt the user to enter the first number (num1).


 Prompt the user to enter the second number (num2).
 Compare num1 and num2 using conditional statements.
 If num1 is greater than num2, print num1 as the greatest number.
 Otherwise, print num2 as the greatest number (handles equal numbers implicitly).

PROGRAM:

# Prompt user to enter two numbers


echo "Enter the first number:"
read num1

echo "Enter the second number:"


read num2

# Compare the two numbers


if [ $num1 -gt $num2 ]; then
echo "The greatest number is: $num1"
elif [ $num2 -gt $num1 ]; then
echo "The greatest number is: $num2"
else
echo "Both numbers are equal."
fi

OUTPUT:

Enter the first number:


10
Enter the second number:
20
The greatest number is: 20

RESULT:
Thus the program of List ADT is executed and the output is obtained successfully.
EX.NO:2(b)-3
FIBONACCI SERIES
DATE:

AIM:

To Develop a Shell program to generate Fibonacci Series.

ALGORITHM:

 Display a message asking the user to enter the number of terms (n) for the Fibonacci series.
 Initialize variables a = 0 and b = 1 as the first two terms of the Fibonacci series.
 Print "Fibonacci Series:" followed by a.
 Use a loop to iterate num_terms - 1 times:
 Calculate the next Fibonacci term c as the sum of a and b.
 Update a to b and b to c.
 Print b after each calculation.
 Call generate_fibonacci(n) to generate and print the Fibonacci series with n terms.

PROGRAM:

# Function to generate Fibonacci series


generate_fibonacci() {
num_terms=$1

# Initialize first two terms of Fibonacci series


a=0
b=1

# Print first two terms


echo "Fibonacci Series:"
echo -n "$a "

# Loop to generate remaining terms


for (( i=1; i<num_terms; i++ )); do
echo -n "$b "

# Calculate next term


c=$((a + b))
a=$b
b=$c
done

echo # Move to the next line after printing the series


}
# Main program

# Prompt user to enter the number of terms


echo "Enter the number of terms for Fibonacci Series:"
read n

# Call function to generate Fibonacci series


generate_fibonacci $n

OUTPUT:
Enter the number of terms for Fibonacci Series:
10
Fibonacci Series:
0 1 1 2 3 5 8 13 21 34

RESULT:

Thus to Develop a Shell program to generate Fibonacci Series was executed successfully and verified.
EX.NO:
EXNO:2(b)-4

AREA AND CIRCUMFERENCE OF A CIRCLE


DATE:

AIM:
To Develop a Shell program to find area and circumference of a circle.

ALGORITHM:
 Prompt user for radius input.
 Calculate area using 3.14159 * radius * radius.
 Print area result.
 Calculate circumference using 2 * 3.14159 * radius.
 Print circumference result.
 End program execution.

PROGRAM:

# Function to calculate area of circle


calculate_area() {
radius=$1
pi=3.14159

area=$(echo "scale=2; $pi * $radius * $radius" | bc)


echo "Area of the circle with radius $radius is: $area square units"
}

# Function to calculate circumference of circle


calculate_circumference() {
radius=$1
pi=3.14159

circumference=$(echo "scale=2; 2 * $pi * $radius" | bc)


echo "Circumference of the circle with radius $radius is: $circumference units"
}
# Main program

# Prompt user to enter the radius of the circle


echo "Enter the radius of the circle:"
read radius

# Call functions to calculate area and circumference


calculate_area $radius
calculate_circumference $radius

OUTPUT:

Enter the radius of the circle:


5
Area of the circle with radius 5 is: 78.54 square units
Circumference of the circle with radius 5 is: 31.42 units

RESULT:

Thus To Develop a Shell program to find area and circumference of a circle.


EXNO:2(b)-5
AREA OF A TRIANGLE

DATE:

AIM:

To Develop a Shell program to find Area of a Triangle.

ALGORITHM:

 Prompt user for base of the triangle.


 Prompt user for height of the triangle.
 Calculate area using the formula area=1/2×base×height
 Print the calculated area with appropriate units.
 End program execution.

PROGRAM:

# Function to calculate area of triangle


calculate_area() {
base=$1
height=$2

area=$(echo "scale=2; 0.5 * $base * $height" | bc)


echo "Area of the triangle with base $base units and height $height units is: $area square units"
}

# Main program

# Prompt user to enter the base and height of the triangle


echo "Enter the base of the triangle:"
read base

echo "Enter the height of the triangle:"


read height

# Call function to calculate area


calculate_area $base $height
OUTPUT:

Enter the base of the triangle:


6
Enter the height of the triangle:
4
Area of the triangle with base 6 units and height 4 units is: 12.00 square units

RESULT:

Thus To Develop a Shell program to find Area of a Triangle was executed successfully.
EXNO:2(b)-6
CELSIUS TO FAHRENHEIT

DATE:

AIM:
To Develop a Shell program to convert Celsius to Fahrenheit

ALGORITHM:
 Prompt user for temperature in Celsius.
 Convert Celsius to Fahrenheit using the formula fahrenheit=(9/5)*Celsius +32
 Print the converted temperature in Fahrenheit with appropriate units.
 End program execution.

PROGRAM:

# Function to convert Celsius to Fahrenheit


convert_celsius_to_fahrenheit() {
celsius=$1

# Perform the conversion using bc for floating point arithmetic


fahrenheit=$(echo "scale=2; (9/5) * $celsius + 32" | bc)
echo "$celsius°C is equal to $fahrenheit°F"
}

# Main program

# Prompt user to enter temperature in Celsius


echo "Enter temperature in Celsius:"
read celsius

# Call function to convert Celsius to Fahrenheit


convert_celsius_to_fahrenheit $celsius
OUTPUT:

Enter temperature in Celsius:


25
25°C is equal to 77.00°F

Result:

Thus the Shell program to convert Celsius to Fahrenheit wa executed successfully and verified.
EX.NO:2(b)-7

DATE: ARMSTRONG NUMBER

AIM:
Develop a Shell program to find whether given number is Armstrong.

ALGORITHM:
1 Prompt user for a number.
2 Initialize variables: num to store the entered number, original_num to store the original number for
comparison, sum to store the sum of the digits raised to the power of the number of digits (num_of_digits).
3 Calculate num_of_digits as the number of digits in num.
4 Use a loop to extract each digit from num, compute its power using num_of_digits, and accumulate the
sum (sum).
5 Compare sum with original_num:
If they are equal, print that original_num is an Armstrong number.
Otherwise, print that original_num is not an Armstrong number.
6 End program execution.

PROGRAM:

# Function to check if a number is Armstrong


is_armstrong() {
num=$1
original_num=$num
sum=0
num_of_digits=${#num}

while [ $num -gt 0 ]; do


digit=$((num % 10))
sum=$((sum + digit**num_of_digits))
num=$((num / 10))
done

if [ $sum -eq $original_num ]; then


echo "$original_num is an Armstrong number."
else
echo "$original_num is not an Armstrong number."
fi
}
# Main program

# Prompt user to enter a number


echo "Enter a number:"
read number

# Call function to check if the number is Armstrong


is_armstrong $number

OUTPUT:
Enter a number:
153
153 is an Armstrong number.

RESULT:

Thus the Shell program to find whether given number is Armstrong was executed successfully and verified.
EX.NO:2(b)-8

DATE: NUMBER IDENTIFICATION

AIM:
Develop a Shell program to find whether given number is positive or negative.

ALGORITHM:
Prompt user for a number.
Define a function check_number(num) that:
Accepts a parameter num.
Checks if num is greater than 0:
If true, print "num is positive."
Checks if num is less than 0:
If true, print "num is negative."
If both conditions are false (i.e., num is 0), print "num is zero."
End program execution.

PROGRAM:
#!/bin/bash

# Function to check if a number is positive, negative, or zero


check_number() {
num=$1

if [ $num -gt 0 ]; then


echo "$num is positive."
elif [ $num -lt 0 ]; then
echo "$num is negative."
else
echo "$num is zero."
fi
}

# Main program

# Prompt user to enter a number


echo "Enter a number:"
read number

# Call function to check if the number is positive, negative, or zero


check_number $number
OUTPUT:
Enter a number:
10
10 is positive.

RESULT:
Thus the Shell program to find whether given number is positive or negative was executed successfully and
verified.
EX.NO:2(b)-9
PRIME NUMBER
DATE:

AIM:
Develop a Shell program to find whether given number is Prime.

ALGORITHM:
1 Prompt user for a number.
2 Define a function is_prime(num) that:
3 Accepts a parameter num.
4 Initializes is_prime to true.
5 Checks if num is less than or equal to 1:
6 If true, set is_prime to false.
7 Use a loop to check for factors from 2 up to the square root of num:
8 If num modulo i is 0 (i.e., num is divisible by i), set is_prime to false and break the loop.
9 Check the value of is_prime:
10 If true, print "num is a prime number."
11 Otherwise, print "num is not a prime number."
12 End program execution.

PROGRAM:

# Function to check if a number is prime


is_prime() {
num=$1
is_prime=true

if [ $num -le 1 ]; then


is_prime=false
fi

# Check for factors from 2 to sqrt(num)


for (( i=2; i*i<=num; i++ )); do
if [ $((num % i)) -eq 0 ]; then
is_prime=false
break
fi
done
if [ $is_prime = true ]; then
echo "$num is a prime number."
else
echo "$num is not a prime number."
fi
}
# Main program

# Prompt user to enter a number


echo "Enter a number:"
read number

# Call function to check if the number is prime


is_prime $number

OUTPUT:
Enter a number:
17
17 is a prime number.

RESULT:

Thus the Shell program to find whether given number is Prime was executed successfully and verified.
EX.NO:2(b)-10
DATE AND TIME
DATE:

AIM:
Write a shell program to display date with time.

ALGORITHM:

1 Get the current date and time using the date command with the format "+%Y-%m-%d
%H:%M:%S".
2 Store the result in current_datetime.
3 Print current_datetime with a message indicating it represents the current date and time.
4 End program execution.

PROGRAM:

# Display current date with time


current_datetime=$(date "+%Y-%m-%d %H:%M:%S")
echo "Current date and time: $current_datetime"

OUTPUT:
Current date and time: 2024-06-18 09:30:15

RESULT:
Thus the shell program to display date with time.
EX.NO : 3(a) System Calls: Fork(), Getpid()

DATE:

AIM:
Illustrate the following System Calls: Fork(),Getpid()

ALGORITHM:
STEP 1: Start the program.
STEP 2: Declare the variables pid,pid1,pid2.
STEP 3: Call fork() system call to create process.
STEP 4: If pid==-1, exit.
STEP 5: Ifpid!=-1 , get the process id using getpid().
STEP 6: Print the process id.
STEP 7:Stop the program

PROGRAM:
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h> // Need to include stdlib.h for exit()

int main()
{
int pid, pid1, pid2;
pid = fork();
if (pid == -1)
{
printf("ERROR IN PROCESS CREATION \n");
exit(1);
}
if (pid != 0)
{
pid1 = getpid();
printf("\nThe parent process ID is %d\n", pid1);
}
else
{
pid2 = getpid();
printf("\nThe child process ID is %d\n", pid2);
}
return 0;
}
OUTPUT:

The parent process ID is 1234


The child process ID is 1235

RESULT:

Thus, the programs for Word Count in a File and List the Directory were executed successfully and verified.
EX.NO:3(b)
WAIT( ) AND EXIT( ) SYSTEM CALLS

DATE:

AIM:
To develop a C program to implement `wait()` and `exit()` system calls.

ALGORITHM:
1. Start the process
2. Create a child process using `fork()`.
3. In the child process, use `printf()` to display a message and call `exit()`.
4. In the parent process, use `wait()` to wait for the child process to terminate.
5. Display a message after the child process has exited.
6. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
pid_t pid = fork(); // Create a new process

if (pid < 0) { // Error in fork


perror("Fork failed");
return 1;
}

if (pid == 0) { // Child process


printf("Child process: Hello, I am the child process.\n");
exit(0); // Child process exits
} else { // Parent process
wait(NULL); // Parent process waits for the child to terminate
printf("Parent process: Child has terminated.\n");
}

return 0;
}

OUTPUT:
Child process: Hello, I am the child process.
Parent process: Child has terminated.

RESULT:
Thus, the C program to implement `wait()` and `exit()` system calls was executed successfully and verified.
EX.NO:4(a)
SINGLE LEVEL DIRECTORY

DATE:

AIM:
To develop a C program to implement a Single Level Directory.

ALGORITHM:
1. Start the process.
2. Define constants for maximum files and filename length.
3. Create a `File` structure to store filenames.
4. Create a function `createFile` to add new files to the directory.
5. Create a function `listFiles` to display all files in the directory.
6. In the `main` function, provide a menu to create files, list files, or exit the program.
7. Implement user input to perform the desired operations.
8.Stop the process.

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

#define MAX_FILES 100


#define MAX_FILENAME_LENGTH 100

typedef struct {
char filename[MAX_FILENAME_LENGTH];
} File;

File directory[MAX_FILES];
int file_count = 0;

void createFile(char *filename) {


if (file_count < MAX_FILES) {
strcpy(directory[file_count].filename, filename);
file_count++;
printf("File '%s' created successfully.\n", filename);
} else {
printf("Directory is full. Cannot create more files.\n");
}
}

void listFiles() {
if (file_count == 0) {
printf("No files in the directory.\n");
} else {
printf("Files in the directory:\n");
for (int i = 0; i < file_count; i++) {
printf("%s\n", directory[i].filename);
}
}
}
int main() {
int choice;
char filename[MAX_FILENAME_LENGTH];
while (1) {
printf("\n1. Create File\n2. List Files\n3. Exit\nEnter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter filename: ");
scanf("%s", filename);
createFile(filename);
break;
case 2:
listFiles();
break;
case 3:
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}

return 0;
}

OUTPUT:
1. Create File
2. List Files
3. Exit
Enter your choice: 1
Enter filename: file1.txt
File 'file1.txt' created successfully.

1. Create File
2. List Files
3. Exit
Enter your choice: 1
Enter filename: file2.txt
File 'file2.txt' created successfully.

1. Create File
2. List Files
3. Exit
Enter your choice: 2
Files in the directory:
file1.txt
file2.txt

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

RESULT:
Thus, the C program to implement a Single Level Directory was executed successfully and verified.
EX.NO:4(b)
TWO-LEVEL DIRECTORY
DATE:

AIM:
To develop a simple C program to implement a Two-Level Directory.

ALGORITHM:
1. Start the process.
2. Define constants for maximum users, files per user, and filename length.
3. Create a structure `User` to store user names and their files.
4. Create a function `createUser` to add new users.
5. Create a function `createFile` to add new files to a user
6. Create a function `listFiles` to display all files for a specific user.
7. In the `main` function, provide a menu to create users, create files, list files, or exit the program.
8. Implement user input to perform the desired operations.
9. Stop the process.

PROGRAM:
#include <stdio.h>
#include <string.h>
#define MAX_USERS 10
#define MAX_FILES_PER_USER 10
#define MAX_NAME_LENGTH 100
typedef struct {
char username[MAX_NAME_LENGTH];
char files[MAX_FILES_PER_USER][MAX_NAME_LENGTH];
int file_count;
} User;
User users[MAX_USERS];
int user_count = 0;
void createUser(char *username) {
strcpy(users[user_count].username, username);
users[user_count].file_count = 0;
user_count++;
printf("User '%s' created successfully.\n", username);
}
void createFile(char *username, char *filename) {
for (int i = 0; i < user_count; i++) {
if (strcmp(users[i].username, username) == 0) {
strcpy(users[i].files[users[i].file_count], filename);
users[i].file_count++;
printf("File '%s' created for user '%s' successfully.\n", filename, username);
return;
}
}
printf("User '%s' not found.\n", username);
}
void listFiles(char *username) {
for (int i = 0; i < user_count; i++) {
if (strcmp(users[i].username, username) == 0) {
printf("Files for user '%s':\n", username);
for (int j = 0; j < users[i].file_count; j++) {
printf("%s\n", users[i].files[j]);
}
return;
}
}
printf("User '%s' not found.\n", username);
}

int main() {
int choice;
char username[MAX_NAME_LENGTH], filename[MAX_NAME_LENGTH];

while (1) {
printf("\n1. Create User\n2. Create File\n3. List Files\n4. Exit\nEnter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
printf("Enter username: ");
scanf("%s", username);
createUser(username);
break;
case 2:
printf("Enter username: ");
scanf("%s", username);
printf("Enter filename: ");
scanf("%s", filename);
createFile(username, filename);
break;
case 3:
printf("Enter username: ");
scanf("%s", username);
listFiles(username);
break;
case 4:
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}

return 0;
}
OUTPUT:
1. Create User
2. Create File
3. List Files
4. Exit
Enter your choice: 1
Enter username: user1
User 'user1' created successfully.

1. Create User
2. Create File
3. List Files
4. Exit
Enter your choice: 2
Enter username: user1
Enter filename: file1.txt
File 'file1.txt' created for user 'user1' successfully.

1. Create User
2. Create File
3. List Files
4. Exit
Enter your choice: 3
Enter username: user1
Files for user 'user1':
file1.txt

1. Create User
2. Create File
3. List Files
4. Exit
Enter your choice: 4

RESULT:
Thus, the C program to implement a Two-Level Directory was executed successfully and verified.
EX.NO:4(c)
HIERARCHICAL DIRECTORY
DATE:

AIM:
To develop a simple C program to implement a Hierarchical Directory.

ALGORITHM:
1. Start the process.
2. Define constants for maximum directories, subdirectories, and filename length.
3. Create structures `Directory` to store directory names and files.
4. Create functions to add directories, subdirectories, and list contents.
5. In the `main` function, provide a menu to perform these operations.
6. Stop the process.

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

#define MAX_FILES 10
#define MAX_DIRS 10
#define MAX_NAME_LENGTH 100

typedef struct Directory {


char name[MAX_NAME_LENGTH];
char files[MAX_FILES][MAX_NAME_LENGTH];
struct Directory *subdirs[MAX_DIRS];
int file_count;
int subdir_count;
} Directory;

Directory root = {"root", {}, {}, 0, 0};

void createDirectory(Directory *parent, char *name) {


Directory *newDir = &parent->subdirs[parent->subdir_count++];
strcpy(newDir->name, name);
newDir->file_count = 0;
newDir->subdir_count = 0;
printf("Directory '%s' created.\n", name);
}

void createFile(Directory *dir, char *name) {


strcpy(dir->files[dir->file_count++], name);
printf("File '%s' created in '%s'.\n", name, dir->name);
}

void listContents(Directory *dir) {


printf("Contents of '%s':\n", dir->name);
for (int i = 0; i < dir->file_count; i++) printf("File: %s\n", dir->files[i]);
for (int i = 0; i < dir->subdir_count; i++) printf("Dir: %s\n", dir->subdirs[i]->name);
}
int main() {
int choice;
char name[MAX_NAME_LENGTH];
Directory *current = &root;
while (1) {
printf("\n1. Create Directory\n2. Create File\n3. List Contents\n4. Exit\nChoice: ");
scanf("%d", &choice);
if (choice == 1) {
printf("Enter directory name: ");
scanf("%s", name);
createDirectory(current, name);
} else if (choice == 2) {
printf("Enter file name: ");
scanf("%s", name);
createFile(current, name);
} else if (choice == 3) {
listContents(current);
} else if (choice == 4) {
break;
} else {
printf("Invalid choice.\n");
}
}
return 0;
}
OUTPUT:
1. Create Directory
2. Create File
3. List Contents
4. Exit
Choice: 1
Enter directory name: dir1
Directory 'dir1' created.

1. Create Directory
2. Create File
3. List Contents
4. Exit
Choice: 2
Enter file name: file1.txt
File 'file1.txt' created in 'root'.

1. Create Directory
2. Create File
3. List Contents
4. Exit
Choice: 3
Contents of 'root':
File: file1.txt
Dir: dir1

1. Create Directory
2. Create File
3. List Contents
4. Exit
Choice: 4

RESULT:
Thus, the C program to implement a Hierarchical Directory was executed successfully and verified.
EX.NO:5
INTER-PROCESS COMMUNICATION (IPC)
DATE:

AIM:
To develop a C program to implement Inter-Process Communication (IPC) using shared
memory, with an increase in complexity and size.

ALGORITHM:
1. Start the process
2. Create a shared memory segment
3. Attach the shared memory to both processes
4. Write data to the shared memory from the child process
5. Read and modify data from the shared memory in the parent process
6. Detach and remove the shared memory segment
7. Stop the process

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
key_t key = ftok("shmfile", 65);
int shmid = shmget(key, 1024, 0666 | IPC_CREAT);
char *str = (char *) shmat(shmid, (void *) 0, 0);

if (fork() == 0) { // Child process


printf("Child process writing to shared memory...\n");
strcpy(str, "Hello from child");
printf("Child process wrote: %s\n", str);
shmdt(str);
} else { // Parent process
wait(NULL);
printf("Parent process reading from shared memory...\n");
printf("Parent process read: %s\n", str);
strcat(str, " and parent");
printf("Parent process modified to: %s\n", str);
shmdt(str);
shmctl(shmid, IPC_RMID, NULL);
}
return 0;
}
OUTPUT:

Child process writing to shared memory...


Child process wrote: Hello from child
Parent process reading from shared memory...
Parent process read: Hello from child
Parent process modified to: Hello from child and parent

RESULT:
Thus, the C program to implement IPC using shared memory was executed successfully and verified.
EX.NO:6
BANKER'S ALGORITHM
DATE:

AIM:
To develop a C program to implement the Banker's Algorithm for deadlock avoidance, with input taken
from the user.
ALGORITHM:
1. Start the process
2. Initialize the resources, maximum, and allocation matrices from user input
3. Calculate the need matrix
4. Check if the system is in a safe state
5. Stop the process

PROGRAM:
#include <stdio.h>
#include <stdbool.h>
#define P 5 // Number of processes
#define R 3 // Number of resources
int available[R];
int maximum[P][R];
int allocation[P][R];
int need[P][R];
void calculateNeed() {
for (int i = 0; i < P; i++)
for (int j = 0; j < R; j++)
need[i][j] = maximum[i][j] - allocation[i][j];
}
bool isSafe() {
int work[R];
bool finish[P] = {0};
for (int i = 0; i < R; i++)
work[i] = available[i];
while (1) {
bool found = false;
for (int i = 0; i < P; i++) {
if (!finish[i]) {
bool possible = true;
for (int j = 0; j < R; j++)
if (need[i][j] > work[j]) {
possible = false;
break;
}
if (possible) {
for (int k = 0; k < R; k++)
work[k] += allocation[i][k];
finish[i] = true;
found = true;
}
}
}
if (!found)
break;
}
for (int i = 0; i < P; i++)
if (!finish[i])
return false;

return true;
}

int main() {
printf("Enter the number of resources: ");
for (int i = 0; i < R; i++)
scanf("%d", &available[i]);

printf("Enter the maximum resource matrix:\n");


for (int i = 0; i < P; i++)
for (int j = 0; j < R; j++)
scanf("%d", &maximum[i][j]);

printf("Enter the allocation resource matrix:\n");


for (int i = 0; i < P; i++)
for (int j = 0; j < R; j++)
scanf("%d", &allocation[i][j]);

calculateNeed();

if (isSafe())
printf("The system is in a safe state.\n");
else
printf("The system is not in a safe state.\n");

return 0;
}

OUTPUT:
Enter the number of resources: 3 3 2
Enter the maximum resource matrix:
753
322
902
222
433
Enter the allocation resource matrix:
010
200
302
211
002
The system is in a safe state.

RESULT:
Thus, the C program to implement the Banker's Algorithm with user input was executed successfully and verified
EX.NO:7
PAGING
DATE:

AIM:
To develop a C program to implement the Paging technique for memory management.

ALGORITHM:
1. Start the process.
2. Declare and initialize variables for page number, frame number, page table, and process size.
3. Read the process size and page size.
4. Calculate the number of pages required.
5. Simulate the mapping of pages to frames using a page table.
6. Translate logical addresses to physical addresses using the page table.
7. Stop the process

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

int main() {
int processSize, pageSize, numPages, logicalAddress;
int pageTable[100];

printf("Enter process size (in KB): ");


scanf("%d", &processSize);

printf("Enter page size (in KB): ");


scanf("%d", &pageSize);

numPages = (processSize + pageSize - 1) / pageSize; // Calculate the number of pages


printf("Number of pages required: %d\n", numPages);

// Generate a page table with random frame numbers for simplicity


for (int i = 0; i < numPages; i++) {
pageTable[i] = rand() % 100; // Assuming 100 frames available
printf("Page %d -> Frame %d\n", i, pageTable[i]);
}
printf("Enter a logical address to translate (0 to %d): ", processSize - 1);
scanf("%d", &logicalAddress);

int pageNumber = logicalAddress / pageSize;


int offset = logicalAddress % pageSize;

if (pageNumber >= numPages) {


printf("Invalid logical address.\n");
} else {
int frameNumber = pageTable[pageNumber];
int physicalAddress = frameNumber * pageSize + offset;
printf("Logical address %d -> Physical address %d\n", logicalAddress, physicalAddress);
}

return 0;
}
OUTPUT:

Enter process size (in KB): 1024


Enter page size (in KB): 256
Number of pages required: 4
Page 0 -> Frame 45
Page 1 -> Frame 12
Page 2 -> Frame 78
Page 3 -> Frame 56
Enter a logical address to translate (0 to 1023): 300
Logical address 300 -> Physical address 4700

RESULT:
Thus, the C program to implement the Paging technique for memory management was executed
successfully and verified.
EX.NO:8(a)
SEQUENTIAL FILE ALLOCATION
DATE:

AIM:
To develop a C program to implement the Sequential File Allocation method.

ALGORITHM:
1. Start the process
2. Declare and initialize variables for files, their starting blocks, and lengths
3. Read the number of files and their corresponding details (starting block and length
4. Allocate the blocks sequentially for each file
5. Display the file allocation details
6. Stop the process

PROGRAM:
#include <stdio.h>

#define MAX_FILES 10

typedef struct {
int start;
int length;
} File;

int main() {
File files[MAX_FILES];
int numFiles;

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


scanf("%d", &numFiles);

for (int i = 0; i < numFiles; i++) {


printf("Enter the starting block and length of file %d: ", i + 1);
scanf("%d %d", &files[i].start, &files[i].length);
}

printf("\nFile Allocation Table:\n");


printf("File\tStart\tLength\tBlocks\n");
for (int i = 0; i < numFiles; i++) {
printf("%d\t%d\t%d\t", i + 1, files[i].start, files[i].length);
for (int j = 0; j < files[i].length; j++) {
printf("%d ", files[i].start + j);
}
printf("\n");
}

return 0;
}
OUTPUT:
Enter the number of files: 3
Enter the starting block and length of file 1: 0 5
Enter the starting block and length of file 2: 5 3
Enter the starting block and length of file 3: 8 4

File Allocation Table:


File Start Length Blocks
1 0 5 01234
2 5 3 567
3 8 4 8 9 10 11

RESULT:
Thus the C program to implement the Sequential file allocation method was executed successfully and verified.
EX.NO:8(b)
INDEXED FILE ALLOCATION METHOD

DATE:
AIM:
To develop a C program to implement the Indexed File Allocation method.

ALGORITHM:
1. Start the process.
2. Declare and initialize variables for files, their index blocks, and block arrays.
3. Read the number of files and their corresponding index block and allocated blocks.
4. Allocate the blocks using the index block for each file.
5. Display the file allocation details.
6. Stop the process.

PROGRAM:
#include <stdio.h>
#define MAX_FILES 10
#define MAX_BLOCKS 10
typedef struct {
int indexBlock;
int blocks[MAX_BLOCKS];
int numBlocks;
} File;
int main() {
File files[MAX_FILES];
int numFiles;
printf("Enter the number of files: ");
scanf("%d", &numFiles);
for (int i = 0; i < numFiles; i++) {
printf("Enter the index block of file %d: ", i + 1);
scanf("%d", &files[i].indexBlock);
printf("Enter the number of blocks allocated to file %d: ", i + 1);
scanf("%d", &files[i].numBlocks);

printf("Enter the blocks allocated to file %d: ", i + 1);


for (int j = 0; j < files[i].numBlocks; j++) {
scanf("%d", &files[i].blocks[j]);
}
}
printf("\nFile Allocation Table:\n");
printf("File\tIndex\tBlocks\n");
for (int i = 0; i < numFiles; i++) {
printf("%d\t%d\t", i + 1, files[i].indexBlock);
for (int j = 0; j < files[i].numBlocks; j++) {
printf("%d ", files[i].blocks[j]);
}
printf("\n");
}
return 0;
}
OUTPUT:
Enter the number of files: 2
Enter the index block of file 1: 10
Enter the number of blocks allocated to file 1: 3
Enter the blocks allocated to file 1: 5 9 15
Enter the index block of file 2: 20
Enter the number of blocks allocated to file 2: 2
Enter the blocks allocated to file 2: 12 18

File Allocation Table:


File Index Blocks
1 10 5 9 15
2 20 12 18

RESULT:
Thus, the C program to implement the Indexed File Allocation method was executed successfully and verified.
EX.NO:9
SEMAPHORE
DATE:

AIM:
To develop a C program to implement semaphore for synchronizing access to a shared resource.

ALGORITHM:
1. Start the process.
2. Initialize the semaphore.
3. Create multiple threads that will access the shared resource.
4. Use `sem_wait()` to decrease the semaphore value before accessing the resource
5. Access the shared resource.
6. Use `sem_post()` to increase the semaphore value after accessing the resource.
7. Join all threads and destroy the semaphore.
8. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#define NUM_THREADS 5
sem_t semaphore;
void* thread_function(void* arg) {
int thread_num = *(int*)arg;
printf("Thread %d: Waiting to enter critical section...\n", thread_num);

sem_wait(&semaphore); // Decrease the semaphore value


printf("Thread %d: Entered critical section.\n", thread_num);
sleep(1); // Simulate some work in the critical section
printf("Thread %d: Exiting critical section.\n", thread_num);
sem_post(&semaphore); // Increase the semaphore value
free(arg);
return NULL;
}
int main() {
pthread_t threads[NUM_THREADS];

// Initialize semaphore with a value of 1 (binary semaphore)


sem_init(&semaphore, 0, 1);

for (int i = 0; i < NUM_THREADS; i++) {


int* thread_num = malloc(sizeof(int));
*thread_num = i + 1;
pthread_create(&threads[i], NULL, thread_function, thread_num);
}
for (int i = 0; i < NUM_THREADS; i++) {
pthread_join(threads[i], NULL);
}

// Destroy the semaphore


sem_destroy(&semaphore);

return 0;
}

OUTPUT:
Thread 1: Waiting to enter critical section...
Thread 1: Entered critical section.
Thread 2: Waiting to enter critical section...
Thread 3: Waiting to enter critical section...
Thread 4: Waiting to enter critical section...
Thread 5: Waiting to enter critical section...
Thread 1: Exiting critical section.
Thread 2: Entered critical section.
Thread 2: Exiting critical section.
Thread 3: Entered critical section.
Thread 3: Exiting critical section.
Thread 4: Entered critical section.
Thread 4: Exiting critical section.
Thread 5: Entered critical section.
Thread 5: Exiting critical section.

RESULT:
Thus, the C program to implement semaphore for synchronizing access to a shared resource was executed
successfully and verified.
EX.NO:10
THREADING
DATE:

AIM:
To develop a C program to implement threading for concurrent execution.

ALGORITHM:
1. Start the process.
2. Initialize thread attributes.
3. Create multiple threads that will execute concurrently.
4. Define the function to be executed by each thread.
5. Wait for all threads to complete using `pthread_join()`.
6. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#define NUM_THREADS 5
void* thread_function(void* arg) {
int thread_num = *(int*)arg;
printf("Thread %d: Starting execution.\n", thread_num);
sleep(1); // Simulate some work
printf("Thread %d: Finishing execution.\n", thread_num);
free(arg);
return NULL;
}
int main() {
pthread_t threads[NUM_THREADS];

for (int i = 0; i < NUM_THREADS; i++) {


int* thread_num = malloc(sizeof(int));
*thread_num = i + 1;
if (pthread_create(&threads[i], NULL, thread_function, thread_num) != 0) {
perror("Failed to create thread");
return 1;
}
}
for (int i = 0; i < NUM_THREADS; i++) {
pthread_join(threads[i], NULL);
}
printf("All threads have finished execution.\n");
return 0;
}
OUTPUT:
Thread 1: Starting execution.
Thread 2: Starting execution.
Thread 3: Starting execution.
Thread 4: Starting execution.
Thread 5: Starting execution.
Thread 1: Finishing execution.
Thread 2: Finishing execution.
Thread 3: Finishing execution.
Thread 4: Finishing execution.
Thread 5: Finishing execution.
All threads have finished execution.

RESULT:
Thus, the C program to implement threading for concurrent execution was executed successfully
and verified.
EX.NO:11
DEADLOCK DETECTION ALGORITHM
DATE:

AIM:
To develop a C program to implement the Deadlock Detection algorithm.

ALGORITHM:
1. Start the process.
2. Initialize the resources, allocation, and request matrices from user input.
3. Calculate the work and finish vectors.
4. Check if any processes can be completed.
5. Mark the processes that can finish and update the work vector.
6. If all processes can finish, no deadlock exists. Otherwise, deadlock is detected.
7. Stop the process.

PROGRAM:

#include <stdio.h>
#include <stdbool.h>

#define P 5 // Number of processes


#define R 3 // Number of resources

void getInput(int allocation[P][R], int request[P][R], int available[R]) {


printf("Enter the allocation matrix:\n");
for (int i = 0; i < P; i++) {
for (int j = 0; j < R; j++) {
scanf("%d", &allocation[i][j]);
}
}

printf("Enter the request matrix:\n");


for (int i = 0; i < P; i++) {
for (int j = 0; j < R; j++) {
scanf("%d", &request[i][j]);
}
}

printf("Enter the available resources:\n");


for (int i = 0; i < R; i++) {
scanf("%d", &available[i]);
}
}
bool deadlockDetection(int allocation[P][R], int request[P][R], int available[R]) {
int work[R];
bool finish[P] = {false};

for (int i = 0; i < R; i++) {


work[i] = available[i];
}

while (1) {
bool found = false;
for (int i = 0; i < P; i++) {
if (!finish[i]) {
bool canFinish = true;
for (int j = 0; j < R; j++) {
if (request[i][j] > work[j]) {
canFinish = false;
break;
}
}

if (canFinish) {
for (int k = 0; k < R; k++) {
work[k] += allocation[i][k];
}
finish[i] = true;
found = true;
}
}
}

if (!found) {
break;
}
}

for (int i = 0; i < P; i++) {


if (!finish[i]) {
return true; // Deadlock detected
}
}

return false; // No deadlock


}

int main() {
int allocation[P][R], request[P][R], available[R];

getInput(allocation, request, available);

if (deadlockDetection(allocation, request, available)) {


printf("Deadlock detected.\n");
} else {
printf("No deadlock detected.\n");
}

return 0;
}
OUTPUT:
Enter the allocation matrix:
010
200
303
211
002
Enter the request matrix:
000
202
000
100
002
Enter the available resources:
000

Deadlock detected.

RESULT:
Thus, the C program to implement the Deadlock Detection algorithm was executed successfully and verified
EX.NO:12(a)
FCFS CPU SCHEDULING
DATE:

AIM:
To develop a C program to implement FCFS CPU scheduling and calculate average waiting time and
turnaround time based on user input.

ALGORITHM:
1. Start the process.
2. Read the number of processes and their details (arrival time and burst time) from the user.
3. Sort the processes based on their arrival time (if not already sorted).
4. Calculate waiting time and turnaround time for each process.
5. Compute the average waiting time and average turnaround time.
6. Display the results.
7. Stop the process.

PROGRAM:

#include <stdio.h>
#include <stdlib.h>

struct Process {
int pid;
int arrival_time;
int burst_time;
};

void calculateTimes(struct Process processes[], int n) {


int completion_time[n];
int waiting_time[n];
int turnaround_time[n];

// Calculate completion times


completion_time[0] = processes[0].burst_time;
for (int i = 1; i < n; i++) {
completion_time[i] = completion_time[i - 1] + processes[i].burst_time;
}

// Calculate turnaround times and waiting times


for (int i = 0; i < n; i++) {
turnaround_time[i] = completion_time[i] - processes[i].arrival_time;
waiting_time[i] = turnaround_time[i] - processes[i].burst_time;
}

// Print processes along with their times


printf("\nProcess\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time\n");
for (int i = 0; i < n; i++) {
printf("%d\t%d\t\t%d\t\t%d\t\t%d\n", processes[i].pid, processes[i].arrival_time,
processes[i].burst_time, waiting_time[i], turnaround_time[i]);
}
// Calculate average waiting time and average turnaround time
float avg_waiting_time = 0, avg_turnaround_time = 0;
for (int i = 0; i < n; i++) {
avg_waiting_time += waiting_time[i];
avg_turnaround_time += turnaround_time[i];
}
avg_waiting_time /= n;
avg_turnaround_time /= n;

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


printf("Average Turnaround Time: %.2f\n", avg_turnaround_time);
}

int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);

struct Process processes[n];

printf("Enter arrival time and burst time for each process:\n");


for (int i = 0; i < n; i++) {
printf("Process %d:\n", i + 1);
processes[i].pid = i + 1;
printf("Arrival Time: ");
scanf("%d", &processes[i].arrival_time);
printf("Burst Time: ");
scanf("%d", &processes[i].burst_time);
}

// Sort processes based on arrival time (if not already sorted)


// FCFS inherently assumes processes are sorted by arrival time
// Sorting logic can be added if necessary

calculateTimes(processes, n);

return 0;
}

OUTPUT:

Enter the number of processes: 4


Enter arrival time and burst time for each process:
Process 1:
Arrival Time: 0
Burst Time: 7
Process 2:
Arrival Time: 2
Burst Time: 4
Process 3:
Arrival Time: 4
Burst Time: 1
Process 4:
Arrival Time: 6
Burst Time: 4
Process Arrival Time Burst Time Waiting Time Turnaround Time
1 0 7 0 7
2 2 4 5 9
3 4 1 7 8
4 6 4 5 9

Average Waiting Time: 4.25


Average Turnaround Time: 8.25

RESULT:
Thus, the C program successfully implements the FCFS CPU scheduling algorithm.
EX.NO:12(b)
SJF CPU SCHEDULING
DATE:

AIM:
To develop a C program to implement SJF CPU scheduling and calculate average waiting time and
turnaround time based on user input.

ALGORITHM:
1. Start the process.
2. Read the number of processes and their details (arrival time and burst time) from the user.
3. Sort the processes based on their burst times (shortest job first).
4. Calculate waiting time and turnaround time for each process.
5. Compute the average waiting time and average turnaround time.
6. Display the results.
7. Stop the process.

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

struct Process {
int pid;
int arrival_time;
int burst_time;
};

// Function to sort processes based on burst time (SJF)


void sortProcesses(struct Process processes[], int n) {
struct Process temp;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (processes[j].burst_time > processes[j + 1].burst_time) {
temp = processes[j];
processes[j] = processes[j + 1];
processes[j + 1] = temp;
}
}
}
}
void calculateTimes(struct Process processes[], int n) {
int completion_time[n];
int waiting_time[n];
int turnaround_time[n];

// Calculate completion times


completion_time[0] = processes[0].burst_time;
for (int i = 1; i < n; i++) {
completion_time[i] = completion_time[i - 1] + processes[i].burst_time;
}

// Calculate turnaround times and waiting times


for (int i = 0; i < n; i++) {
turnaround_time[i] = completion_time[i] - processes[i].arrival_time;
waiting_time[i] = turnaround_time[i] - processes[i].burst_time;
}

// Print processes along with their times


printf("\nProcess\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time\n");
for (int i = 0; i < n; i++) {
printf("%d\t%d\t\t%d\t\t%d\t\t%d\n", processes[i].pid, processes[i].arrival_time,
processes[i].burst_time, waiting_time[i], turnaround_time[i]);
}

// Calculate average waiting time and average turnaround time


float avg_waiting_time = 0, avg_turnaround_time = 0;
for (int i = 0; i < n; i++) {
avg_waiting_time += waiting_time[i];
avg_turnaround_time += turnaround_time[i];
}
avg_waiting_time /= n;
avg_turnaround_time /= n;

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


printf("Average Turnaround Time: %.2f\n", avg_turnaround_time);
}

int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);

struct Process processes[n];

printf("Enter arrival time and burst time for each process:\n");


for (int i = 0; i < n; i++) {
printf("Process %d:\n", i + 1);
processes[i].pid = i + 1;
printf("Arrival Time: ");
scanf("%d", &processes[i].arrival_time);
printf("Burst Time: ");
scanf("%d", &processes[i].burst_time);
}
// Sort processes based on burst time (SJF)
sortProcesses(processes, n);

calculateTimes(processes, n);

return 0;
}

OUTPUT:
Enter the number of processes: 4
Enter arrival time and burst time for each process:
Process 1:
Arrival Time: 0
Burst Time: 7
Process 2:
Arrival Time: 2
Burst Time: 4
Process 3:
Arrival Time: 4
Burst Time: 1
Process 4:
Arrival Time: 6
Burst Time: 4

Process Arrival Time Burst Time Waiting Time Turnaround Time


3 4 1 0 1
2 2 4 1 5
4 6 4 0 4
1 0 7 5 12

Average Waiting Time: 1.50


Average Turnaround Time: 5.50

RESULT:
Thus, the C program successfully implements the Shortest Job First (SJF) CPU scheduling algorithm
EX.NO:12(c)
PRIORITY CPU SCHEDULING
DATE:

AIM:
To develop a C program to implement Priority CPU scheduling and calculate average waiting time and turnaround
time based on user input.

ALGORITHM:
1. Start the process.
2. Read the number of processes and their details (arrival time, burst time, and priority) from the user.
3. Sort the processes based on their priority (higher priority first).
4. Calculate waiting time and turnaround time for each process.
5. Compute the average waiting time and average turnaround time.
6. Display the results.
7. Stop the process.

PROGRAM:

#include <stdio.h>
#include <stdlib.h>

struct Process {
int pid;
int arrival_time;
int burst_time;
int priority;
};

// Function to sort processes based on priority (higher priority first)


void sortProcesses(struct Process processes[], int n) {
struct Process temp;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (processes[j].priority > processes[j + 1].priority) {
temp = processes[j];
processes[j] = processes[j + 1];
processes[j + 1] = temp;
}
}
}
}

void calculateTimes(struct Process processes[], int n) {


int completion_time[n];
int waiting_time[n];
int turnaround_time[n];

// Calculate completion times


completion_time[0] = processes[0].burst_time;
for (int i = 1; i < n; i++) {
completion_time[i] = completion_time[i - 1] + processes[i].burst_time;
}
// Calculate turnaround times and waiting times
for (int i = 0; i < n; i++) {
turnaround_time[i] = completion_time[i] - processes[i].arrival_time;
waiting_time[i] = turnaround_time[i] - processes[i].burst_time;
}

// Print processes along with their times


printf("\nProcess\tArrival Time\tBurst Time\tPriority\tWaiting Time\tTurnaround Time\n");
for (int i = 0; i < n; i++) {
printf("%d\t%d\t\t%d\t\t%d\t\t%d\t\t%d\n", processes[i].pid, processes[i].arrival_time,
processes[i].burst_time, processes[i].priority, waiting_time[i], turnaround_time[i]);
}

// Calculate average waiting time and average turnaround time


float avg_waiting_time = 0, avg_turnaround_time = 0;
for (int i = 0; i < n; i++) {
avg_waiting_time += waiting_time[i];
avg_turnaround_time += turnaround_time[i];
}
avg_waiting_time /= n;
avg_turnaround_time /= n;

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


printf("Average Turnaround Time: %.2f\n", avg_turnaround_time);
}

int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);

struct Process processes[n];

printf("Enter arrival time, burst time, and priority for each process:\n");
for (int i = 0; i < n; i++) {
printf("Process %d:\n", i + 1);
processes[i].pid = i + 1;
printf("Arrival Time: ");
scanf("%d", &processes[i].arrival_time);
printf("Burst Time: ");
scanf("%d", &processes[i].burst_time);
printf("Priority: ");
scanf("%d", &processes[i].priority);
}

// Sort processes based on priority (higher priority first)


sortProcesses(processes, n);

calculateTimes(processes, n);

return 0;
}

OUTPUT:
Enter the number of processes: 4
Enter arrival time, burst time, and priority for each process:
Process 1:
Arrival Time: 0
Burst Time: 7
Priority: 3
Process 2:
Arrival Time: 2
Burst Time: 4
Priority: 1
Process 3:
Arrival Time: 4
Burst Time: 1
Priority: 4
Process 4:
Arrival Time: 6
Burst Time: 4
Priority: 2

Process Arrival Time Burst Time Priority Waiting Time Turnaround Time
2 2 4 1 0 4
4 6 4 2 0 4
1 0 7 3 4 11
3 4 1 4 7 8

Average Waiting Time: 2.75


Average Turnaround Time: 6.75

RESULT:
Thus, the C program successfully implements Priority CPU scheduling
EX.NO:13(a)
MEMORY ALLOCATION FIRST FIT ALLOCATION
DATE: METHOD

AIM:
To develop a C program to implement First Fit Allocation Method for memory allocation.

ALGORITHM:
1. Start the process.
2. Read the number of processes and their respective sizes from the user.
3. Read the number of memory blocks and their respective sizes from the user
4. Initialize an array to track the allocation status of each memory block (free or allocated
5. For each process, find the first memory block that can accommodate its size using First Fit
6. Allocate the memory block to the process and mark it as allocated
7. If no suitable block is found for a process, display a message indicating it cannot be allocated
8. Display the allocation status after all processes have been allocated
9. Stop the process.

PROGRAM:

#include <stdio.h>
#include <stdbool.h>

void firstFit(int processes[], int m, int blocks[], int n) {


int allocation[m]; // To store block id assigned to a process

// Initialize all blocks as unallocated


for (int i = 0; i < m; i++)
allocation[i] = -1;

// Traverse each process and find suitable blocks according to first fit
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (blocks[j] >= processes[i]) {
// Allocate block j to process i
allocation[i] = j;

// Reduce available memory in this block


blocks[j] -= processes[i];

break;
}
}
}
// Display the allocation status
printf("\nProcess No.\tProcess Size\tBlock No.\n");
for (int i = 0; i < m; i++) {
printf("P%d\t\t%d\t\t", i, processes[i]);
if (allocation[i] != -1)
printf("B%d\n", allocation[i]);
else
printf("Not Allocated\n");
}
}

int main() {
int m, n; // m -> number of processes, n -> number of memory blocks

printf("Enter number of processes: ");


scanf("%d", &m);

int processes[m];
printf("Enter sizes of processes:\n");
for (int i = 0; i < m; i++) {
printf("P%d: ", i);
scanf("%d", &processes[i]);
}

printf("Enter number of memory blocks: ");


scanf("%d", &n);

int blocks[n];
printf("Enter sizes of memory blocks:\n");
for (int i = 0; i < n; i++) {
printf("B%d: ", i);
scanf("%d", &blocks[i]);
}

// Apply First Fit allocation method


firstFit(processes, m, blocks, n);

return 0;
}

OUTPUT:
Enter number of processes: 4
Enter sizes of processes:
P0: 90
P1: 50
P2: 30
P3: 40
Enter number of memory blocks: 5
Enter sizes of memory blocks:
B0: 20
B1: 100
B2: 40
B3: 200
B4: 10
Process No. Process Size Block No.
P0 90 B1
P1 50 B2
P2 30 B0
P3 40 B2

RESULT:
Thus, the C program successfully implements the First Fit Allocation Method
EX.NO:13(b)
MEMORY ALLOCATION BEST FIT ALLOCATION
DATE: METHOD

AIM:
To develop a C program to implement the Best Fit Allocation Method for memory allocation based on user
input.

ALGORITHM:
1. Start the process
2. Read the number of processes and their respective sizes from the user
3. Read the number of memory blocks and their respective sizes from the user
4. Initialize an array to track the allocation status of each memory block (free or allocated
5. For each process, find the memory block that is closest in size to the process size and can accommodate it (Best
Fit).
6. Allocate the memory block to the process and mark it as allocated.
7. If no suitable block is found for a process, display a message indicating it cannot be allocated.
8. Display the allocation status after all processes have been allocated.
9. Stop the process.

PROGRAM:
#include <stdio.h>

void bestFit(int processes[], int m, int blocks[], int n) {


int allocation[m]; // To store block id assigned to a process

// Initialize all blocks as unallocated


for (int i = 0; i < m; i++)
allocation[i] = -1;

// Traverse each process and find the best fit block according to best fit
for (int i = 0; i < m; i++) {
int bestIdx = -1;
for (int j = 0; j < n; j++) {
if (blocks[j] >= processes[i]) {
if (bestIdx == -1 || blocks[j] < blocks[bestIdx])
bestIdx = j;
}
}

// Allocate block bestIdx to process i


if (bestIdx != -1) {
allocation[i] = bestIdx;
blocks[bestIdx] -= processes[i];
}
}
// Display the allocation status
printf("\nProcess No.\tProcess Size\tBlock No.\n");
for (int i = 0; i < m; i++) {
printf("P%d\t\t%d\t\t", i, processes[i]);
if (allocation[i] != -1)
printf("B%d\n", allocation[i]);
else
printf("Not Allocated\n");
}
}

int main() {
int m, n; // m -> number of processes, n -> number of memory blocks

printf("Enter number of processes: ");


scanf("%d", &m);

int processes[m];
printf("Enter sizes of processes:\n");
for (int i = 0; i < m; i++) {
printf("P%d: ", i);
scanf("%d", &processes[i]);
}

printf("Enter number of memory blocks: ");


scanf("%d", &n);

int blocks[n];
printf("Enter sizes of memory blocks:\n");
for (int i = 0; i < n; i++) {
printf("B%d: ", i);
scanf("%d", &blocks[i]);
}

// Apply Best Fit allocation method


bestFit(processes, m, blocks, n);

return 0;
}

OUTPUT:
Enter number of processes: 4
Enter sizes of processes:
P0: 90
P1: 50
P2: 30
P3: 40
Enter number of memory blocks: 5
Enter sizes of memory blocks:
B0: 20
B1: 100
B2: 40
B3: 200
B4: 10
Process No. Process Size Block No.
P0 90 B2
P1 50 B1
P2 30 B0
P3 40 B2

RESULT:
Thus, the C program successfully implements the Best Fit Allocation Method
EX.NO:13(c)
MEMORY ALLOCATION WORST FIT ALLOCATION
DATE: METHOD

AIM:
To develop a C program to implement the Worst Fit Allocation Method for memory allocation based on user
input.

ALGORITHM:
1. Start the process.
2. Read the number of processes and their respective sizes from the user.
3. Read the number of memory blocks and their respective sizes from the user.
4. Initialize an array to track the allocation status of each memory block (free or allocated).
5. For each process, find the largest memory block that can accommodate its size (Worst Fit).
6. Allocate the memory block to the process and mark it as allocated.
7. If no suitable block is found for a process, display a message indicating it cannot be allocated.
8. Display the allocation status after all processes have been allocated.
9. Stop the process.

PROGRAM:

#include <stdio.h>

void worstFit(int processes[], int m, int blocks[], int n) {


int allocation[m]; // To store block id assigned to a process

// Initialize all blocks as unallocated


for (int i = 0; i < m; i++)
allocation[i] = -1;

// Traverse each process and find the worst fit block according to worst fit
for (int i = 0; i < m; i++) {
int worstIdx = -1;
for (int j = 0; j < n; j++) {
if (blocks[j] >= processes[i]) {
if (worstIdx == -1 || blocks[j] > blocks[worstIdx])
worstIdx = j;
}
}
if (worstIdx != -1) {
allocation[i] = worstIdx;
blocks[worstIdx] -= processes[i];
}
}
printf("\nProcess No.\tProcess Size\tBlock No.\n");
for (int i = 0; i < m; i++) {
printf("P%d\t\t%d\t\t", i, processes[i]);
if (allocation[i] != -1)
printf("B%d\n", allocation[i]);
else
printf("Not Allocated\n");
}
}
int main() {
int m, n; // m -> number of processes, n -> number of memory blocks

printf("Enter number of processes: ");


scanf("%d", &m);

int processes[m];
printf("Enter sizes of processes:\n");
for (int i = 0; i < m; i++) {
printf("P%d: ", i);
scanf("%d", &processes[i]);
}

printf("Enter number of memory blocks: ");


scanf("%d", &n);

int blocks[n];
printf("Enter sizes of memory blocks:\n");
for (int i = 0; i < n; i++) {
printf("B%d: ", i);
scanf("%d", &blocks[i]);
}

// Apply Worst Fit allocation method


worstFit(processes, m, blocks, n);

return 0;
}

OUTPUT:
Enter number of processes: 4
Enter sizes of processes:
P0: 90
P1: 50
P2: 30
P3: 40
Enter number of memory blocks: 5
Enter sizes of memory blocks:
B0: 20
B1: 100
B2: 40
B3: 200
B4: 10

Process No. Process Size Block No.


P0 90 B3
P1 50 B1
P2 30 B2
P3 40 B3

RESULT:
Thus, the C program successfully implements the Worst Fit Allocation Method
EX.NO:14(a)
FIFO PAGE REPLACEMENT ALGORITHM
DATE:

AIM:
To develop a C program that implements the FIFO page replacement algorithm and calculates the number of
page faults based on a given reference string and three frames of memory.

ALGORITHM:
1. Start the process.
2. Read the reference string (sequence of page numbers) from the user.
3. Initialize an array to represent the frames of memory (size 3 for this case).
4. Initialize a queue to keep track of the pages in the frames in the order they were loaded (FIFO order).
5. Initialize a counter to keep track of the number of page faults.
6. For each page in the reference string:
- Check if the page is already in one of the frames.
- If it is, continue to the next page.
- If it is not, check if there is an empty frame available.
- If there is an empty frame, load the page into the frame and update the queue.
- If there are no empty frames, replace the page at the front of the queue (oldest page) with the current
page, update the queue, and increment the page fault counter.
7. Display the total number of page faults incurred.
8. Stop the process.

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

#define MAX_FRAMES 3

int main() {
int reference_string[100]; // Assuming max length of reference string is 100
int frames[MAX_FRAMES];
int queue[MAX_FRAMES]; // To store page numbers in FIFO order
int front = 0, rear = 0;
int num_pages, num_frames, num_faults = 0;

printf("Enter number of pages in reference string: ");


scanf("%d", &num_pages);

printf("Enter the reference string (separated by spaces): ");


for (int i = 0; i < num_pages; i++) {
scanf("%d", &reference_string[i]);
}

// Initialize frames and queue


for (int i = 0; i < MAX_FRAMES; i++) {
frames[i] = -1; // -1 indicates an empty frame
queue[i] = -1;
}
// Implement FIFO page replacement algorithm
for (int i = 0; i < num_pages; i++) {
bool page_found = false;
// Check if page is already in frames
for (int j = 0; j < MAX_FRAMES; j++) {
if (frames[j] == reference_string[i]) {
page_found = true;
break;
}
}

// If page is not in frames, replace or add it


if (!page_found) {
// Increment page fault count
num_faults++;

// If there's space in frames, add page to an empty frame


if (rear < MAX_FRAMES) {
frames[rear] = reference_string[i];
queue[rear] = reference_string[i];
rear++;
} else { // If no space, replace the oldest page (front of queue)
int replace_page = queue[front];
frames[front] = reference_string[i];
queue[front] = reference_string[i];
front = (front + 1) % MAX_FRAMES;
}
}

// Print current frames


printf("Current frames: ");
for (int j = 0; j < MAX_FRAMES; j++) {
if (frames[j] == -1)
printf("[ ] ");
else
printf("[%d] ", frames[j]);
}
printf("\n");
}

printf("\nTotal Page Faults: %d\n", num_faults);

return 0;
}

OUTPUT:
Enter number of pages in reference string: 20
Enter the reference string (separated by spaces): 6 1 1 2 0 3 4 6 0 2 1 2 1 2 0 3 2 1 2 0

Current frames: [6] [ ] [ ]


Current frames: [6] [1] [ ]
Current frames: [6] [1] [2]
Current frames: [0] [1] [2]
Current frames: [0] [1] [2]
Current frames: [0] [3] [2]
Current frames: [4] [3] [2]
Current frames: [4] [3] [6]
Current frames: [4] [0] [6]
Current frames: [2] [0] [6]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [0] [2] [1]
Current frames: [0] [2] [1]
Current frames: [0] [2] [1]
Current frames: [0] [2] [1]

Total Page Faults: 9

RESULT:
The C program successfully implements the FIFO page replacement algorithm.
EX.NO:14(b)
OPTIMAL PAGE REPLACEMENT ALGORITHM
DATE:

AIM:
To develop a C program that implements the OPTIMAL page replacement algorithm and calculates the
number of page faults based on a given reference string and three frames of memory.

ALGORITHM:
1. Start the process.
2. Read the reference string (sequence of page numbers) from the user.
3. Initialize an array to represent the frames of memory (size 3 for this case).
4. Initialize a counter to keep track of the number of page faults.
5. For each page in the reference string:
- Check if the page is already in one of the frames.
- If it is, continue to the next page.
- If it is not, check if there is an empty frame available.
- If there is an empty frame, load the page into the frame and mark it as loaded.
- If there are no empty frames, find the page that will not be used for the longest period in the future
(OPTIMAL replacement) and replace it with the current page.
- Increment the page fault counter whenever a page fault occurs.
6. Display the total number of page faults incurred.
7. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
#define NUM_FRAMES 3
bool isPresent(int page, int frames[], int num_frames) {
for (int i = 0; i < num_frames; i++) {
if (frames[i] == page)
return true;
}
return false;
}
int findOptimal(int reference_string[], int frames[], int num_frames, int start_index, int num_pages) {
int farthest = -1;
int replace_index = -1;
for (int i = 0; i < num_frames; i++) {
int j;
for (j = start_index; j < num_pages; j++) {
if (frames[i] == reference_string[j]) {
if (j > farthest) {
farthest = j;
replace_index = i;
}
break;
}
}
// If the page is not found in future reference string, replace it
if (j == num_pages)
return i;
}
return (replace_index == -1) ? 0 : replace_index;
}
int main() {
int reference_string[100]; // Assuming max length of reference string is 100
int frames[NUM_FRAMES];
int num_pages, num_faults = 0;

printf("Enter number of pages in reference string: ");


scanf("%d", &num_pages);

printf("Enter the reference string (separated by spaces): ");


for (int i = 0; i < num_pages; i++) {
scanf("%d", &reference_string[i]);
}
for (int i = 0; i < NUM_FRAMES; i++) {
frames[i] = -1; // -1 indicates an empty frame
}

// Implement OPTIMAL page replacement algorithm


for (int i = 0; i < num_pages; i++) {
// If page is already in frames, continue
if (isPresent(reference_string[i], frames, NUM_FRAMES)) {
continue;
}

// Increment page fault count


num_faults++;

// If there's space in frames, add page to an empty frame


if (i < NUM_FRAMES) {
frames[i] = reference_string[i];
} else { // If no space, find the optimal page to replace
int replace_index = findOptimal(reference_string, frames, NUM_FRAMES, i + 1, num_pages);
frames[replace_index] = reference_string[i];
}

printf("Current frames: ");


for (int j = 0; j < NUM_FRAMES; j++) {
if (frames[j] == -1)
printf("[ ] ");
else
printf("[%d] ", frames[j]);
}
printf("\n");
}
printf("\nTotal Page Faults: %d\n", num_faults);

return 0;
}
OUTPUT:
Enter number of pages in reference string: 20
Enter the reference string (separated by spaces): 6 1 1 2 0 3 4 6 0 2 1 2 1 2 0 3 2 1 4 0

Current frames: [6] [ ] [ ]


Current frames: [6] [1] [ ]
Current frames: [6] [1] [2]
Current frames: [0] [1] [2]
Current frames: [0] [1] [2]
Current frames: [0] [1] [3]
Current frames: [4] [1] [3]
Current frames: [4] [1] [6]
Current frames: [4] [0] [6]
Current frames: [2] [0] [6]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [4] [0] [1]
Current frames: [4] [0] [1]

Total Page Faults: 9

RESULT:
The C program successfully implements the OPTIMAL page replacement algorithm
EX.NO:14(c)
LRU PAGE REPLACEMENT ALGORITHM
DATE:

AIM:
To develop a C program that implements the LRU page replacement algorithm and calculates the number of
page faults based on a given reference string and three frames of memory.

ALGORITHM:
1. Start the process.
2. Read the reference string (sequence of page numbers) from the user.
3. Initialize an array to represent the frames of memory (size 3 for this case).
4. Initialize an array to keep track of the time of last use (LRU timestamp) for each frame.
5. Initialize a counter to keep track of the number of page faults.
6. For each page in the reference string:
- Check if the page is already in one of the frames.
- If it is, update the LRU timestamp for that frame and continue to the next page.
- If it is not, check if there is an empty frame available.
- If there is an empty frame, load the page into the frame, update the LRU timestamp, and increment the
page fault counter.
- If there are no empty frames, find the frame with the oldest LRU timestamp (least recently used) and
replace it with the current page. Update the LRU timestamp and increment the page fault counter.
7. Display the total number of page faults incurred.
8. Stop the process.

PROGRAM:

#include <stdio.h>
#include <stdbool.h>

#define NUM_FRAMES 3
#define INF INT_MAX

// Function to check if page is present in frames


bool isPresent(int page, int frames[], int num_frames) {
for (int i = 0; i < num_frames; i++) {
if (frames[i] == page)
return true;
}
return false;
}

// Function to find the index of the least recently used frame


int findLRU(int lru[], int num_frames) {
int min_index = 0;
for (int i = 1; i < num_frames; i++) {
if (lru[i] < lru[min_index]) {
min_index = i;
}
}
return min_index;
}
int main() {
int reference_string[100]; // Assuming max length of reference string is 100
int frames[NUM_FRAMES];
int lru[NUM_FRAMES] = {0}; // To store time of last use (LRU timestamp) for each frame
int num_pages, num_faults = 0;

printf("Enter number of pages in reference string: ");


scanf("%d", &num_pages);

printf("Enter the reference string (separated by spaces): ");


for (int i = 0; i < num_pages; i++) {
scanf("%d", &reference_string[i]);
}

// Initialize frames
for (int i = 0; i < NUM_FRAMES; i++) {
frames[i] = -1; // -1 indicates an empty frame
}

// Implement LRU page replacement algorithm


for (int i = 0; i < num_pages; i++) {
// If page is already in frames, update LRU timestamp and continue
if (isPresent(reference_string[i], frames, NUM_FRAMES)) {
for (int j = 0; j < NUM_FRAMES; j++) {
if (frames[j] == reference_string[i]) {
lru[j] = i; // Update LRU timestamp
break;
}
}
continue;
}
num_faults++;

// If there's space in frames, add page to an empty frame


if (i < NUM_FRAMES) {
frames[i] = reference_string[i];
lru[i] = i; // Set initial LRU timestamp
} else { // If no space, find LRU frame and replace it
int replace_index = findLRU(lru, NUM_FRAMES);
frames[replace_index] = reference_string[i];
lru[replace_index] = i; // Update LRU timestamp
}

// Print current frames


printf("Current frames: ");
for (int j = 0; j < NUM_FRAMES; j++) {
if (frames[j] == -1)
printf("[ ] ");
else
printf("[%d] ", frames[j]);
}
printf("\n");
}

printf("\nTotal Page Faults: %d\n", num_faults);

return 0;
}
OUTPUT:
Enter number of pages in reference string: 20
Enter the reference string (separated by spaces): 6 1 1 2 0 3 4 6 0 2 1 2 1 2 0 3 2 1 4 0

Current frames: [6] [ ] [ ]


Current frames: [6] [1] [ ]
Current frames: [6] [1] [2]
Current frames: [0] [1] [2]
Current frames: [0] [1] [2]
Current frames: [0] [3] [2]
Current frames: [4] [3] [2]
Current frames: [4] [3] [6]
Current frames: [4] [0] [6]
Current frames: [2] [0] [6]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [2] [0] [1]
Current frames: [4] [0] [1]
Current frames: [4] [0] [1]

Total Page Faults: 9

RESULT:
The C program successfully implements the LRU page replacement algorithm
EX.NO:15(a)
SSTF DISK SCHEDULING ALGORITHM
DATE:

AIM:
To develop a C program that implements the SSTF disk scheduling algorithm and calculates the total head
movement based on a given sequence of disk I/O requests and initial head position.

ALGORITHM:
1. Start the process.
2. Read the number of requests and the sequence of cylinder numbers from the user.
3. Initialize variables:
- `num_requests`: Number of disk I/O requests.
- `requests[]`: Array to store the cylinder numbers of requests.
- `head`: Initial position of the disk head.
- `total_movement`: Variable to store the total head movement.
- `visited[]`: Array to keep track of visited requests.
4. Sort the requests based on the shortest seek time from the current head position.
5. Calculate the head movement:
- Find the nearest request from the current head position that has not been visited.
- Move the head to this request.
- Mark this request as visited.
- Update `total_movement` with the distance moved by the head.
6. Repeat Step 5 until all requests have been serviced.
7. Display the total head movement.
8. Stop the process.

PROGRAM:

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define MAX_REQUESTS 100

// Function to find the nearest request from the current head position
int findNearestRequest(int head, int requests[], int visited[], int num_requests) {
int min_distance = INT_MAX;
int nearest_index = -1;

for (int i = 0; i < num_requests; i++) {


if (!visited[i]) {
int distance = abs(head - requests[i]);
if (distance < min_distance) {
min_distance = distance;
nearest_index = i;
}
}
}

return nearest_index;
}
int main() {
int requests[MAX_REQUESTS];
int visited[MAX_REQUESTS] = {0}; // Initialize all requests as not visited
int num_requests, head, total_movement = 0;

printf("Enter number of requests: ");


scanf("%d", &num_requests);

printf("Enter the cylinder requests (separated by spaces): ");


for (int i = 0; i < num_requests; i++) {
scanf("%d", &requests[i]);
}

printf("Enter initial head position: ");


scanf("%d", &head);

// Implement SSTF scheduling algorithm


for (int count = 0; count < num_requests; count++) {
// Find nearest request from current head position
int nearest_index = findNearestRequest(head, requests, visited, num_requests);

// Move head to nearest request


total_movement += abs(head - requests[nearest_index]);

// Update head position


head = requests[nearest_index];

// Mark request as visited


visited[nearest_index] = 1;
}

// Display total head movement


printf("\nTotal head movement: %d cylinders\n", total_movement);

return 0;
}

OUTPUT:
Enter number of requests: 10
Enter the cylinder requests (separated by spaces): 4 34 10 7 19 73 2 15 6 20
Enter initial head position: 50

Total head movement: 144 cylinders

RESULT:
The C program successfully implements the SSTF disk scheduling algorithm
EX.NO:15(b)
FCFS DISK SCHEDULING ALGORITHM
DATE:

AIM:
To develop a C program that implements the FCFS disk scheduling algorithm and calculates the total head
movement based on a given sequence of disk I/O requests and initial head position.

ALGORITHM:
1. Start the process.
2. Read the number of requests and the sequence of cylinder numbers from the user.
3. Initialize variables:
- `num_requests`: Number of disk I/O requests.
- `requests[]`: Array to store the cylinder numbers of requests.
- `head`: Initial position of the disk head.
- `total_movement`: Variable to store the total head movement.
4. Calculate the head movement:
- Traverse through the requests in the order they arrive (FCFS).
- For each request, calculate the distance from the current head position to the requested cylinder.
- Move the head to the requested cylinder.
- Update `total_movement` with the distance moved by the head.
5. Display the total head movement.
6. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAX_REQUESTS 100
int main() {
int requests[MAX_REQUESTS];
int num_requests, head, total_movement = 0;
printf("Enter number of requests: ");
scanf("%d", &num_requests);
printf("Enter the cylinder requests (separated by spaces): ");
for (int i = 0; i < num_requests; i++) {
scanf("%d", &requests[i]);
}
printf("Enter initial head position: ");
scanf("%d", &head);
for (int i = 0; i < num_requests; i++) {
// Calculate head movement to next request
total_movement += abs(head - requests[i]);

// Move head to next request


head = requests[i];
}
printf("\nTotal head movement: %d cylinders\n", total_movement);
return 0;
}
OUTPUT:
Enter number of requests: 8
Enter the cylinder requests (separated by spaces): 98 183 41 122 14 124 65 67
Enter initial head position: 53

Total head movement: 640 cylinders

RESULT:
The C program successfully implements the FCFS disk scheduling algorithm
EX.NO:15(c)
CLOOK DISK SCHEDULING ALGORITHM
DATE:

AIM:
To develop a C program that implements the CLOOK disk scheduling algorithm and calculates the total
head movement based on a given sequence of disk I/O requests and initial head position.

ALGORITHM:
1. Start the process.
2. Read the number of requests and the sequence of cylinder numbers from the user.
3. Initialize variables:
- `num_requests`: Number of disk I/O requests.
- `requests[]`: Array to store the cylinder numbers of requests.
- `head`: Initial position of the disk head.
- `total_movement`: Variable to store the total head movement.
4. Sort the requests and the head position in ascending order.
5. Calculate the head movement:
- Find the nearest request from the current head position that has not been visited.
- If no requests are found, reset the head position to 0 and repeat the process in a circular fashion.
- Move the head to this request.
- Update `total_movement` with the distance moved by the head.
6. Display the total head movement.
7. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAX_REQUESTS 100
void sort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = i+1; j < n; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int findNearestRequest(int head, int requests[], int num_requests) {
int nearest_index = -1;
for (int i = 0; i < num_requests; i++) {
if (requests[i] >= head) {
nearest_index = i;
break;
}
}
// If no requests are found in higher direction, go to the first request
if (nearest_index == -1)
nearest_index = 0;
return nearest_index;
}
int main() {
int requests[MAX_REQUESTS];
int num_requests, head, total_movement = 0;

printf("Enter number of requests: ");


scanf("%d", &num_requests);

printf("Enter the cylinder requests (separated by spaces): ");


for (int i = 0; i < num_requests; i++) {
scanf("%d", &requests[i]);
}

printf("Enter initial head position: ");


scanf("%d", &head);

// Sort requests in ascending order


sort(requests, num_requests);

// Implement CLOOK scheduling algorithm


int current_index = findNearestRequest(head, requests, num_requests);
for (int count = 0; count < num_requests; count++) {
// Calculate head movement to next request
total_movement += abs(head - requests[current_index]);

// Move head to next request


head = requests[current_index];

// Mark request as visited


requests[current_index] = -1; // Mark as visited

// Find next nearest request


current_index = (current_index + 1) % num_requests;
while (requests[current_index] == -1) {
current_index = (current_index + 1) % num_requests;
}
}

// Display total head movement


printf("\nTotal head movement: %d cylinders\n", total_movement);

return 0;
}

OUTPUT:
Enter number of requests: 8
Enter the cylinder requests (separated by spaces): 98 183 41 122 14 124 65 67
Enter initial head position: 53

Total head movement: 236 cylinders

RESULT:
The C program successfully implements the CLOOK disk scheduling algorithm
EX.NO:15(d)
C-SCAN DISK SCHEDULING ALGORITHM
DATE:

AIM:
To develop a C program that implements the C-SCAN disk scheduling algorithm and calculates the total
head movement based on a given sequence of disk I/O requests and initial head position.

ALGORITHM:
1. Start the process.
2. Read the number of requests and the sequence of cylinder numbers from the user.
3. Initialize variables:
- `num_requests`: Number of disk I/O requests.
- `requests[]`: Array to store the cylinder numbers of requests.
- `head`: Initial position of the disk head.
- `total_movement`: Variable to store the total head movement.
4. Sort the requests and the head position in ascending order.
5. Calculate the head movement:
- Traverse the requests in the order they arrive (ascending order).
- Move the head towards larger cylinder numbers until the end of the disk.
- Wrap around to the beginning of the disk after reaching the last cylinder.
- Continue moving in the same direction until all requests are serviced.
- Count the head movements for each request and accumulate them in `total_movement`.
6. Display the total head movement.
7. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAX_REQUESTS 100
void sort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = i+1; j < n; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main() {
int requests[MAX_REQUESTS];
int num_requests, head, total_movement = 0;

printf("Enter number of requests: ");


scanf("%d", &num_requests);

printf("Enter the cylinder requests (separated by spaces): ");


for (int i = 0; i < num_requests; i++) {
scanf("%d", &requests[i]);
}
printf("Enter initial head position: ");
scanf("%d", &head);
// Sort requests in ascending order
sort(requests, num_requests);

// Implement C-SCAN scheduling algorithm


int current_index = 0;
while (current_index < num_requests && requests[current_index] < head) {
current_index++;
}

// Move towards larger cylinder numbers until the end


for (int i = current_index; i < num_requests; i++) {
total_movement += abs(head - requests[i]);
head = requests[i];
}

// Move to the end of the disk


total_movement += (199 - head);

// Move from the end of the disk to the beginning (0)


total_movement += 199;

// Move towards larger cylinder numbers for remaining requests


for (int i = 0; i < current_index; i++) {
total_movement += abs(head - requests[i]);
head = requests[i];
}

// Display total head movement


printf("\nTotal head movement: %d cylinders\n", total_movement);

return 0;
}

OUTPUT:
Enter number of requests: 8
Enter the cylinder requests (separated by spaces): 98 183 41 122 14 124 65 67
Enter initial head position: 53

Total head movement: 236 cylinders

RESULT:
The C program successfully implements the C-SCAN disk scheduling algorithm
EX.NO:15(e)
LOOK DISK SCHEDULING ALGORITHM
DATE:

AIM:
To develop a C program that implements the LOOK disk scheduling algorithm and calculates the total head
movement based on a given sequence of disk I/O requests and initial head position.

ALGORITHM:
1. Start the process.
2. Read the number of requests and the sequence of cylinder numbers from the user.
3. Initialize variables:
- `num_requests`: Number of disk I/O requests.
- `requests[]`: Array to store the cylinder numbers of requests.
- `head`: Initial position of the disk head.
- `total_movement`: Variable to store the total head movement.
4. Sort the requests and the head position in ascending order.
5. Calculate the head movement:
- Traverse the requests in the order they arrive (ascending order).
- Move the head towards larger cylinder numbers until the last request that is less than or equal to the head
position.
- Move the head towards smaller cylinder numbers until the first request that is greater than or equal to the
head position.
- Count the head movements for each segment and accumulate them in `total_movement`.
6. Display the total head movement.
7. Stop the process.

PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define MAX_REQUESTS 100

// Function to sort array in ascending order


void sort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = i+1; j < n; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main() {
int requests[MAX_REQUESTS];
int num_requests, head, total_movement = 0;

printf("Enter number of requests: ");


scanf("%d", &num_requests);

printf("Enter the cylinder requests (separated by spaces): ");


for (int i = 0; i < num_requests; i++) {
scanf("%d", &requests[i]);
}

printf("Enter initial head position: ");


scanf("%d", &head);

// Sort requests in ascending order


sort(requests, num_requests);

// Implement LOOK scheduling algorithm


int current_index = 0;
while (current_index < num_requests && requests[current_index] < head) {
current_index++;
}

// Move towards larger cylinder numbers


for (int i = current_index; i < num_requests; i++) {
total_movement += abs(head - requests[i]);
head = requests[i];
}

// Move towards smaller cylinder numbers


for (int i = current_index - 1; i >= 0; i--) {
total_movement += abs(head - requests[i]);
head = requests[i];
}

// Display total head movement


printf("\nTotal head movement: %d cylinders\n", total_movement);

return 0;
}

OUTPUT:
Enter number of requests: 8
Enter the cylinder requests (separated by spaces): 98 183 41 122 14 124 65 67
Enter initial head position: 53

Total head movement: 236 cylinders

RESULT:
The C program successfully implements the LOOK disk scheduling algorithm
EX.NO:15(f)
SCAN DISK SCHEDULING ALGORITHM
DATE:

AIM:
To develop a C program that implements the SCAN disk scheduling algorithm and calculates the total head
movement based on a given sequence of disk I/O requests and initial head position.

ALGORITHM:
1. Start the process.
2. Read the number of requests and the sequence of cylinder numbers from the user.
3. Initialize variables:
- `num_requests`: Number of disk I/O requests.
- `requests[]`: Array to store the cylinder numbers of requests.
- `head`: Initial position of the disk head.
- `total_movement`: Variable to store the total head movement.
- `direction`: Flag to indicate the direction of head movement (1 for towards larger cylinders, 0 for towards
smaller cylinders).
4. Sort the requests and the head position in ascending order.
5. Calculate the head movement:
- Determine the initial direction based on the head position relative to the first request.
- Move the head towards larger cylinder numbers until the last request in that direction.
- Change direction and move towards smaller cylinder numbers until the first request in that direction.
- Count the head movements for each segment and accumulate them in `total_movement`.
6. Display the total head movement.
7. Stop the process.

PROGRAM:

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define MAX_REQUESTS 100

// Function to sort array in ascending order


void sort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = i+1; j < n; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main() {
int requests[MAX_REQUESTS];
int num_requests, head, total_movement = 0, direction = 1;

printf("Enter number of requests: ");


scanf("%d", &num_requests);

printf("Enter the cylinder requests (separated by spaces): ");


for (int i = 0; i < num_requests; i++) {
scanf("%d", &requests[i]);
}

printf("Enter initial head position: ");


scanf("%d", &head);

// Sort requests in ascending order


sort(requests, num_requests);

// Determine initial direction


if (head > requests[0]) {
direction = 1; // Move towards larger cylinders
} else {
direction = 0; // Move towards smaller cylinders
}

// Implement SCAN scheduling algorithm


int current_index = 0;
if (direction == 1) {
// Move towards larger cylinders
while (current_index < num_requests && requests[current_index] < head) {
current_index++;
}
for (int i = current_index; i < num_requests; i++) {
total_movement += abs(head - requests[i]);
head = requests[i];
}
// Move to the end of the disk
total_movement += (199 - head);
head = 199;
// Move towards smaller cylinders
for (int i = num_requests - 1; i >= 0; i--) {
total_movement += abs(head - requests[i]);
head = requests[i];
}
} else {
// Move towards smaller cylinders
while (current_index < num_requests && requests[current_index] > head) {
current_index++;
}
for (int i = current_index - 1; i >= 0; i--) {
total_movement += abs(head - requests[i]);
head = requests[i];
}
// Move to the beginning of the disk
total_movement += head;
head = 0;
// Move towards larger cylinders
for (int i = 0; i < num_requests; i++) {
total_movement += abs(head - requests[i]);
head = requests[i];
}
}

printf("\nTotal head movement: %d cylinders\n", total_movement);

return 0;
}

OUTPUT:
Enter number of requests: 8
Enter the cylinder requests (separated by spaces): 98 183 41 122 14 124 65 67
Enter initial head position: 53

Total head movement: 236 cylinders

RESULT:
The C program successfully implements the SCAN (Elevator) disk scheduling algorithm
EX.NO:16
INSTALL LINUX OPERATING SYSTEM USING
DATE: VMWARE.

Aim:
To install any guest operating system like linux using VMware

Description:
Installing a Linux operating System using a VMware consists of two steps.
Part 1: Prepare a Computer for Virtualization
Part 2: Create a Virtual Machine

Scenario:
Personal computing power and resources have increased tremendously over the last 5 to 10 years. One of the
benefits of having access to multicore processors and large amounts of RAM memory is the ability to use
virtualization on a personal computer. With virtualization, a user can run multiple virtual computers on one
physical computer or server. Virtual computers that run within a physical computer system are called virtual
machines. Today entire computer networks are being implemented where all of the end user computer
stations are actually virtual machines run off of a centralized server. Anyone with a modern computer and
operating system has the ability to run virtual machines from the desktop.

Part 1: Prepare a Computer for Virtualization


In Part 1, you will download and install virtualization software, and acquire a bootable image of a Linux
distribution.

Step 1: Download and install the free VMware player.


There are two excellent virtualization programs that you can download and install for free, VMware Player
and VirtualBox. In this lab, you will use the VMware player.
a. Go to http://vmware.com, hover the cursor over Downloads, and search for Free Product Downloads.
b. Under Free Product Downloads, click Player.
The VMware Player has 32-bit and 64-bit versions for Windows and Linux. To download the software, you
must register a free user account with VMware.
Note: The Linux version of VMware Player might work on Mac OS X; if not, http://virtualbox.org has a free
version of its VirtualBox software that will run on Mac OS X.
c. When you have downloaded the VMware Player installation file, run the installer and accept the default
installation settings.

Step 2: Download a bootable image of Linux.


You need an operating system to install on your virtual machine’s virtual hardware. Linux is a suitable
choice for an operating system, because most of the distributions are free to download and run. It also allows
you to
explore an operating system that might be unfamiliar to you.

a. To download Linux, you first must select a distribution such as Mint, Ubuntu, Fedora, Suse, Debian, or
CentOS. (There are many others to choose from.) In this lab, the instructions follow an installation of Linux
Mint.
b. Go to http://linuxmint.com, hover over the Download button, and click Linux Mint 16 (or current version
number).
c. Scroll down the page until you see the version of the Mint code name, Cinnamon (or the current code
name). Choose either the 32-bit or 64-bit version, depending on your current operating system platform,
and click the link.
d. A new web page will appear. Select a download mirror site from which to download the operating system.
Click a mirror site to activate the Linux file download. When prompted by the browser, choose to save the
Linux .iso file to a local directory.
e. When the file has finished downloading, you should have a Linux Mint .iso bootable image.
Part 2: Create a Virtual Machine
In Part 2, using the VMware Player, you will create a virtual machine and customize its virtual hardware.
Then, using the Linux Mint .iso file that you downloaded in Part 1, you will install the Linux Mint operating
system on the virtual machine.

Step 1: Create a virtual computer and customize the virtual hardware.


a. Open VMware Player, and click Create a New Virtual Machine.
b. A new window will appear. Select I will install the operating system later. The virtual machine will be
created with a blank hard disk option. Click Next.
c. A new window will appear. Select Linux as the guest operating system. Under version, you may notice
that Mint is not listed. In this case, select an alternate Linux distribution, one that is closely related to Mint
(like Ubuntu). Lastly, select either the 32-bit or 64-bit version and click Next.
d. A new window will appear. Select a name and storage location for the virtual machine.
e. A new window will appear. Select the maximum size of the virtual hard drive storage. You can also
decide
whether or not to store the virtual hard drive in a single file or in multiple files.
f. When a new window appears, click Finish to finish creating the virtual machine hardware, or click
Customize Hardware to customize the virtual hardware. For example, you can specify the amount of
RAM, how many CPU cores you want, and add additional drives and peripheral components (see video
tutorial).
g. When you have customized and completed the process, you are now ready to run your virtual machine
and install an operating system.

Step 2: Install the Linux operating system on the virtual computer.


To install from an .iso bootable image file, complete the following steps:
a. In VMware Player, click Edit virtual machine settings. If you have multiple virtual machines created, you
must first select which one you intend to edit.
b. In the pop-up window, under the Hardware tab, select CD/DVD (SATA), and on the right side (under
Connections), select the Use ISO image file option, and click Browse to search through your file
system for the Linux Mint .iso image file downloaded in Part 1.
Selecting the Linux .iso file causes it to be automatically mounted to the CD/DVD drive when the virtual
machine boots, which, in turn, causes the system to boot and run the Linux installation image.
c. Select Network Adapter, and click OK.
The network adapter is currently set to NAT mode, which allows your virtual machine to access the
network through the host computer system by translating all Internet requests through the VMware player,
much like a gateway router. This gives your virtual machine a private network address separate from your
home network.
(Optional) To have your virtual machine on the same network as the computer hosting the virtual
machine, select the Bridged option and click Configure Adapters to identify to which physical network
adapter the virtual machine should bridge.
Note: This is especially important on laptops that have both wireless and wired network adapters that can
connect to the network.
d. When you are finished click OK.
e. Click Play virtual machine to launch your virtual machine and boot to Linux.
When the boot process has completed you should be presented with a Linux Mint desktop.
f. (Optional) To permanently install Linux Mint on the virtual machine hard disk drive, on the desktop,
double-click the Install Linux Mint disk icon and follow the installation procedure (see video).
During the installation, you will be presented with a warning message that installing to the drive will erase
everything on the disk drive; this refers to the virtual disk drive, not the host computer physical disk drive.
g. When you have finished the installation procedure, you should have a Linux Mint virtual machine that
you can run in a window alongside your host computer system.

Result:
Thus the guest operating system like linux using VMware is successfully installed.

You might also like