OS - 2nd Year 4th Sem - Last Sem
OS - 2nd Year 4th Sem - Last Sem
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:
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.
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
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
Creation:
Syn:$cat>filename
Viewing:
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:
ALGORITHM:
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:
ALGORITHM:
COMMAND:
d)ls
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:
DATE:
AIM:
ALGORITHM:
PROGRAM:
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:
ALGORITHM:
PROGRAM:
OUTPUT:
RESULT:
Thus the program of List ADT is executed and the output is obtained successfully.
EX.NO:2(b)-3
FIBONACCI SERIES
DATE:
AIM:
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:
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
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:
OUTPUT:
RESULT:
DATE:
AIM:
ALGORITHM:
PROGRAM:
# Main program
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:
# Main program
Result:
Thus the Shell program to convert Celsius to Fahrenheit wa executed successfully and verified.
EX.NO:2(b)-7
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:
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
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
# Main program
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:
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:
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:
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
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>
typedef struct {
char filename[MAX_FILENAME_LENGTH];
} File;
File directory[MAX_FILES];
int file_count = 0;
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
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);
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]);
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];
return 0;
}
OUTPUT:
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;
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
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);
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);
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];
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>
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;
}
}
int main() {
int allocation[P][R], request[P][R], available[R];
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;
};
int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &n);
calculateTimes(processes, n);
return 0;
}
OUTPUT:
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;
};
int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &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
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;
};
int main() {
int n;
printf("Enter the number of processes: ");
scanf("%d", &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);
}
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
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>
// 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;
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
int processes[m];
printf("Enter sizes of processes:\n");
for (int i = 0; i < m; i++) {
printf("P%d: ", i);
scanf("%d", &processes[i]);
}
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]);
}
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>
// 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;
}
}
int main() {
int m, n; // m -> number of processes, n -> number of memory blocks
int processes[m];
printf("Enter sizes of processes:\n");
for (int i = 0; i < m; i++) {
printf("P%d: ", i);
scanf("%d", &processes[i]);
}
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]);
}
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>
// 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
int processes[m];
printf("Enter sizes of processes:\n");
for (int i = 0; i < m; i++) {
printf("P%d: ", i);
scanf("%d", &processes[i]);
}
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]);
}
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
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;
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
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;
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
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
// Initialize frames
for (int i = 0; i < NUM_FRAMES; i++) {
frames[i] = -1; // -1 indicates an empty frame
}
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
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>
// 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;
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;
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
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]);
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;
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
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;
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
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>
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
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>
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
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.
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.
Result:
Thus the guest operating system like linux using VMware is successfully installed.