GROUP INSITUTIONS
KOMARAPALAYAM
College Name: EXCEL ENGINEERING COLLEGE (Autonomous)
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
LABORATORY RECORD NOTEBOOK
Certified that this bonafide record of work done by
Selvan / Selvi Reg. No
of the III semester B. Tech -CSBS branch during the Academic Year 2025-2026 in the
23IT403 - OPERATING SYSTEMS LABORATORY
Signature of Lab-Incharge Signature of Head of the Department
Submitted for the Practical Examination held on
Internal Examiner External Examiner
EXCEL ENGINEERING COLLEGE, KOMARAPALAYAM
(AUTONOMOUS)
Department of Computer Science and Business Systems
Vision
To be a center of excellence in Computer Science and Business Systems by imparting futuristic knowledge
and skills, fostering innovation, and nurturing ethically sound professionals to meet global industry and
societal demands.
Mission
To deliver a comprehensive education in Computer Science and Business Systems integrating technical
expertise with contemporary business principles.
To enhance employability skills by promoting innovation, problem solving and adaptability to emerging
technologies.
To inculcate ethical values and social responsibility in students ensuring their contribution to sustainable
development.
To foster partnerships with industries, academia, and research organizations for lifelong learning and
professional growth.
Program Educational Objectives (PEOs)
Professional Competence
Graduates will demonstrate expertise in Computer Science and Business Systems, applying technical and
business knowledge to solve real-world problems effectively.
Innovation and Lifelong Learning
Graduates will engage in innovative practices and continuous learning to adapt to evolving technologies and
dynamic business environments.
Ethical and Social Responsibility
Graduates will uphold ethical values, contribute to sustainable development, and address societal challenges
with a sense of responsibility.
Leadership and Collaboration
Graduates will exhibit leadership qualities and excel in multidisciplinary teamwork to achieve organizational
and personal goals in global settings.
PSOs
To display competence in Computer Science while appreciating the significance of the management sciences and
human ethics
To formulate, identify, and apply relevant strategies, resources, and advanced engineering and business technologies,
including predictive modeling and data analytics, to complex engineering and business activities
INDEX
EXP.NO DATE MARKS SIGNATURE
Name of the Experiment
1. Implement various UNIX system calls Process
management, File management and I/O
system calls.
2. Implementation Of CPU Scheduling
Algorithms.
A) FCFS B) SJF C) PRIORITY D) ROUND
ROBIN
3. Implement the solution for Producer-
Consumer Problem using Semaphores .
4. Simulate Banker’s Algorithm For Deadlock
Avoidance.
5. Develop a program to simulate page
replacement using FIFO,LRU and Optimal
algorithms
6. Write a program to simulate the following file
allocation strategies A)SEQUENTIAL
B)LINKED C) INDEXED
7. Simulate Disk scheduling algorithms A) FCFS
B) SCAN
8. Implement a new system call, add this new
system call in the Linux kernel (any kernel
source, any architecture and any Linux kernel
distribution) and demonstrate the use of same.
9. Install a C compiler (GCC) in a virtual
machine created using VirtualBox and execute
simple C programs.
1. Implement various UNIX system calls Process management, File management and
I/O system calls.
AIM:
To simulate basic UNIX system call functionalities such as process management, file management, and input/output
system calls using Turbo C++.
ALGORITHMS:
1. Start the Program
2. Print the title "Turbo C++ Simulation of UNIX Concepts" to indicate the start.
3. Simulate Process Management
4. Simulate File Management
5. Simulate I/O System Calls.
6. End of Program
PROGRAM:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h> // For delay(), not a UNIX function but works in Turbo C++
void simulate_process() {
printf("\nSimulating Process Task...");
delay(1000); // Simulate delay for "processing"
printf("\nProcess completed.\n");
}
void file_management() {
FILE *fp;
char data[100];
// Create and write to file
fp = fopen("demo.txt", "w");
if (fp == NULL) {
printf("File creation failed!\n");
return;
}
printf("Enter some text to save to file: ");
fflush(stdin);
gets(data);
fprintf(fp, "%s", data);
fclose(fp);
printf("Data written to file successfully.\n");
// Read from file
fp = fopen("demo.txt", "r");
if (fp == NULL) {
printf("Unable to open file!\n");
return;
}
printf("\nReading from file:\n");
while (fgets(data, sizeof(data), fp)) {
printf("%s", data);
}
fclose(fp);
}
void io_system() {
char name[50];
int age;
printf("\n--- User Input Demo ---\n");
printf("Enter your name: ");
fflush(stdin);
gets(name);
printf("Enter your age: ");
scanf("%d", &age);
printf("\n--- Output ---\n");
printf("Hello %s! You are %d years old.\n", name, age);
}
void main() {
clrscr();
printf("=== Turbo C++ Simulation of UNIX Concepts ===\n");
printf("\n1. Simulating Process Management");
simulate_process();
printf("\n2. File Management");
file_management();
printf("\n3. I/O System Call Simulation");
io_system();
printf("\nProgram Complete.");
getch();
}
OUTPUT:
=== Turbo C++ Simulation of UNIX Concepts ===
1. Simulating Process Management
Simulating Process Task...
Process completed.
2. File Management
Enter some text to save to file: Hello from Turbo C++
Data written to file successfully.
Reading from file:
Hello from Turbo C++
3. I/O System Call Simulation
Enter your name: Raj
Enter your age: 20
--- Output ---
Hello Raj! You are 20 years old.
Program Complete.
Result:
Thus the given program executed and verified successfully.
2) Implementation Of CPU Scheduling Algorithms.
A) FCFS B) SJF C) PRIORITY D) ROUND ROBIN
A) FIRST-COME, FIRST-SEREVE (FCFS)
AIM:
To write a C program for to calculate average waiting and turnaround time.
ALGORITHM:
1) Start the program.
2) Sort processes by arrival time.
3) Calculate the start time for each process.
4) Compute waiting time (WT) as the start time minus the arrival time.
5) Compute turnaround time (TAT) as the waiting time plus the burst time.
6) Calculate average waiting and turnaround times.
PROGRAM:
#include <stdio.h>
int main() {
int n, i, bt[10], wt[10], tat[10], total_wt = 0, total_tat = 0;
printf("Enter number of processes: ");
scanf("%d", &n);
printf("Enter burst times:\n");
for(i = 0; i< n; i++) scanf("%d", &bt[i]);
wt[0] = 0;
for(i = 1; i< n; i++) wt[i] = wt[i-1] + bt[i-1];
for(i = 0; i< n; i++) {
tat[i] = bt[i] + wt[i];
total_wt += wt[i];
total_tat += tat[i]; }
printf("\nAverage Waiting Time: %.2f", (float)total_wt/n);
printf("\nAverage Turnaround Time: %.2f\n", (float)total_tat/n);
return 0;
OUTPUT:
Enter number of processes: 4
Enter burst times:
5386
Average Waiting Time: 7.25
Average Turnaround Time: 12.75
B) SHORTEST JOB FIRST (SJF)
AIM:
To write a C program for to calculate average waiting and turnaround time.
ALGORITHM:
1) Sort processes by burst time.
2) Calculate the start time for each process.
3) Compute waiting time (WT) as the start time minus the arrival time.
4) Compute turnaround time (TAT) as the waiting time plus the burst time.
5) Calculate average waiting and turnaround times.
PROGRAM:
#include <stdio.h>
int main() {
int n, i, j, pos, temp, bt[10], p[10], wt[10], tat[10], total_wt = 0, total_tat = 0;
printf("Enter number of processes: ");
scanf("%d", &n);
printf("Enter burst times:\n");
for(i = 0; i< n; i++) scanf("%d", &bt[i]);
for(i = 0; i< n; i++) {
pos = i;
for(j = i+1; j < n; j++)
if(bt[j] <bt[pos]) pos = j;
temp = bt[i]; bt[i] = bt[pos]; bt[pos] = temp;
wt[0] = 0;
for(i = 1; i< n; i++) wt[i] = wt[i-1] + bt[i-1];
for(i = 0; i< n; i++) {
tat[i] = bt[i] + wt[i];
total_wt += wt[i];
total_tat += tat[i];
printf("\nAverage Waiting Time: %.2f", (float)total_wt/n);
printf("\nAverage Turnaround Time: %.2f\n", (float)total_tat/n);
return 0;
OUTPUT:
Enter number of processes: 4
Enter burst times:
6873
Average Waiting Time: 7.00
Average Turnaround Time: 13.00
C) PRIORITY SCHEDULING
AIM:
To write a C program for to calculate average waiting and turnaround time.
ALGORITHM:
1) Sort processes by priority.
2) Calculate the start time for each process.
3) Compute waiting time (WT) as the start time minus the arrival time.
4) Compute turnaround time (TAT) as the waiting time plus the burst time.
5) Calculate average waiting and turnaround times.
PROGRAM :
#include <stdio.h>
int main() {
int n, i, j, pos, temp, bt[10], pr[10], wt[10], tat[10], total_wt = 0, total_tat = 0;
printf("Enter number of processes: ");
scanf("%d", &n);
printf("Enter burst times and priorities:\n");
for(i = 0; i< n; i++) {
scanf("%d%d", &bt[i], &pr[i]);
for(i = 0; i< n; i++) {
pos = i;
for(j = i + 1; j < n; j++)
if(pr[j] < pr[pos]) pos = j;
temp = pr[i]; pr[i] = pr[pos]; pr[pos] = temp;
temp = bt[i]; bt[i] = bt[pos]; bt[pos] = temp;
}
wt[0] = 0;
for(i = 1; i< n; i++) wt[i] = wt[i-1] + bt[i-1];
for(i = 0; i< n; i++) {
tat[i] = bt[i] + wt[i];
total_wt += wt[i];
total_tat += tat[i];
printf("\nAverage Waiting Time: %.2f", (float)total_wt/n);
printf("\nAverage Turnaround Time: %.2f\n", (float)total_tat/n);
return 0;
OUTPUT:
Enter number of processes: 4
Enter burst times and priorities:
6 2
8 1
7 3
3 2
Average Waiting Time: 9.75
Average Turnaround Time: 15.75
D) ROUND ROBIN (RR)
AIM:
To write a C program for to calculate average waiting and turnaround time.
ALGORITHM:
1) Assign a time quantum (TQ).
2) Execute each process for TQ or until completion.
3) If incomplete, move the process to the end of the queue.
4) Repeat until all processes are complete.
5) Calculate average waiting and turnaround times.
PROGRAM :
#include <stdio.h>
int main() {
int n, i, tq, t = 0, bt[10], rem_bt[10], wt[10] = {0}, tat[10], total_wt = 0, total_tat = 0;
printf("Enter number of processes: ");
scanf("%d", &n);
printf("Enter burst times:\n");
for(i = 0; i< n; i++) {
scanf("%d", &bt[i]);
rem_bt[i] = bt[i];
printf("Enter time quantum: ");
scanf("%d", &tq);
while(1) {
int done = 1;
for(i = 0; i< n; i++) {
if(rem_bt[i] > 0) {
done = 0;
int t_inc = rem_bt[i] >tq ?tq : rem_bt[i];
t += t_inc;
rem_bt[i] -= t_inc;
if(rem_bt[i] == 0) wt[i] = t - bt[i];
}
if(done) break;
for(i = 0; i< n; i++) {
tat[i] = bt[i] + wt[i];
total_wt += wt[i];
total_tat += tat[i];
printf("\nAvg Waiting Time: %.2f", (float)total_wt/n);
printf("\nAvg Turnaround Time: %.2f\n", (float)total_tat/n);
return 0;
OUTPUT:
Enter number of processes: 4
Enter burst times:
5 15 4 3
Enter time quantum: 5
Avg Waiting Time: 9.00
Avg Turnaround Time: 15.75
Result:
Thus the given program executed and verified successfully.
3) Implement the solution for Producer-Consumer Problem using Semaphores
AIM:
To solve the Producer-Consumer Problem using semaphores to manage synchronization and avoid race
conditions between the producer and consumer.
ALGORITHM:
1. Initialize semaphores: mutex = 1, empty = N, full = 0.
2. Producer waits on empty and mutex.
3. Add item to the buffer and signal full.
4. Consumer waits on full and mutex.
5. Remove item from the buffer and signal empty.
6. Repeat until production or consumption stops.
PROGRAM:
#include <stdio.h>
#include <conio.h>
#include <dos.h> // For delay()
#define BUFFER_SIZE 5
int buffer[BUFFER_SIZE];
int in = 0, out = 0;
int empty = BUFFER_SIZE;
int full = 0;
int mutex = 1;
void wait(int *s) {
while (*s <= 0) delay(10);
(*s)--;
}
void signal(int *s) {
(*s)++;
}
void producer() {
int item;
item = in + 1;
wait(&empty);
wait(&mutex);
buffer[in] = item;
printf("Produced: %d at %d\n", item, in);
in = (in + 1) % BUFFER_SIZE;
signal(&mutex);
signal(&full);
delay(500);
}
void consumer() {
int item;
wait(&full);
wait(&mutex);
item = buffer[out];
printf("Consumed: %d from %d\n", item, out);
out = (out + 1) % BUFFER_SIZE;
signal(&mutex);
signal(&empty);
delay(1000);
}
void main() {
clrscr();
int i;
for (i = 0; i < 10; i++) {
producer();
consumer();
}
printf("\nProcessing completed.\n");
getch();
}
OUTPUT:
Produced: 1 at 0
Consumed: 1 from 0
Produced: 2 at 1
Consumed: 2 from 1
Produced: 3 at 2
Consumed: 3 from 2
Produced: 4 at 3
Consumed: 4 from 3
Produced: 5 at 4
Consumed: 5 from 4
Produced: 6 at 0
Consumed: 6 from 0
Produced: 7 at 1
Consumed: 7 from 1
Produced: 8 at 2
Consumed: 8 from 2
Produced: 9 at 3
Consumed: 9 from 3
Produced: 10 at 4
Consumed: 10 from 4
Processing completed.
Result:
Thus the given program executed and verified successfully.
4. Simulate Banker’s Algorithm For Deadlock Avoidance.
AIM:
To Simulate bankers algorithm for Dead Lock Avoidance (Banker‘s Algorithm)
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 safe state.
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.
PROGRAM :
#include <stdio.h>
#include <conio.h>
void main() {
int alloc[10][10], max[10][10], need[10][10];
int avail[10], work[10], total[10];
int finish[10];
int i, j, k, n, m, count = 0, c;
clrscr();
printf("Enter number of processes and resources: ");
scanf("%d%d", &n, &m);
printf("Enter total instances of each resource:\n");
for (j = 0; j < m; j++)
scanf("%d", &total[j]);
printf("Enter Allocation matrix:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &alloc[i][j]);
}
}
printf("Enter Max matrix:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &max[i][j]);
}
}
// Calculate available resources
for (j = 0; j < m; j++) {
int sum = 0;
for (i = 0; i < n; i++)
sum += alloc[i][j];
avail[j] = total[j] - sum;
work[j] = avail[j];
}
// Initialize finish array
for (i = 0; i < n; i++)
finish[i] = 0;
// Calculate need matrix
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
need[i][j] = max[i][j] - alloc[i][j];
}
}
A:
for (i = 0; i < n; i++) {
if (finish[i] == 0) {
c = 0;
for (j = 0; j < m; j++) {
if (need[i][j] <= work[j])
c++;
}
if (c == m) {
printf("Process %d can execute.\n", i + 1);
for (k = 0; k < m; k++) {
work[k] += alloc[i][k];
}
finish[i] = 1;
count++;
goto A;
}
}
}
if (count == n) {
printf("\nSystem is in safe state.\n");
} else {
printf("\nSystem is in unsafe state.\n");
}
getch();
}
OUTPUT:
Enter number of processes and resources: 3 3
Enter total instances of each resource:
10 5 7
Enter Allocation matrix:
010
200
302
Enter Max matrix:
753
322
902
Process 2 can execute.
Process 1 can execute.
Process 3 can execute.
System is in safe state.
Result:
Thus the given program executed and verified successfully.
5. IMPLEMENTATION OF PAGE REPLACEMENT ALGORITHMS
5. A) FIFO – First In First Out
AIM:
To simulate the FIFO (First-In First-Out) Page Replacement Algorithm and calculate the total number of page
faults when a set of pages is referenced by a program, and a fixed number of memory frames are available.
ALGORITHM:
1. Input the number of pages to be referenced and their values.
2. Input the number of memory frames available.
3. Initialize all frames as empty (-1).
4. Repeat for each page in the reference string:
o Check if the page is already in one of the frames:
If yes, it’s a page hit — do nothing.
If no, it’s a page fault:
Replace the oldest page in the frame with the new page (FIFO method).
Increase the page fault count.
o Display the current state of the memory frames.
5. After all pages are processed, print the total number of page faults.
PROGRAM :
#include <stdio.h>
int main() {
int i, j = 0, k, n, no, a[50], frame[10], avail, count = 0;
printf("\nEnter the number of pages:\n");
scanf("%d", &n);
printf("Enter the page numbers:\n");
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
printf("Enter the number of frames:\n");
scanf("%d", &no);
for (i = 0; i < no; i++)
frame[i] = -1; // Initialize all frames to -1
printf("\nRef String\t Page Frames\n");
for (i = 0; i < n; i++) {
printf("%d\t\t", a[i]);
avail = 0;
for (k = 0; k < no; k++) {
if (frame[k] == a[i]) {
avail = 1; // Page hit
break;
}
}
if (avail == 0) {
frame[j] = a[i]; // FIFO: Replace oldest
j = (j + 1) % no;
count++;
for (k = 0; k < no; k++) {
if (frame[k] != -1)
printf("%d\t", frame[k]);
else
printf("-\t");
}
}
printf("\n");
}
printf("\nTotal Page Faults = %d\n", count);
return 0;
}
Input:
Enter the number of pages:
12
Enter the page numbers:
123412512345
Enter the number of frames:
3
OUTPUT:
Ref String Page Frames
1 1 - -
2 1 2 -
3 1 2 3
4 4 2 3
1 4 1 3
2 4 1 2
5 5 1 2
1
2
3 3 1 2
4 3 4 2
5 3 4 5
Total Page Faults = 9
5. B) LRU algorithms
AIM:
To simulate the LRU (Least Recently Used) Page Replacement Algorithm and calculate the total number
of page faults and page fault rate using a given page reference string and fixed number of memory frames.
ALGORITHM:
1. Start the program.
2. Give Input for the program.
3. Give Initialize
4. For each page in the reference string
5. After processing each page, display current frame contents.
6. Calculate page fault rate as:
page fault rate = (page faults / total pages)
7. Print the total page faults and fault rate.
8. End the program.
PROGRAM:
#include <stdio.h>
#include <conio.h>
int f[30], fs;
int cnt[30];
int flag, ps[30];
void increment(int ele);
void check( int ele);
int main() {
int p, i, pos = 0, j = 0, k, max, pf = 0;
float pfr;
clrscr();
printf("Enter number of pages: ");
scanf("%d", &p);
printf("Enter the pages: ");
for (i = 0; i < p; i++)
scanf("%d", &ps[i]);
printf("Enter the frame size: ");
scanf("%d", &fs);
for (k = 0; k < fs; k++) {
f[k] = -999;
cnt[k] = 0;
}
for (i = 0; i < p; i++) {
flag = 0;
check(fs, ps[i]);
if (flag == 0) {
if (j < fs) {
f[j] = ps[i];
for (k = 0; k <= j; k++)
cnt[k] += 1;
j++;
} else {
max = cnt[0];
pos = 0;
for (k = 1; k < fs; k++) {
if (max < cnt[k]) {
max = cnt[k];
pos = k;
}
}
f[pos] = ps[i];
increment(ps[i]);
}
pf++;
}
for (k = 0; k < fs; k++) {
if (f[k] != -999)
printf("%4d", f[k]);
else
printf(" -");
}
printf("\n");
}
pfr = (float)pf / p;
printf("\nTotal number of page faults: %d\n", pf);
printf("Page fault rate: %.2f\n", pfr);
getch();
return 0;
}
void increment(int ele) {
int k;
for (k = 0; k < fs; k++) {
if (f[k] == ele)
cnt[k] = 1;
else
cnt[k] += 1;
}
}
void check( int ele) {
int k;
for (k = 0; k < fs; k++) {
if (f[k] == ele) {
cnt[k] = 1;
flag = 1;
}
}
}
Input:
Enter number of pages: 8
Enter the pages: 1 2 3 2 4 1 5 2
Enter the frame size: 3
OUTPUT:
1 - -
1 2 -
1 2 3
1 2 3
4 2 3
4 1 3
5 1 3
5 2 3
Total number of page faults: 6
Page fault rate: 0.75
Result:
Thus the given program executed and verified successfully.
6. IMPLEMENT ALL FILE ALLOCATION STRATEGIES
6. A) SEQUENTIAL FILE ALLOCATION
AIM:
To write a C program to simulate Sequential File Allocation in memory management.
The program should allocate memory blocks sequentially for files and handle allocation failures if blocks are already
occupied.
ALGORITHM:
1. Start the program.
2. Initialize an array f[50] with all elements set to 0 to indicate that all memory blocks are free.
3. Repeat the following steps for each file (inside a do-while loop):
4. Input the starting block number (st) and the length of the file (len).
5. Set a flag variable flag = 0.
6. Check if the required blocks from st to st + len - 1 are free:
7. If flag == 0 (i.e., all required blocks are free):
8. If flag == 1:
9. Ask the user whether they want to continue entering files (press 1 for yes, 0 for no).
10. Repeat the process until the user chooses to stop.
11. End the program.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
int main() {
int f[50], i, st, j, len, c, k;
// Initialize all blocks to 0 (free)
for(i = 0; i < 50; i++)
f[i] = 0;
do {
int flag = 0;
printf("\nEnter the starting block & length of the file: ");
scanf("%d%d", &st, &len);
// Check if allocation is possible
for(j = st; j < st + len; j++) {
if(f[j] == 1) {
flag = 1;
break;
}
}
if(flag == 0) {
for(j = st; j < st + len; j++) {
f[j] = 1;
printf("\n%d -> Allocated", j);
}
printf("\nThe file is allocated to disk successfully.");
} else {
printf("\nBlock already allocated, file not allocated.");
}
printf("\nDo you want to enter more files? (Yes = 1 / No = 0): ");
scanf("%d", &c);
} while(c == 1);
getch();
return 0;
}
OUTPUT:
Enter the starting block & length of the file: 5 4
5 -> Allocated
6 -> Allocated
7 -> Allocated
8 -> Allocated
The file is allocated to disk successfully.
Do you want to enter more files? (Yes = 1 / No = 0): 1
Enter the starting block & length of the file: 7 3
Block already allocated, file not allocated.
Do you want to enter more files? (Yes = 1 / No = 0): 1
Enter the starting block & length of the file: 10 2
10 -> Allocated
11 -> Allocated
The file is allocated to disk successfully.
Do you want to enter more files? (Yes = 1 / No = 0): 0
6. B) LINKED FILE ALLOCATION
AIM:
To implement a C program for Indexed File Allocation in memory management.
The objective is to simulate how a file is allocated non-contiguously using an index block, and to track which
blocks are already allocated or free.
ALGORITHM:
1. Start the program.
2. Initialize an array f[50] to 0, where each element represents a disk block:
3. 0 → Free block
4. 1 → Allocated block
5. Input how many blocks (p) are already allocated.
6. Input the block numbers (a) that are already allocated:
7. Set f[a] = 1 for each valid block number entered.
8. If an invalid block number is entered (outside 0–49), display an error message.
9. Ask the user whether they want to allocate another file (Yes = 1, No = 0).
10. Repeat until the user chooses not to continue.
11. End the program.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main() {
int f[50], p, i, j, k, a, st, len, c;
// Initialize all blocks as free
for(i = 0; i < 50; i++)
f[i] = 0;
printf("Enter how many blocks are already allocated: ");
scanf("%d", &p);
printf("Enter the block numbers that are already allocated: ");
for(i = 0; i < p; i++) {
scanf("%d", &a);
if (a >= 0 && a < 50)
f[a] = 1;
else
printf("Invalid block number: %d\n", a);
}
do {
printf("\nEnter the starting index block & length: ");
scanf("%d%d", &st, &len);
int count = 0;
k = len;
for(j = st; count < len && j < 50; j++) {
if(f[j] == 0) {
f[j] = 1;
printf("%d -> Allocated\n", j);
count++;
} else {
printf("%d -> Already allocated\n", j);
k++;
}
}
if(count == len) {
printf("File allocated successfully.\n");
} else {
printf("File allocation failed. Not enough space.\n");
}
printf("Do you want to enter one more file? (Yes = 1 / No = 0): ");
scanf("%d", &c);
} while(c == 1);
return 0;
}
OUTPUT:
Enter how many blocks are already allocated: 3
Enter the block numbers that are already allocated: 2 3 5
Enter the starting index block & length: 4 4
4 -> Allocated
5 -> Already allocated
6 -> Allocated
7 -> Allocated
8 -> Allocated
File allocated successfully.
Do you want to enter one more file? (Yes = 1 / No = 0): 1
Enter the starting index block & length: 2 2
2 -> Already allocated
3 -> Already allocated
4 -> Already allocated
5 -> Already allocated
File allocation failed. Not enough space.
Do you want to enter one more file? (Yes = 1 / No = 0): 0
6. C) INDEXED LIST
AIM:
To implement a C program to simulate Indexed File Allocation method in memory management.
This method allocates one index block per file which stores the addresses of all data blocks used by the file.
ALGORITHM:
1. Start the program.
2. Initialize an array f[50] with all values as 0, indicating that all blocks are initially free.
3. Use a do-while loop to allow multiple file entries.
4. Inside the loop:
o Input the index block number p.
5. Input the number of blocks required by the file n.
6. Input the block numbers that the file will use into an array inde[].
7. Check each block number in inde[]:
o If any block is already allocated ( f[inde[i]] == 1), display a message:
8. If all file blocks are free, allocate them by setting f[inde[j]] = 1.
9. Display successful allocation:
o Print the index block and its corresponding file blocks.
10. Ask the user whether they want to enter another file (1 = yes, 0 = no).
11. Repeat the loop until the user chooses to stop.
12. End the program.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main() {
int f[50], i, k, j, inde[50], n, c, p;
// Initialize all blocks as free
for(i = 0; i < 50; i++)
f[i] = 0;
do {
printf("\nEnter the index block: ");
scanf("%d", &p);
if(f[p] == 1) {
printf("Block already allocated. Try another index block.\n");
continue;
}
f[p] = 1; // Allocate index block
printf("Enter number of blocks for the file: ");
scanf("%d", &n);
printf("Enter the block numbers:\n");
for(i = 0; i < n; i++) {
scanf("%d", &inde[i]);
}
// Check if any of the blocks are already allocated
int flag = 0;
for(i = 0; i < n; i++) {
if(f[inde[i]] == 1) {
flag = 1;
break;
}
}
if(flag == 1) {
printf("One or more blocks are already allocated. File cannot be stored.\n");
f[p] = 0; // Free index block
continue;
}
// Allocate blocks
for(j = 0; j < n; j++) {
f[inde[j]] = 1;
}
printf("\nFile allocated successfully using Indexed Allocation.\n");
printf("Index Block: %d\n", p);
for(k = 0; k < n; k++) {
printf("%d -> %d\n", p, inde[k]);
}
printf("\nEnter 1 to add another file or 0 to exit: ");
scanf("%d", &c);
} while(c == 1);
return 0;
}
OUTPUT:
Enter the index block: 5
Enter number of blocks for the file: 3
Enter the block numbers:
10 11 12
File allocated successfully using Indexed Allocation.
Index Block: 5
5 -> 10
5 -> 11
5 -> 12
Enter 1 to add another file or 0 to exit: 1
Enter the index block: 10
Block already allocated. Try another index block.
Enter the index block: 6
Enter number of blocks for the file: 2
Enter the block numbers:
12 13
One or more blocks are already allocated. File cannot be stored.
Enter the index block: 7
Enter number of blocks for the file: 2
Enter the block numbers:
20 21
File allocated successfully using Indexed Allocation.
Index Block: 7
7 -> 20
7 -> 21
Enter 1 to add another file or 0 to exit: 0
Result:
Thus the given program executed and verified successfully.
7 . Simulate the Disk Scheduling Algorithms.
A) FCFS B)SCAN
A) FCFS DISK SCHEDULING ALGORITHM
AIM:
To write a C program to calculate the total and average head movements during disk scheduling based on a given
sequence of track requests.
ALGORITHM:
1. Start the program.
2. Input the total number of tracks to be traversed (n).
3. Input the track numbers in the order they are accessed, and store them in array t[].
4. For each consecutive pair of tracks (t[i] and t[i+1]):
5. Calculate the absolute difference between the two tracks.
6. Store the result in the array tohm[] (total head movement between pairs).
7. Initialize a variable tot = 0 and:
8. Sum all the values in tohm[] to get the total head movements.
9. Calculate the average head movement .
10. End the program.
PROGRAM :
#include <stdio.h>
#include <stdlib.h>
int main() {
int t[20], n, i, tohm[20], tot = 0;
float avhm;
printf("Enter the number of tracks to be traversed: ");
scanf("%d", &n);
printf("Enter the track numbers:\n");
for(i = 0; i < n; i++) {
scanf("%d", &t[i]);
}
for(i = 0; i < n - 1; i++) {
tohm[i] = abs(t[i + 1] - t[i]);
}
for(i = 0; i < n - 1; i++) {
tot += tohm[i];
}
avhm = (float)tot / (n - 1);
printf("\nTracks Traversed\tDifference between tracks\n");
for(i = 0; i < n - 1; i++) {
printf("%d -> %d\t\t\t%d\n", t[i], t[i + 1], tohm[i]);
}
printf("\nTotal head movements: %d", tot);
printf("\nAverage head movement: %.2f\n", avhm);
return 0;
}
OUTPUT:
Enter the number of tracks to be traversed: 5
Enter the track numbers:
100
150
90
120
180
Tracks Traversed Difference between tracks
100 -> 150 50
150 -> 90 60
90 -> 120 30
120 -> 180 60
Total head movements: 200
Average head movement: 50.00
B) SCAN DISK SCHEDULING ALGORITHM
AIM:
To write a C program to simulate the SCAN (Elevator) Disk Scheduling Algorithm, and calculate the total and
average head movement for a given set of track requests and initial head position.
ALGORITHM:
1. Start the program.
2. Give Input Total number of track requests (n).Initial position of the disk head (h).The list of track
requests (t[]).
3. Add the start of the disk (0) and the initial head position (h) to the track list.
4. Sort the entire track list (including 0 and head position) in ascending order.
5. Find the position of the head (h) in the sorted array.
6. Simulate SCAN movement:
7. Move the head left (towards track 0), store the order in array atr[].
8. After reaching 0, reverse direction and move right, processing remaining requests.
9. Calculate head movements:
10. For each pair of consecutive tracks in the atr[] list, calculate the absolute difference and sum it to get
total head movement.
11. Compute average head movement
12. Display The order of track traversal And total and average head movement.
13. End the program.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main() {
int t[20], d[20], h, i, j, n, temp, k, atr[20], tot, p, sum = 0;
float avg;
printf("Enter the number of tracks to be traversed: ");
scanf("%d", &n);
printf("Enter the initial position of the head: ");
scanf("%d", &h);
t[0] = 0; // Start of disk
t[1] = h;
printf("Enter the track numbers:\n");
for(i = 2; i < n + 2; i++) {
scanf("%d", &t[i]);
}
// Sort all tracks (including head and 0)
for(i = 0; i < n + 2; i++) {
for(j = 0; j < (n + 2) - i - 1; j++) {
if(t[j] > t[j + 1]) {
temp = t[j];
t[j] = t[j + 1];
t[j + 1] = temp;
}
}
}
// Find position of head in sorted list
for(i = 0; i < n + 2; i++) {
if(t[i] == h) {
j = i;
k = i;
break;
}
}
// Move left (towards 0)
p = 0;
while(j >= 0) {
atr[p++] = t[j--];
}
// Move right from k+1
for(i = k + 1; i < n + 2; i++) {
atr[p++] = t[i];
}
// Calculate differences between each movement
for(i = 0; i < n + 1; i++) {
d[i] = abs(atr[i + 1] - atr[i]);
sum += d[i];
}
avg = (float)sum / n;
// Print results
printf("\nTrack Traversal Order (SCAN):\n");
for(i = 0; i <= n + 1; i++) {
printf("%d ", atr[i]);
}
printf("\n\nTotal head movement: %d", sum);
printf("\nAverage head movement: %.2f\n", avg);
return 0;
}
OUTPUT:
Enter the number of tracks to be traversed: 5
Enter the initial position of the head: 50
Enter the track numbers:
10
20
35
70
90
Track Traversal Order (SCAN):
50 35 20 10 0 70 90
Total head movement: 140
Average head movement: 28.00
Result:
Thus the given program executed and verified successfully.
8) Implement a new system call, add this new system call in the Linux kernel (any kernel
source, any architecture and any Linux kernel distribution) and demonstrate the use of
same.
Aim:
To implement a new system call in the Linux kernel, add it to the system call table, and demonstrate its usage
through a user-space program.
DESCRIPTIPON:
Steps to Implement in Linux:
1. Download and Prepare the Linux Kernel Source:
Download the kernel source for your specific distribution from the official kernel repository.
Extract the source code and set up the environment for building the kernel.
2. Modify the Kernel to Add the New System Call:
Algorithm:
1. Locate System Call Table:
In the kernel source, locate the file that defines the system call table (e.g.,
arch/x86/entry/syscalls/syscall_64.tbl for 64-bit systems).
2. Add New System Call Function:
Write the system call function in a C file (e.g., kernel/my_syscall.c).
Example:
asmlinkage long sys_mycall(void) {
printk(KERN_INFO "My system call is invoked!\n");
return 0;
3. Modify the System Call Table:
Assign a unique system call number to your new system call in the table (syscall_64.tbl).
<new_number> common mycallsys_mycall
4. Declare the New System Call:
Add the prototype of the new system call to include/linux/syscalls.h:
asmlinkage long sys_mycall(void);
5. Compile the Kernel:
Build the kernel and modules.
Install the new kernel and reboot.
3. Write a User Program to Invoke the New System Call:
Example program to call the new system call:
PROGRAM:
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#define SYS_GET_PID 333 // Replace with your syscall number
int main() {
long pid = syscall(SYS_GET_PID);
if (pid == -1) {
perror("syscall");
} else {
printf("Current Process ID: %ld\n", pid);
return 0;
Compile the Test Program:
gcctest_get_pid.c -o test_get_pid
Run the Test Program:
./test_get_pid
OUTPUT:
Current Process ID: <PID>
Result:
Thus the Program verified successfully.
9.Install a C compiler in a virtual machine created using virtual box and execute simple
programs.
AIM:
To install a C compiler (GCC) in a virtual machine created using Virtual Box and execute simple C programs.
Steps to Implement:
1. Create a Virtual Machine:
Install VirtualBox on your system.
Create a new virtual machine in VirtualBox and install a Linux distribution (e.g., Ubuntu, CentOS).
2. Install GCC (GNU Compiler Collection):
Algorithm:
1. Open Terminal in the Virtual Machine:
Access the terminal by searching for it or using Ctrl + Alt + T in Linux.
2. Update the Package List:
Run the following command to update the package list:
sudo apt update
3. Install GCC Compiler:
Install the GCC compiler using the following command:
sudo apt install gcc
For CentOS or Fedora, use:
sudo yum install gcc
4. Verify the GCC Installation:
After installation, verify the GCC version by running:
gcc --version
3. Write and Compile a Simple C Program:
ALGORITHM:
1. Create a C Program:
Open a text editor (e.g., nano, vim) and write a simple C program. For example:
#include <stdio.h>
int main() {
printf("Hello, Virtual World!\n");
return 0;
2. Save the File:
Save the file with a .c extension (e.g., hello.c).
3. Compile the Program:
Compile the program using GCC:
gcchello.c -o hello
4. Run the Executable:
Run the generated executable:
./hello
output :
Hello, Virtual World!
Result:
Thus the Program verified and executed successfully.