Record Os 18mar
Record Os 18mar
Step 2: Mount the ISO image as a drive or burn it into a DVD. Optionally, you can create a Windows 10 bootable USB drive.
Step 3: Launch your virtual machine software and create a new virtual machine. You can read more details on how to install
Windows 10 on VMWare Workstation.
Step 4: After you create the virtual machine, follow the steps below to install Windows 10.
Step 5: In the welcome screen, choose your language settings and click the "Next" button to proceed.
Step 8: Installer will copy all the necessary files to the computer and continue with the installation. Depending on your system
configuration, it may take a while (10-20 minutes) to complete the installation.
After successful installation, you will see the Windows welcome screen, which is similar to the Windows 8 theme.
You will be presented with an option to select the Settings. Unless you want to make custom configuration, you can choose
"Express Settings" and proceed.
In the next step, you will be prompted to select One Drive option. If you don't want to integrate One Drive storage for this
computer, you can Turn Off the One Drive options.
The next step is installing some basic apps for your Windows 10 computer. No intervention from your side is necessary.
Windows will automatically install the apps for you. It may take several minutes to complete the installation.
As part of installation, you will need to connect your Microsoft account with your OS to access various services like Microsoft
App Store. You will need to use the same Microsoft account to login to your Windows.
You are all set. In a few minutes, Windows 10 will be configured and will be ready for you to use.
Exercise 2:A-Z Index of the Bash command line for Linux
a
b
basename Strip directory and suffix fromfilenames
bg Send to background
c
cal Display a calendar
cd Change Directory
d
date Display or change the date &time
dc Desk Calculator
op Operator access
ps Process status
q
quota Display disk usage and limits
rm Remove files
ss Socket Statistics
V
v Verbosely list directory contents (`ls -l -b')
vi Text Editor
w
w Show who is logged on and what they are doing
whereis Search the user's $path, man pages and source files
for a program
which Search the user's $path for a program file
while Execute commands
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un')
wget Retrieve web pages or files via HTTP, HTTPS or FTP
write Send a message to another user
x
xargs Execute utility, passing constructed argument list(s)
xdg-open Open a file or URL in the user's preferred application
xz Compress or decompress .xz and .lzma files
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid;
Output:
Child process:
PID: [child_pid]
Parent PID: [parent_pid]
Exiting child process
Parent process:
PID: [parent_pid]
Child PID: [child_pid]
Waiting for child process to finish...
Child process finished
Exiting parent process
Exercise 4:
CPU SCHEDULINGALGORITHMS
DESCRIPTION:
To calculate the average waiting time using the FCFS algorithm first the waiting time of the first process
is kept zero and the waiting time of the second process is the burst time of the first process and the
waiting time of the third process is the sum of the burst times of the first and the second process and so
on. After calculating all the waiting times the average waiting time is calculated as the average of all
the waiting times. FCFS mainly says first come first serve the algorithm which camefirst will be served
first.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process name and the burst time
Step 4: Set the waiting of the first process as ‗0‘and its burst time as its turnaround
timeStep 5: for each process in the Ready Q calculate a).Waiting
time (n) = waiting time (n-1) + Burst time (n-1)b). Turnaround
time (n)= waiting time(n)+Burst time(n)
Step 6: Calculate
a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number ofprocess
Step 7: Stop the process
SOURCE CODE :
#include<stdio.h>
int main()
{
int bt[20], wt[20], tat[20], i, n;
float wtavg, tatavg;
printf("\n Enter the number of processes -- ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg = wtavg + wt[i]; tatavg = tatavg + tat[i];
}
printf("\t PROCESS \t BURST TIME \t WAITING TIME\t TURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", i, bt[i], wt[i], tat[i]);
printf("\n Average Waiting Time --%f", wtavg/n);
printf("\n Average Turnaround Time -- %f", tatavg/n);
}
INPUT:
Enter the number of processes – 3
Enter Burst Time for Process 0 -- 24
Enter Burst Time for Process 1 -- 3
Enter Burst Time for Process 2 – 3
Expected Output:
PROCESS BURST TIME WAITING TIME TURNAROUND TIME
P0 24 0 24
P1 3 24 27
P2 3 27 30
Average Waiting Time --17.000000
Average Turnaround Time -- 27.000000
OUTPUT:
B. SHORTEST JOB FIRST:
AIM: To write a program to stimulate the CPU scheduling algorithm Shortest job first (Non- Preemption)
DESCRIPTION:
To calculate the average waiting time in the shortest job first algorithm the sorting of the process based on
their burst time in ascending order then calculate the waiting time of each process as the sum of the bursting
times of all the process previous or before to that process.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Start the Ready Q according the shortest Burst time by sorting according to lowest to
highest burst time.
Step 5: Set the waiting time of the first process as ‗0‘ and its turnaround time as its burst time.
Step 6: Sort the processes names based on their Burt time
Step 7: For each process in the ready queue, calculate
A) Waiting time(n)= waiting time (n-1) + Burst time (n-1)
SOURCE CODE :
#include<stdio.h>
int main()
{
int p[20], bt[20], wt[20], tat[20], i, k, n, temp;
float wtavg, tatavg;
printf("\nEnter the number of processes -- ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
p[i]=i;
printf("Enter Burst Time for Process %d -- ", i);
scanf("%d", &bt[i]);
}
for(i=0;i<n;i++) for(k=i+1;k<n;k++)
if(bt[i]>bt[k])
{
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
wt[0] = wtavg = 0;
tat[0] = tatavg = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] +bt[i-1];
tat[i] = tat[i-1] +bt[i];
wtavg = wtavg + wt[i]; tatavg = tatavg + tat[i];
}
printf("\n\t PROCESS \tBURST TIME \t WAITING TIME\t TURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", p[i], bt[i], wt[i], tat[i]);
printf("\nAverage Waiting Time -- %f", wtavg/n);
printf("\nAverage Turnaround Time -- %f", tatavg/n);
}
INPUT:
Enter the number of processes --4
Enter Burst Time for Process 0 --6
Enter Burst Time for Process 1 --8
Enter Burst Time for Process 2 --7
Enter Burst Time for Process 3 –3
Expected Output:
PROCESS BURST TIME WAITING TIME TURNAROUND TIME
P0 6 3 9
P1 8 16 24
P2 7 9 16
P3 3 0 3
OUTPUT:
C.ROUND ROBIN:
AIM: To simulate the CPU scheduling algorithm round-robin.
DESCRIPTION:
To aim is to calculate the average waiting time. There will be a time slice, each process should be executed
within that time-slice and if not it will go to the waiting state so first check whether the burst time is
less than the time-slice. If it is less than it assign the waiting time to the sum of the total times. If it is
greater than the burst-time then subtract the time slot from the actual burst time and increment it by time-
slot and the loop continues until all the processes are completed.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue and time quantum (or) time slice
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 4: Calculate the no. of time slices for each process where No. of time slice for process (n) = burst
time process (n)/time slice
Step 5: If the burst time is less than the time slice then the no. of time slices =1.
Step 6: Consider the ready queue is a circular Q, calculate
a) Waiting time for process (n) = waiting time of process(n-1)+ burst timeof process(n-1 ) + the
time difference in getting the CPU fromprocess(n-1)
b) Turnaround time for process(n) = waiting time of process(n) + burst time of process(n)+ the time
difference in getting CPU from process(n).
Step 7: Calculate
a)Average waiting time = Total waiting Time / Number of process
a) Average Turnaround time = Total Turnaround Time / Number ofprocessStep 8: Stop the process
SOURCE CODE
#include<stdio.h>
int main()
{
int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;
float awt=0,att=0,temp=0;
printf("Enter the no of processes -- ");
scanf("%d",&n);for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for process %d -- ", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnter the size of time slice -- ");
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i]) max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t)
{
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else
{
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++)
{
wa[i]=tat[i]-ct[i]; att+=tat[i];
awt+=wa[i];
}
printf("\nThe Average Turnaround time is -- %f",att/n);
printf("\nThe Average Waiting time is --%f ",awt/n);
printf("\n\tPROCESS\t BURST TIME \t WAITING TIME\tTURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\t%d \t %d \t\t %d \t\t %d \n",i+1,ct[i],wa[i],tat[i]);
}
INPUT:
Enter the no of processes – 3
Enter Burst Time for process 1 – 24Enter
Burst Time for process 2 -- 3 Enter Burst
Time for process 3 – 3 Enter the size of
time slice – 3 Expected Output:
The Average Turnaround time is -- 15.000000The
Average Waiting time is --5.000000
DESCRIPTION:
To calculate the average waiting time in the priority algorithm, sort the burst times according to their
priorities and then calculate the average waiting time of the processes. The waiting time ofeach process
is obtained by summing up the burst times of all the previous processes.
ALGORITHM:
Step 1: Start the process
Step 2: Accept the number of processes in the ready Queue
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst timeStep 4:Sort the
ready queue according to the priority number.
Step 5: Set the waiting of the first process as ‗0‘ and its burst time as its turnaround timeStep 6:Arrange the
processes based on process priority
Step 7: For each process in the Ready Q calculate
a) Waiting time(n)= waiting time (n-1) + Burst time (n-1)
b) Turnaround time (n)= waiting time(n)+Burst time(n)
Step 8: Calculate
a) Average waiting time = Total waiting Time / Number of process
Average Turnaround time = Total Turnaround Time / Number of process Print theresults in an order.
Step9:Stop
SOURCE CODE :
#include<stdio.h>int
main()
{
int i,j,n,bu[10],wa[10],tat[10],t,ct[10],max;float
awt=0,att=0,temp=0;
printf("Enter the no of processes -- ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Burst Time for process %d -- ", i+1);
scanf("%d",&bu[i]);
ct[i]=bu[i];
}
printf("\nEnter the size of time slice -- ");
scanf("%d",&t);
max=bu[0]; for(i=1;i<n;i++)
if(max<bu[i]) max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++) if(bu[i]!=0)
if(bu[i]<=t)
{
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
}
else
{
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++)
{
wa[i]=tat[i]-ct[i];
att+=tat[i]; awt+=wa[i];
}
printf("\nThe Average Turnaround time is -- %f",att/n);
printf("\nThe Average Waiting time is --%f ",awt/n);
printf("\n\tPROCESS\t BURST TIME \t WAITING TIME\tTURNAROUND TIME\n");
for(i=0;i<n;i++)
printf("\t%d \t %d \t\t %d \t\t %d \n",i+1,ct[i],wa[i],tat[i]);
}
INPUT:
Enter the no of processes – 3
Enter Burst Time for process 1 – 24Enter
Burst Time for process 2 -- 3 Enter Burst
Time for process 3 – 3 Enter the size of
time slice – 3
Expected Output:
The Average Turnaround time is -- 15.000000The
Average Waiting time is --5.000000
PROCESS BURST TIME WAITING TIME TURNAROUND TIME
1 24 6 30
2 3 3 6
3 3 6 9
Exercise 5:Illustrate the inter process communication strategy
Program code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#define BUFFER_SIZE 25
int main() {
int pipefds[2];
pid_t pid;
char buffer[BUFFER_SIZE];
char message[] = "Hello, IPC!";
// Create pipe
if (pipe(pipefds) == -1) {
perror("pipe");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
} else { // Parent process
// Close the read end of the pipe in the parent
close(pipefds[0]);
return 0;
}
Output:
Child process received: Hello, IPC!
Exercise 6:
AIM: To Write a C program to simulate producer-consumer problem using semaphores.
DESCRIPTION
Producer consumer problem is a synchronization problem. There is a fixed size buffer where the
producer produces items and that is consumed by a consumer process. One solution to the producer-
consumer problem uses shared memory. To allow producer and consumer processes to run
concurrently, there must be available a buffer of items that can be filled by the producer and emptied
by the consumer. This buffer will reside in a region of memory that is shared by the producer and
consumer processes. The producer and consumer must be synchronized, so that the consumer does not
try to consume an item that has not yet been produced.
PROGRAM
#include<stdio.h>
int main()
{
int buffer[10], bufsize, in, out, produce, consume,
choice=0; in = 0;
out = 0;
bufsize = 10;
while(choice !=3)
{
printf(“\n1. Produce \t 2. Consume \t3. Exit”);
printf(“\nEnter your choice: ”);
scanf(“%d”,&choice);
switch(choice) {
case 1: if((in+1)%bufsize==out)
printf(“\nBuffer is Full”);
else
{
printf(“\nEnter the value: “);
scanf(“%d”, &produce);
buffer[in] = produce;
in = (in+1)%bufsize;
}
break;;;
AIM: Simulate bankers algorithm for Dead Lock Avoidance (Banker‘s Algorithm)
DESCRIPTION:
Deadlock is a situation where in two or more competing actions are waiting f or the other to finish, and
thus neither ever does. When a new process enters a system, it must declare the maximum number of
instances of each resource type it needed. This number may exceed the total number of resources in the
system. When the user request a set of resources, the system must determine whether the allocation of
each resources will leave the system in safe state. If it will the resources are allocation; otherwise the
process must wait until some other process release the resources.
Data structures Allocation: If Allocation [i, j]=k, Pi allocated to k instances of resource Rj Need: If
Need[I, j]=k, Pi may need k more instances of resource type Rj, Need[I, j]=Max[I, j]- Allocation[I, j];
Safety Algorithm
Work and Finish be the vector of length m and n respectively, Work=Available and Finish[i] =False.
3. Have the system pretend to have allocated the requested resources to process Pi by modifying the
state as follows;
Available=Available-Request I; Allocation I=Allocation +Request I; Need i=Need i- Request I;
If the resulting resource allocation state is safe, the transaction is completed and process Pi is
allocated its resources. However if the state is unsafe, the Pi must wait for Request i and the old
resource-allocation state is restored.
ALGORITHM:
1. Start the program.
2. Get the values of resources and processes.
3. Get the avail value.
4. After allocation find the need value.
5. Check whether its possible to allocate.
6. If it is possible then the system is in safestate.
7. Else system is not in safety state.
8. If the new request comes then check that the system is in safety.
9. or not if we allow the request.
10. stop the program.
11. End.
SOURCE CODE :
#include <stdio.h>
#define MAX_PROCESSES 10
#define MAX_RESOURCES 10
int available[MAX_RESOURCES];
int maximum[MAX_PROCESSES][MAX_RESOURCES];
int allocation[MAX_PROCESSES][MAX_RESOURCES];
int need[MAX_PROCESSES][MAX_RESOURCES];
int num_processes, num_resources;
int count = 0;
while (count < num_processes) {
int found = 0;
for (int i = 0; i < num_processes; i++) {
if (finish[i] == 0) {
int j;
for (j = 0; j < num_resources; j++) {
if (need[i][j] > work[j]) {
break;
}
}
if (j == num_resources) {
for (int k = 0; k < num_resources; k++) {
work[k] += alloc[i][k];
}
finish[i] = 1;
processes[count++] = i;
found = 1;
}
}
}
if (!found) {
break; // If no process found, break the loop
}
}
if (count == num_processes) {
return 1; // If all processes are finished, return true (safe state)
} else {
return 0; // If some processes are unfinished, return false (unsafe state)
}
}
int main() {
printf("Enter the number of processes: ");
scanf("%d", &num_processes);
printf("Enter the number of resources: ");
scanf("%d", &num_resources);
return 0;
}
Expected Output:
Enter the number of processes: 3
Enter the number of resources: 4
Program code:
#include <stdio.h>
#define MAX_PROCESSES 10
#define MAX_RESOURCES 10
void initialize() {
printf("Enter the number of processes: ");
scanf("%d", &n_processes);
printf("Enter the number of resources: ");
scanf("%d", &n_resources);
void detect_deadlock() {
int work[MAX_RESOURCES];
int finish[MAX_PROCESSES] = {0};
int main() {
printf("Deadlock Detection Algorithm\n");
initialize();
detect_deadlock();
return 0;
}
Output:
Number of processes: 3
Number of resources: 3
Allocation matrix:
201
010
121
Request matrix:
100
002
000
Available resources: 1 1 1
Deadlock detected!
Exercise 9:Write C program to implement Threading.
Program code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // Header file for sleep()
#include <pthread.h>
int main() {
pthread_t thread_id;
printf("Before Thread\n");
Output:
Before Thread
Printing GeeksQuiz from Thread
After Thread
Program code:
#include <stdio.h>
#include <stdlib.h>
#define NUM_FRAMES 4
#define NUM_PAGES 10
#define PAGE_SIZE 1024 // Page size in bytes
int main() {
int frames[NUM_FRAMES] = {-1, -1, -1, -1}; // Represents frames, -1 indicates empty frame
int pages[NUM_PAGES]; // Represents pages
int i, j, page, frame, offset, physical_address;
// Accessing pages
printf("Page\tFrame\tOffset\tPhysical Address\n");
for (i = 0; i < NUM_PAGES; i++) {
page = i;
frame = page % NUM_FRAMES;
offset = page * PAGE_SIZE % PAGE_SIZE;
physical_address = frames[frame] * PAGE_SIZE + offset;
if (frames[frame] == -1) {
frames[frame] = i; // Allocate frame for page
}
printf("%d\t%d\t%d\t%d\n", page, frame, offset, physical_address);
}
return 0;
}
Output:
Exercise 11:
MEMORY ALLOCATION TECHNIQUES
AIM: To Write a C program to simulate the following contiguous memory allocation techniques
a) Worst-fit b) Best-fit c) First-fit
PROGRAM
WORST-FIT
#include <stdio.h>
#include <stdlib.h>
int main() {
Block blocks[MAX_BLOCKS];
Process processes[MAX_PROCESS];
int m, n;
// Print allocation
printf("\nMemory allocation after worst fit:\n");
printAllocation(blocks, m, processes, n);
return 0;
}
Output:
Enter the number of memory blocks: 3
Enter the size of memory blocks:
Block 1: 100
Block 2: 200
Block 3: 300
Enter the number of processes: 4
Enter the size of processes:
Process 1: 50
Process 2: 100
Process 3: 250
Process 4: 150
BEST-FIT
Program code:
#include <stdio.h>
int main() {
struct MemoryBlock blocks[MAX_BLOCKS];
int requests[MAX_REQUESTS];
int m, n;
return 0;
}
Output:
Enter the number of memory blocks: 3
Enter the size of each memory block:
10
20
30
Enter the number of memory allocation requests: 2
Enter the size of each memory allocation request:
15
10
Request 1: Allocated block of size 15 at index 1
Request 2: Allocated block of size 10 at index 0
FIRST-FIT
Program code:
#include <stdio.h>
int main() {
int memory[MAX_MEMORY_SIZE], process[MAX_PROCESS_SIZE];
int n, m, i, j;
return 0;
}
Output:
Enter the number of memory blocks: 4
Enter the number of processes: 3
Enter memory block sizes:
Memory block 1: 50
Memory block 2: 20
Memory block 3: 30
Memory block 4: 40
Enter process sizes:
Process 1: 25
Process 2: 10
Process 3: 35
Process 1 allocated to Memory block 1
Process 2 allocated to Memory block 1
Process 3 allocated to Memory block 4
#include<stdio.h>
#include<stdlib.h>
#define MAX_FRAMES 3
int main() {
int pages[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};
int n = sizeof(pages) / sizeof(pages[0]);
int frames = MAX_FRAMES;
return 0;
}
// Function prototypes
void sequential();
void indexed();
void direct();
int main() {
int choice;
do {
printf("\nFile Organization Techniques\n");
printf("1. Sequential File\n");
printf("2. Indexed File\n");
printf("3. Direct File\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
sequential();
break;
case 2:
indexed();
break;
case 3:
direct();
break;
case 4:
printf("Exiting program...\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 4);
return 0;
}
void sequential() {
FILE *file;
Record record;
int choice;
if (file == NULL) {
printf("Error opening file.\n");
return;
}
do {
printf("\nSequential File Operations\n");
printf("1. Add Record\n");
printf("2. Search Record\n");
printf("3. Delete Record\n");
printf("4. Back to Main Menu\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter ID: ");
scanf("%d", &record.id);
printf("Enter Name: ");
scanf("%s", record.name);
printf("Enter Salary: ");
scanf("%f", &record.salary);
addRecord(file, record);
break;
case 2:
printf("Enter ID to search: ");
scanf("%d", &record.id);
if (searchRecord(file, record.id))
printf("Record found.\n");
else
printf("Record not found.\n");
break;
case 3:
printf("Enter ID to delete: ");
scanf("%d", &record.id);
deleteRecord(file, record.id);
break;
case 4:
printf("Returning to Main Menu...\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 4);
fclose(file);
}
void indexed() {
// Implement indexed file organization
printf("Indexed File Organization\n");
}
void direct() {
// Implement direct file organization
printf("Direct File Organization\n");
}
rewind(file);
fclose(file);
fclose(tempFile);
remove("sequential.txt");
rename("temp.txt", "sequential.txt");
}
Output:
File Organization Techniques
1. Sequential File
2. Indexed File
3. Direct File
4. Exit
Enter your choice: 1
Exercise 14:
FILE ALLOCATION STRATEGIES
A) SEQUENTIAL:
AIM: To write a C program for implementing sequential file allocation method
SOURCE CODE :
#include <stdio.h>
#include <stdlib.h>
int main() {
int disk[MAX_BLOCKS];
int diskSize = MAX_BLOCKS;
// Initialize disk
initializeDisk(disk, diskSize);
return 0;
}
return startBlock;
}
Program code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct IndexTable {
int blockNumber;
bool occupied;
};
int main() {
int numBlocks;
printf("Enter the number of blocks: ");
scanf("%d", &numBlocks);
switch (choice) {
case 1:
blockNum = allocateBlock(indexTable, numBlocks);
if (blockNum != -1)
printf("Block allocated at index %d.\n", blockNum);
else
printf("No free blocks available.\n");
break;
case 2:
printf("Enter the block number to deallocate: ");
scanf("%d", &blockNum);
deallocateBlock(indexTable, blockNum);
printf("Block at index %d deallocated.\n", blockNum);
break;
case 3:
displayIndexTable(indexTable, numBlocks);
break;
case 4:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 4);
return 0;
}
Output:
Enter the number of blocks: 5
1. Allocate Block
2. Deallocate Block
3. Display Index Table
4. Exit
Enter your choice: 1
Block allocated at index 0.
1. Allocate Block
2. Deallocate Block
3. Display Index Table
4. Exit
Enter your choice: 1
Block allocated at index 1.
1. Allocate Block
2. Deallocate Block
3. Display Index Table
4. Exit
Enter your choice: 1
Block allocated at index 2.
1. Allocate Block
2. Deallocate Block
3. Display Index Table
4. Exit
Enter your choice: 3
Index Table:
Block Number | Occupied
0 | Yes
1 | Yes
2 | Yes
-1 | No
-1 | No
1. Allocate Block
2. Deallocate Block
3. Display Index Table
4. Exit
Enter your choice: 2
Enter the block number to deallocate: 1
Block at index 1 deallocated.
1. Allocate Block
2. Deallocate Block
3. Display Index Table
4. Exit
Enter your choice: 3
Index Table:
Block Number | Occupied
0 | Yes
-1 | No
2 | Yes
-1 | No
-1 | No
1. Allocate Block
2. Deallocate Block
3. Display Index Table
4. Exit
Enter your choice: 4
Exiting...
C) LINKED:
Program code:
#include <stdio.h>
#include <stdlib.h>
k = length;
if (pages[startBlock] == 0) {
for (j = startBlock; j < (startBlock + k); j++) {
if (pages[j] == 0) {
pages[j] = 1;
printf("%d ------> %d\n", j, pages[j]);
} else {
printf("Block %d is already allocated.\n", j);
break;
}
}
} else {
printf("Block %d is already allocated.\n", startBlock);
}
}
int main() {
int numFiles, i;
printf("Enter the number of files: ");
scanf("%d", &numFiles);
return 0;
}
Output:
Enter the number of files: 1
Enter the index of the starting block and its length for File 1: 2
3
2 ------> 1
3 ------> 1
4 ------> 1
Program code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main() {
int requests[MAX_REQUESTS];
int n, head, direction;
sort(requests, n);
fcfs(requests, n, head);
sstf(requests, n, head);
scan(requests, n, head, direction);
cscan(requests, n, head, direction);
look(requests, n, head, direction);
clook(requests, n, head, direction);
return 0;
}
Output:
Enter the number of requests: 5
Enter the requests: 98 183 37 122 14
Enter the initial position of head: 53
Enter the direction of movement (1 for towards 0, 0 for away from 0): 1
FCFS Schedule:
Move from 53 to 37
Move from 37 to 14
Move from 14 to 98
Move from 98 to 122
Move from 122 to 183
Total seek time: 261
SSTF Schedule:
Move from 53 to 37
Move from 37 to 14
Move from 14 to 98
Move from 98 to 122
Move from 122 to 183
Total seek time: 261
SCAN Schedule:
Move from 53 to 37
Move from 37 to 14
Move from 14 to 0
Move from 0 to 98
Move from 98 to 122
Move from 122 to 183
Total seek time: 408
C-SCAN Schedule:
Move from 53 to 37
Move from 37 to 14
Move from 14 to 0
Move from 0 to 199
Move from 199 to 98
Move from 98 to 122
Move from 122 to 183
Total seek time: 484
LOOK Schedule:
Move from 53 to 37
Move from 37 to 14
Move from 14 to 0
Move from 0 to 98
Move from 98 to 122
Move from 122 to 183
Total seek time: 386
C-LOOK Schedule:
Move from 53 to 37
Move from 37 to 14
Move from 14 to 0
Move from 0 to 199
Move from 199 to 98
Move from 98 to 122
Move from 122 to 183
Total seek time: 484
Exercise 16: Install any guest operating system like linux using VMware.