Os Record Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 90

Ex.

No : 1 INSTALLATION OF WINDOWS OPERATING SYSTEM


Date :

Aim:

To install windows operating system using an empty usb flash drive.

Step1:
Connect a blank USB flash drive or insert a blank writable DVD.

Step2:
Make sure you have a product key.
Step3:
Go to https://www.microsoft.com/en-us/software-download/windows10%20.

Step4:
Click Download tool now.
Step5:
Double-click the downloaded file.

Step6:
Click Accept to accept the license.

Step7:
Select "Create installation media" and click OK.
Step8:
Select your preferences and click Next.

Step9:
Choose an installation type and click Next.

Step10:
Create your installation media.

Result:

Thus installation of windows operating system is successfully executed and verified.


Ex:No: 2 ILLUSTRATE UNIX COMMANDS AND SHELL PROGRAMMING

Date:

2. (A): BASICS OF UNIX

COMMANDS

Aim: To illustrate basics of UNIX commands.

ls: List files and directories in the current directory.


Example: ls

cd: Change directory. Example:


cd /path/to/directory

mkdir: Create a new directory.


Example: mkdir new_directory

rm: Remove files or directories.


Example: rm file.txt (removes a file)
rm -r directory (removes a directory and its contents recursively)

cp: Copy files and directories.


Example: cp file.txt new_file.txt (copies a file)
cp -r directory/ new_directory/ (copies a directory and its contents recursively)

mv: Move or rename files and directories.


Example: mv file.txt new_directory/ (moves a file to a directory)mv
old_name.txt new_name.txt (renames a file)

cat: Concatenate and display file contents.


Example: cat file.txt

grep: Search for patterns in files.


Example: grep "pattern" file.txt (searches for "pattern" in file.txt)

wc: Count lines, words, and characters in files.


Example: wc file.txt

chmod: Change file permissions.


Example: chmod 755 file.txt (sets read, write, and execute permissions for the owner, and read and
execute permissions for group and others)

Result:
Thus to illustrate Basics of UNIX commands is executed successfully.
2. (B): SHELL PROGRAMMING

Aim: To implement Shell Programming using bash.

Algorithm:
1)Define the shebang.
2)Define variables.
3) Write the main logic of your script.
4) Use built-in shell commands or call external programs to perform the actions required by your
script.

Program:
#!/bin/bash

# This is a comment

# Declare and assign a variable


name="John"

# Print a message echo


"Hello, $name!"

# Use conditional statementsif [


"$name" == "John" ]; then
echo "You are John."
else
echo "You are not John."
fi

# Use a loop
for (( i=1; i<=5; i++ )); do
echo "Count: $i"
done

# Read user input echo


"Enter your age:"read
age
echo "Your age is $age."

# Perform arithmetic calculations


result=$((5 + 3))
echo "5 + 3 equals $result."
# Define a function
say_hello() {
echo "Hello from the function!"
}
# Call the function
say_hello

# End of the script


Output:

Result:
Thus to implement Shell Programming using bash is successfully executed and verified.
Ex. No: 3 A PROCESS MANAGEMENT USING SYSTEM CALLS: FORK

Date :

Aim:
To implement fork system call using c.

Algorithm:
1)Include the necessary header files.
2)Call the fork() function.
3) After calling fork(), you need to check the return value to determine whether you are in the parent
or child process.
4) Based on the return value of fork(), you can now branch your code accordingly for the parent
and child processes.
5) Execute the code.

Program:
#include <stdio.h>
#include <unistd.h>

int main() {
pid_t pid;

// Create a new processpid


= fork();

if (pid < 0) {
// Error occurred while forking
fprintf(stderr, "Fork failed\n");
return 1;
} else if (pid == 0) {
// Child process
printf("Child process\n");
// Perform child-specific tasks
} else {
// Parent process
printf("Parent process\n");
// Perform parent-specific tasks
}

return 0;
}
Output:
Parent process
Child process

Result:

Thus to implement fork system call using c is successfully executed and verified.
Ex. No: 3 B PROCESS MANAGEMENT USING SYSTEM CALLS: EXIT

Date :

Aim:

To implement exit system call using c.

Algorithm:

1)Include the necessary header files.


2)Define the cleanup function.
3)Implement the main function.
4)Terminate the program.

Program:

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

void cleanup() {
// Code to clean up resources before exiting
printf("Cleaning up resources...\n");
// Cleanup code goes here
}

int main() {
// Code execution before exit call

// Register the cleanup function to be called before exit


atexit(cleanup);

// Terminate the program and return control to the operating systemexit(0);


}
Output:

Cleaning up resources…

Result:

Thus to implement exit system call using c is successfully executed and verified.
Ex. No: 3 C PROCESS MANAGEMENT USING SYSTEM CALLS: GETPID

Date :

Aim:

To implement Getpid system call using c.

Algorithm:

1) Include the necessary header files.


2) Declare pid.
3)Use getpid system call function.
4) Print the Process ID.

Program:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
pid_t pid;

pid = getpid(); // Get the PID of the current processprintf("The

process ID is: %d\n", pid);

return 0;
}
Output:

The Process ID is : 6319.

Result:

Thus to implement Getpid system call using c is successfully executed and verified.
Ex. No: 3 D PROCESS MANAGEMENT USING SYSTEM CALLS: WAIT

Date :

Aim:

To implement wait system call using c.

Algorithm:

1) Include the necessary header files.


2) Declare pid,status.
3)Use fork system call function.
4) Execute the code and use wait system call to status.

Program:

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main() {
pid_t pid;
int status;

pid = fork(); // Create a child processif

(pid < 0) {
// Error occurred while forking
fprintf(stderr, "Fork failed\n");
return 1;
} else if (pid == 0) {
// Child process
printf("Child process running...\n");
sleep(5); // Simulating some work in the child process
printf("Child process done.\n");
} else {
// Parent process
printf("Parent process waiting for child...\n");
wait(&status); // Wait for child process to finish
printf("Parent process resumed.\n");
}

return 0;
}
Output:

Parent process waiting for child…Child


process running…

Result:

Thus to implement wait system call using c is successfully executed and verified.
Ex. No: 3 E PROCESS MANAGEMENT USING SYSTEM CALLS: CLOSE

Date :

Aim:

To implement close system using c.

Algorithm:

1) Include the necessary header files.


2) Open the file to read.
3) Close the file using close system call.

Program:

#include <unistd.h>
#include <stdio.h>

int main() {
int file_descriptor = 123; // Replace with your file descriptor

if (close(file_descriptor) == -1) {
perror("Error closing file");
return 1;
}

printf("File closed successfully.\n");


return 0;
}
Output:

File closed successfully.

Result:

Thus to implement close system call using c is successfully executed and verified.
Ex. No: 4 A IMPLEMENT THE VARIOUS CPU SCHEDULING ALGORITHMS

Date : FIRST COME FIRST SERVE (FCFS) SCHEDULING ALGORITHM

Aim:

To implement FCFS scheduling algorithm using c.

Algorithm:

1) Define a structure to represent a process.


2) Accept the number of processes and their arrival time and burst time from the user.3)Sort
the processes based on their arrival time in ascending order.
4) Implement fcfs scheduling algorithm.
5)Calculate the waiting time and turnaround time for each process.
6)Calculate the average waiting time and average turnaround time.
7)Display the scheduling results.

Program:

#include <stdio.h>

int main()
{
int i, j, n, bt[20], wt[20], tat[20], ct[20], temp, totalwt = 0, totaltat = 0;float
avgwt, avgtat;

printf("Enter the number of processes: ");scanf("%d",


&n);

printf("Enter the burst time of each process: \n");for(i =


0; i < n; i++)
{
printf("Process[%d]: ", i+1);
scanf("%d", &bt[i]);
}
// Sorting the processes based on their burst timesfor(i =
0; i < n; i++)
{
for(j = i + 1; j < n; j++)
{
if(bt[i] > bt[j])
{
temp = bt[i];
bt[i] = bt[j];
bt[j] = temp;
}
}
}
// Calculating the completion time, waiting time, and turnaround timefor(i =
0; i < n; i++)
{
if(i == 0)
ct[i] =
bt[i];else
ct[i] = ct[i-1] + bt[i];

tat[i] = ct[i];
wt[i] = tat[i] - bt[i];

totalwt += wt[i];
totaltat += tat[i];
}

// Calculating the average waiting time and average turnaround timeavgwt


= (float)totalwt/n;
avgtat = (float)totaltat/n;

printf("\nProcess\t Burst Time\t Completion Time\t Waiting Time\t Turnaround Time\n");for(i =


0; i < n; i++)
{
printf("P[%d]\t %d\t\t %d\t\t %d\t\t %d\n", i+1, bt[i], ct[i], wt[i], tat[i]);
}

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


Turnaround Time: %.2f\n", avgtat);

return 0;
}
Output:

Result:

Thus to implement FCFS scheduling algorithm using c is successfully executed and verified.
Ex. No: 4 B SHORTEST JOB FIRST (SJF) SCHEDULING ALGORITHM

Date :

Aim:

To Implement Shortest Job First Scheduling Algorithm using c.

Algorithm:

1) Define a structure to represent a process.


2) Accept the number of processes and their arrival time and burst time from the user.3)Sort
the processes based on their arrival time in ascending order.
4) Implement sjf scheduling algorithm.
5)Calculate the waiting time and turnaround time for each process.
6)Calculate the average waiting time and average turnaround time.
7)Display the scheduling results.

Program:

#include <stdio.h>

struct Process {
int pid; // Process ID int
arrival; // Arrival time
int burst; // Burst time int
waiting; // Waiting time
int turnaround; // Turnaround time
};

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


total_waiting = 0, total_turnaround = 0;
int completion_time[n], remaining_time[n];

// Copy the burst times into remaining_time arrayfor


(int i = 0; i < n; i++)
remaining_time[i] = processes[i].burst;int

completed = 0, current_time = 0;

while (completed != n) {
int shortest = -1; // Index of the process with the shortest remaining time

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


if (processes[i].arrival <= current_time && (shortest == -1 || remaining_time[i] <
remaining_time[shortest]))
shortest = i;
}
if (shortest == -1) {
current_time++;
continue;
}

completion_time[shortest] = current_time + remaining_time[shortest];


current_time += remaining_time[shortest];
processes[shortest].waiting = current_time - processes[shortest].arrival -processes[shortest].burst;
processes[shortest].turnaround = current_time - processes[shortest].arrival;total_waiting +=
processes[shortest].waiting;
total_turnaround += processes[shortest].turnaround;
remaining_time[shortest] = 0;
completed++;
}

float average_waiting = (float)total_waiting / n;


float average_turnaround = (float)total_turnaround / n;

// Print process details


printf("PID\tArrival\tBurst\tWaiting\tTurnaround\n");for
(int i = 0; i < n; i++) {
printf("%d\t%d\t%d\t%d\t%d\n", processes[i].pid, processes[i].arrival, processes[i].burst,
processes[i].waiting, processes[i].turnaround);
}

// Print average waiting and turnaround times printf("\nAverage


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

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

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

sjf_scheduling(processes, n);

return 0;
}
Output:

Result:

Thus to implement Shortest Job First Scheduling Algorithm using c is successfully executed and verified.
Ex. No: 4 C PRIORITY SCHEDULING ALGORITHMS

Date:

Aim:

To implement Priority Scheduling Algorithms using c.

Algorithm:

1) Define a structure to represent a process.


2) Accept the number of processes and their arrival time and burst time from the user.3)Sort
the processes based on their arrival time in ascending order.
4) Implement priority scheduling algorithm.
5)Calculate the waiting time and turnaround time for each process.
6)Calculate the average waiting time and average turnaround time.
7)Display the scheduling results.

Program:

#include<stdio.h>

void main() {
int n, i, j, temp;
int arrival_time[20], burst_time[20], priority[20], waiting_time[20], turnaround_time[20]; float
avg_waiting_time = 0, avg_turnaround_time = 0;

printf("Enter the number of processes: ");scanf("%d",


&n);

printf("\nEnter the arrival time, burst time and priority of each process:\n");for(i =
0; i < n; i++) {
printf("\nProcess[%d]\n", i + 1);
printf("Arrival time: ");
scanf("%d", &arrival_time[i]);
printf("Burst time: "); scanf("%d",
&burst_time[i]);
printf("Priority: ");
scanf("%d", &priority[i]);
}

// Sorting processes based on priorityfor(i


= 0; i < n; i++) {
for(j = i + 1; j < n; j++) {
if(priority[i] > priority[j]) {
temp = priority[i];
priority[i] = priority[j];
priority[j] = temp;
temp = burst_time[i];
burst_time[i] = burst_time[j];
burst_time[j] = temp;

temp = arrival_time[i];
arrival_time[i] = arrival_time[j];
arrival_time[j] = temp;
}
}
}

// Calculating waiting time and turnaround timefor(i =


0; i < n; i++) {
waiting_time[i] = 0;
turnaround_time[i] = burst_time[i] + waiting_time[i];

for(j = 0; j < i; j++) {


waiting_time[i] += burst_time[j];
}

avg_waiting_time += waiting_time[i];
avg_turnaround_time += turnaround_time[i];
}

// Displaying the results


printf("\nProcess\t Arrival time\t Burst time\t Priority\t Waiting time\t Turnaround time\n"); for(i
= 0; i < n; i++) {
printf("P[%d]\t\t %d\t\t %d\t\t %d\t\t %d\t\t %d\n", i + 1, arrival_time[i], burst_time[i],
priority[i], waiting_time[i], turnaround_time[i]);
}

avg_waiting_time /= n;
avg_turnaround_time /= n;
printf("\nAverage waiting time: %f", avg_waiting_time);
printf("\nAverage turnaround time: %f", avg_turnaround_time);
}
Output:

Result:

Thus to implement Priority Scheduling Algorithms using c is successfully executed and verified.
Ex. No: 4 D ROUND ROBIN SCHEDULING ALGORITHMS

Date :

Aim:

To implement Round Robin Scheduling Algorithms using c.

Algorithm:

1) Define a structure to represent a process.


2) Accept the number of processes and their arrival time and burst time from the user.3)Sort
the processes based on their arrival time in ascending order.
4) Implement round robin scheduling algorithm.
5)Calculate the waiting time and turnaround time for each process.
6)Calculate the average waiting time and average turnaround time.
7)Display the scheduling results.

Program:

#include <stdio.h>

#define MAX_PROCESSES 10
#define TIME_QUANTUM 4

struct process {
int pid; // Process IDint
burst; // Burst time
int remaining; // Remaining time
};

int main() {
struct process p[MAX_PROCESSES];int n,
i, t, completed = 0;
int wait_time = 0, turnaround_time = 0; printf("Enter

the number of processes: ");

scanf("%d", &n);

// Input the processesfor


(i = 0; i < n; i++) {
printf("Enter the burst time for process %d: ", i + 1);scanf("%d",
&p[i].burst);
p[i].remaining = p[i].burst;
p[i].pid = i + 1;
}
// Execute the processes in a Round Robin fashion
printf("\nExecution order: ");
for (t = 0;; t++) {
for (i = 0; i < n; i++) {
if (p[i].remaining > 0) {
printf("P%d ", p[i].pid);

if (p[i].remaining > TIME_QUANTUM) {


t += TIME_QUANTUM - 1;
p[i].remaining -= TIME_QUANTUM;
} else {
t += p[i].remaining - 1;
wait_time += t - p[i].burst;
turnaround_time += t;
p[i].remaining = 0;
completed++;
}
}
}

// If all processes are completed, exit the loopif


(completed == n) {
break;
}
}

printf("\n\nAverage waiting time: %.2f", (float)wait_time / n);


printf("\nAverage turnaround time: %.2f", (float)turnaround_time / n);

return 0;
}
Output:

Result:

Thus to implement Round Robin Scheduling Algorithms using c is successfully executed and
verified.
Ex. No : 5 ILLUSTRATE THE INTER PROCESS COMMUNICATION STRATEGY

Date :

Aim:

To illustrate Inter process communication strategy using c

Algorithm:

1) Include necessary header files.


2) Implement fork system call for child process.
3) Determine child and parent actions.
4)Handle errors and execute the code.

Program:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main()
{
int fd[2]; // file descriptors for pipe
pid_t pid;

if (pipe(fd) == -1) { // create pipe


perror("pipe");
exit(EXIT_FAILURE);
}
pid = fork(); // fork process
if (pid == -1) {
perror("fork");
exit(EXIT_FAILURE);
}
if (pid == 0) { // child process close(fd[0]);
// close unused read end
const char* message = "Hello from child process!";
write(fd[1], message, strlen(message) + 1); close(fd[1]);
// close write end exit(EXIT_SUCCESS);
} else { // parent process
close(fd[1]); // close unused write endchar
buffer[100];
read(fd[0], buffer, sizeof(buffer));
printf("Message received from child: %s\n", buffer);close(fd[0]);
// close read end
wait(NULL); // wait for child to exit
exit(EXIT_SUCCESS);
}
}
Output:

Result:

Thus to illustrate Inter process communication strategy using c is successfully executed and verified.
Ex. No : 6 IMPLEMENT MUTUAL EXCLUSION BY SEMAPHORE

Date :

Aim:

To implement mutual exclusion by semaphore using c

Algorithm:

1) Include the necessary header files.


2) Declare and initialize the semaphore variable.
3)Initialize the semaphore in your main function.
4)Implement mutual exclusion using semaphores.

Program:

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

#define NUM_THREADS 2

int shared_data = 0;
sem_t mutex;

void *thread_func(void *arg) {int


id = *(int *) arg;
int i;
for (i = 0; i < 5; i++) {
sem_wait(&mutex);
shared_data++;
printf("Thread %d: shared_data = %d\n", id, shared_data);
sem_post(&mutex);
}
pthread_exit(NULL);
}

int main() {
pthread_t threads[NUM_THREADS];
int thread_ids[NUM_THREADS] = {0, 1};int
i;

// initialize the semaphore


sem_init(&mutex, 0, 1);

// create threads
for (i = 0; i < NUM_THREADS; i++) {
pthread_create(&threads[i], NULL, thread_func, &thread_ids[i]);
}
// wait for threads to finish
for (i = 0; i < NUM_THREADS; i++) {
pthread_join(threads[i], NULL);
}

// destroy the semaphore


sem_destroy(&mutex);

return 0;
}
Output:

Result:

Thus to implement mutual exclusion by semaphore using c is successfully executed and verified.
Ex. No : 7 AVOID DEADLOCK USING BANKER’S ALGORITHM

Date :

Aim:

To avoid Deadlock using Banker's Algorithm in c

Algorithm:

1) Include the necessary header files.


2) Declare and initialize the variables and data structures required for the Banker's algorithm.
3)Implement the Banker's algorithm functions.
4) Implement the main function.

Program:

#include <stdio.h>

#define MAX_RESOURCES 5

int available_resources = MAX_RESOURCES;


int allocated_resources = 0;

int max_requests[] = {1, 2, 3, 4, 5};


int allocated_resources_array[] = {0, 0, 0, 0, 0};
int need_resources_array[] = {1, 2, 3, 4, 5};

int request_resources(int request[])


{
int i, safe = 1;

for (i = 0; i < MAX_RESOURCES; i++) {


if (request[i] > need_resources_array[i] ||
request[i] > available_resources) { safe =
0;
break;
}
}

if (safe) {
for (i = 0; i < MAX_RESOURCES; i++) {
available_resources -= request[i];
allocated_resources_array[i] += request[i];
need_resources_array[i] -= request[i];
}
allocated_resources += 1;
}

return safe;
}
void release_resources(int release[])
{
int i;

for (i = 0; i < MAX_RESOURCES; i++) {


available_resources += release[i]; allocated_resources_array[i] -
= release[i];need_resources_array[i] += release[i];
}
allocated_resources -= 1;
}

void print_state()
{
printf("Available resources: %d\n", available_resources);
printf("Allocated resources: %d\n", allocated_resources);
printf("Max requests: ");
for (int i = 0; i < MAX_RESOURCES; i++)
{
printf("%d ", max_requests[i]);
}
printf("\n");
printf("Allocated resources array: ");
for (int i = 0; i < MAX_RESOURCES; i++) {
printf("%d ", allocated_resources_array[i]);
}
printf("\n");
printf("Need resources array: ");
for (int i = 0; i < MAX_RESOURCES; i++) {printf("%d
", need_resources_array[i]);
}
printf("\n");
}

int main()
{
int request[MAX_RESOURCES] = {0, 0, 0, 0, 0};
int release[MAX_RESOURCES] = {0, 0, 0, 0, 0};

// Make some initial requests


request[0] = 1;
request[1] = 2;
request[2] = 3;
request[3] = 4;
request[4] = 5;

if (request_resources(request)) {
printf("Request granted.\n");
} else {
printf("Request denied.\n");
}
print_state();
// Release some resources
release[0] = 1;
release[1] = 2;
release[2] = 3;
release[3] = 4;
release[4] = 5;

release_resources(release);

print_state();

return 0;
}
Output:

Result:

Thus to avoid Deadlock using Banker's Algorithm in c is successfully executed and verified.
Ex. No : 8 IMPLEMENT DEADLOCK DETECTION ALGORITHM

Date :

Aim:

To implement deadlock detection algorithm using c.

Algorithm:

1) Include the necessary header files.


2) Declare and initialize the variables and data structures required for deadlock detection.
3)Implement the deadlock detection algorithm functions.
4)Implement the main function.

Program:

#include <stdio.h>

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

int available[m], max[n][m], allocation[n][m], need[n][m], finish[n];

printf("Enter the available resources: ");


for(i=0; i<m; i++)
{
scanf("%d", &available[i]);
}

printf("Enter the maximum resources needed by each process:\n");for(i=0;


i<n; i++)
{
for(j=0; j<m; j++)
{
scanf("%d", &max[i][j]);
}
}
printf("Enter the resources allocated to each process:\n");for(i=0;
i<n; i++)
{
for(j=0; j<m; j++)
{
scanf("%d", &allocation[i][j]);
need[i][j] = max[i][j] - allocation[i][j];
}
finish[i] = 0;
}

int work[m], safe[n], count=0;

for(i=0; i<m; i++)


{
work[i] = available[i];
}

while(count < n)
{
int found = 0;
for(i=0; i<n; i++)
{
if(finish[i] == 0)
{
int flag = 1;
for(j=0; j<m; j++)
{
if(need[i][j] > work[j])
{
flag = 0;
break;
}
}

if(flag)
{
for(k=0; k<m; k++)
{
work[k] += allocation[i][k];
}
safe[count] = i;
count++;
finish[i] = 1;
found = 1;
}
}
}

if(!found)
{
printf("Deadlock detected!\n");
return 0;
}
}
printf("System is in safe state.\n");
printf("Safe sequence is: "); for(i=0;
i<n; i++)

{
printf("%d ", safe[i]);
}
printf("\n");

return 0;
}
Output:

Result:

Thus to implement deadlock detection algorithm using c is successfully executed and verified.
Ex. No : 9 IMPLEMENTATION OF THREADING

Date :

Aim:

To implement threading using c.

Algorithm:

1) Include the necessary header files.


2) Declare the function that will be executed by the thread.
3)Implement the main function.

Program:

#include <stdio.h>
#include <pthread.h>
void *thread_function(void *arg);

int main() { pthread_t


thread;
char *message = "Hello, world!";int
result;

result = pthread_create(&thread, NULL, thread_function, (void *) message);if


(result) {
printf("Error - pthread_create() return code: %d\n", result);return 1;
}

printf("Main thread waiting for thread to finish...\n");


result = pthread_join(thread, NULL);
if (result) {
printf("Error - pthread_join() return code: %d\n", result);return
1;
}

printf("Thread finished, message: %s\n", message);

return 0;
}

void *thread_function(void *arg) {


char *message = (char *) arg;
printf("Thread running, message: %s\n", message);
pthread_exit(NULL);
}
Output:

Result:

Thus to implement threading using c is successfully executed and verified.


Ex. No : 10 IMPLEMENTATION OF PAGING TECHNIQUE

Date :

Aim:

To implement the paging technique using c.

Algorithm:

1)Define the necessary data structures and constants.2)Implement the


page table initialization function.
3) Implement the page fault handler function.
4) Implement the function to read a byte from a logical address.
5)Implement the main function to demonstrate the usage.

Program:

#include <stdio.h>

#define PAGE_SIZE 4 // page size in bytes


#define NUM_PAGES 10 // number of pages in memory

int main() {
int page_table[NUM_PAGES] = {-1}; // initialize all entries to -1
int physical_mem[NUM_PAGES * PAGE_SIZE] = {0}; // initialize physical memory to 0int
virtual_mem_size, logical_address, page_num, offset, physical_address, value;

// get size of virtual memory from user printf("Enter


size of virtual memory (in bytes): ");scanf("%d",
&virtual_mem_size);

// loop to read logical addresses and retrieve valueswhile (1)


{
printf("Enter logical address (or -1 to exit): ");
scanf("%d", &logical_address);

if (logical_address == -1) {
break;
}

// calculate page number and offset page_num =


logical_address / PAGE_SIZE;offset =
logical_address % PAGE_SIZE;

// check if page is in memory


if (page_table[page_num] == -1) {
printf("Page fault!\n");
// simulate loading page into memory page_table[page_num]
= page_num * PAGE_SIZE;
printf("Loaded page %d into physical memory at address %d\n", page_num,
page_table[page_num]);
}

// calculate physical address and retrieve value


physical_address = page_table[page_num] + offset;value
= physical_mem[physical_address];
printf("Value at logical address %d is %d\n", logical_address, value);
}

return 0;
}
Output:

Result:

Thus to implement the paging technique using c is successfully executed and verified.
Ex. No : 11 A FIRST FIT MEMORY ALLOCATION ALGORITHM

Date :

Aim:

To implement First Fit Memory Allocation Algorithm using c.

Algorithm:

1) Define a structure to represent a memory block.


2) Create an array of memory blocks to represent the available memory. Initialize the array with the
initial state of the memory.
3) Implement a function to allocate memory using the First Fit algorithm.
4)Implement a function to deallocate memory.
5)Test the memory allocation algorithm by calling the allocate_memory anddeallocate_memory
functions as needed.

Program:
#include <stdio.h>

#define MAX_SIZE 100

// Structure to represent a memory block


typedef struct {
int start;
int end;
int size;
int allocated; // 0 for unallocated, 1 for allocated
} MemoryBlock;

// Function to allocate memory using First Fit


void firstFit(MemoryBlock blocks[], int numBlocks, int processSize) {int i;
for (i = 0; i < numBlocks; i++) {
if (blocks[i].allocated == 0 && blocks[i].size >= processSize) {
// Allocate memory
blocks[i].allocated = 1;
blocks[i].size -= processSize;
blocks[i].end -= processSize;

printf("Memory allocated successfully.\n");


printf("Allocated block: %d\n", i);
printf("Allocated memory size: %d\n", processSize);
printf("Remaining block size: %d\n", blocks[i].size);

return;
}
}
printf("Memory allocation failed.\n");
}

// Function to display the memory blocks


void displayBlocks(MemoryBlock blocks[], int numBlocks) {int i;
printf("\nMemory Blocks:\n");
for (i = 0; i < numBlocks; i++) {
printf("Block %d: ", i);
if (blocks[i].allocated)
printf("Allocated\n");else
printf("Free\n");
}
}
int main() {
int numBlocks = 5;
MemoryBlock blocks[MAX_SIZE] = {
{0, 99, 100, 0},
{100, 199, 100, 0},
{200, 299, 100, 0},
{300, 399, 100, 0},
{400, 499, 100, 0}
};

displayBlocks(blocks, numBlocks);int

processSize;
printf("\nEnter the size of the process to be allocated: ");
scanf("%d", &processSize);

firstFit(blocks, numBlocks, processSize);displayBlocks(blocks,

numBlocks);

return 0;
}
Output:

Result:

Thus to implement First Fit Memory Allocation Algorithm using c is successfully executed and
verified.
Ex. No : 11 B WORST FIT MEMORY ALLOCATION ALGORITHM

Date :

Aim:

To implement Worst Fit Memory Allocation Algorithm using c.

Algorithm:

1) Define a structure to represent a memory block.


2) Create an array of memory blocks to represent the available memory. Initialize the array with the
initial state of the memory.
3) Implement a function to allocate memory using the Worst Fit algorithm.
4)Implement a function to deallocate memory.
5)Test the memory allocation algorithm by calling the allocate_memory anddeallocate_memory
functions as needed.

Program:

#include <stdio.h>

#define MAX_SIZE 100

// Structure to represent a memory block


typedef struct {
int start;
int end;
int size;
int allocated; // 0 for unallocated, 1 for allocated
} MemoryBlock;

// Function to allocate memory using Worst Fit


void worstFit(MemoryBlock blocks[], int numBlocks, int processSize) {int i,
j, maxBlockSize = -1, maxBlockIndex = -1;

// Find the largest block that can accommodate the processfor (i =


0; i < numBlocks; i++) {
if (blocks[i].allocated == 0 && blocks[i].size >= processSize) {if
(blocks[i].size > maxBlockSize) {
maxBlockSize = blocks[i].size;maxBlockIndex
= i;
}
}
}

if (maxBlockIndex != -1) {
// Allocate memory blocks[maxBlockIndex].allocated
= 1; blocks[maxBlockIndex].size -= processSize;
blocks[maxBlockIndex].end -= processSize;
printf("Memory allocated successfully.\n");
printf("Allocated block: %d\n", maxBlockIndex);
printf("Allocated memory size: %d\n", processSize);
printf("Remaining block size: %d\n", blocks[maxBlockIndex].size);
} else
{
printf("Memory allocation failed.\n");
}
}

// Function to display the memory blocks


void displayBlocks(MemoryBlock blocks[], int numBlocks) {int i;
printf("\nMemory Blocks:\n");
for (i = 0; i < numBlocks; i++) {
printf("Block %d: ", i);
if (blocks[i].allocated)
printf("Allocated\n");else
printf("Free\n");
}
}

int main() {
int numBlocks = 5;
MemoryBlock blocks[MAX_SIZE] = {
{0, 99, 100, 0},
{100, 199, 100, 0},
{200, 299, 100, 0},
{300, 399, 100, 0},
{400, 499, 100, 0}
};

displayBlocks(blocks, numBlocks);int

processSize;
printf("\nEnter the size of the process to be allocated: ");
scanf("%d", &processSize);

worstFit(blocks, numBlocks, processSize);displayBlocks(blocks,

numBlocks);

return 0;
}
Output:

Result:

Thus to implement Worst Fit Memory Allocation Algorithm using c is successfully executed and
verified.
Ex. No : 11 C BEST FIT MEMORY ALLOCATION ALGORITHM

Date :

Aim:

To implement Best Fit Memory Allocation Algorithm using c is successfully executed and verified.

Algorithm:

1) Define a structure to represent a memory block.


2) Create an array of memory blocks to represent the available memory. Initialize the array with the
initial state of the memory.
3) Implement a function to allocate memory using the Best Fit algorithm.
4)Implement a function to deallocate memory.
5)Test the memory allocation algorithm by calling the allocate_memory anddeallocate_memory
functions as needed.

Program:

#include <stdio.h>

#define MAX_SIZE 100

// Structure to represent a memory block


typedef struct {
int start;
int end;
int size;
int allocated; // 0 for unallocated, 1 for allocated
} MemoryBlock;

// Function to allocate memory using Best Fit


void bestFit(MemoryBlock blocks[], int numBlocks, int processSize) {int i,
j, minBlockSize = -1, minBlockIndex = -1;

// Find the smallest block that can accommodate the processfor (i =


0; i < numBlocks; i++) {
if (blocks[i].allocated == 0 && blocks[i].size >= processSize) {if
(blocks[i].size < minBlockSize || minBlockSize == -1) {
minBlockSize = blocks[i].size;
minBlockIndex = i;
}
}
}

if (minBlockIndex != -1) {
// Allocate memory blocks[minBlockIndex].allocated
= 1; blocks[minBlockIndex].size -= processSize;
blocks[minBlockIndex].end -= processSize;
printf("Memory allocated successfully.\n"); printf("Allocated
block: %d\n", minBlockIndex); printf("Allocated memory size:
%d\n", processSize);
printf("Remaining block size: %d\n", blocks[minBlockIndex].size);
} else {
printf("Memory allocation failed.\n");
}
}

// Function to display the memory blocks


void displayBlocks(MemoryBlock blocks[], int numBlocks) {int i;
printf("\nMemory Blocks:\n");
for (i = 0; i < numBlocks; i++) {
printf("Block %d: ", i);
if (blocks[i].allocated)
printf("Allocated\n");else
printf("Free\n");
}
}

int main() {
int numBlocks = 5;
MemoryBlock blocks[MAX_SIZE] = {
{0, 99, 100, 0},
{100, 199, 100, 0},
{200, 299, 100, 0},
{300, 399, 100, 0},
{400, 499, 100, 0}
};

displayBlocks(blocks, numBlocks);int

processSize;
printf("\nEnter the size of the process to be allocated: ");
scanf("%d", &processSize);

bestFit(blocks, numBlocks, processSize);displayBlocks(blocks,

numBlocks);

return 0;
}
Output:

Result:

Thus to implement Best Fit Memory Allocation Algorithm using c is successfully executed and
verified.
Ex. No : 12 A FIRST-IN-FIRST-OUT (FIFO) PAGE REPLACEMENT ALGORITHM

Date :

Aim:
To implement FIFO Page Replacement Algorithm using c.

Algorithm:

1)Define the necessary variables and constants.2)Initialize


the variables.
3)Read the number of pages and the page reference string from the user.4)Implement
the FIFO page replacement algorithm.
5)Print the total number of page faults.

Program:

#include <stdio.h> #define

MAX_FRAMES 3

void fifoPageReplacement(int pages[], int n)


{
int frames[MAX_FRAMES] = {0};
int frameIndex = 0;
int pageFaults = 0;
int i, j, k;

for (i = 0; i < n; i++)


{
int currentPage = pages[i];int
pageExists = 0;

for (j = 0; j < MAX_FRAMES; j++)


{
if (frames[j] == currentPage)
{
pageExists = 1;
break;
}
}

if (!pageExists)
{
frames[frameIndex] = currentPage;
frameIndex = (frameIndex + 1) % MAX_FRAMES;
pageFaults++;
}

printf("Page %d: ", currentPage); for


(k = 0; k < MAX_FRAMES; k++)
printf("%d ", frames[k]);
printf("\n");
}
printf("Total Page Faults: %d\n", pageFaults);
}

int main()
{
int pages[] = {1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5};
int n = sizeof(pages) / sizeof(pages[0]);

printf("FIFO Page Replacement Algorithm:\n");


fifoPageReplacement(pages, n);

return 0;
}
Output:

Result:

Thus to implement FIFO Page Replacement Algorithm using c is successfullyexecuted and verified.
Ex. No : 12 B LRU PAGE REPLACEMENT ALGORITHM

Date :

Aim:

To implement LRU Page Replacement Algorithm using c.

Algorithm:

1)Define the necessary variables and constants.2)Initialize


the variables.
3)Read the number of pages and the page reference string from the user.4)Implement
the LRU page replacement algorithm.
5)Print the total number of page faults.

Program:

#include <stdio.h> #define

MAX_FRAMES 3

void lruPageReplacement(int pages[], int n)


{
int frames[MAX_FRAMES] = {0};
int frameIndex[MAX_FRAMES] = {0};
int pageFaults = 0;
int i, j, k;

for (i = 0; i < n; i++)


{
int currentPage = pages[i];int
pageExists = 0;

for (j = 0; j < MAX_FRAMES; j++)


{
if (frames[j] == currentPage)
{
pageExists = 1;
frameIndex[j] = i;
break;
}
}

if (!pageExists)
{
int leastRecentIndex = 0;
for (j = 1; j < MAX_FRAMES; j++)
{
if (frameIndex[j] < frameIndex[leastRecentIndex])
leastRecentIndex = j;
}

frames[leastRecentIndex] = currentPage;
frameIndex[leastRecentIndex] = i;
pageFaults++;
}

printf("Page %d: ", currentPage); for


(k = 0; k < MAX_FRAMES; k++)
printf("%d ", frames[k]);
printf("\n");
}

printf("Total Page Faults: %d\n", pageFaults);


}
int main()
{
int pages[] = {1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5};
int n = sizeof(pages) / sizeof(pages[0]);

printf("LRU Page Replacement Algorithm:\n");


lruPageReplacement(pages, n);

return 0;
}
Output:

Result:

Thus to implement LRU Page Replacement Algorithm using c is successfullyexecuted and verified.
Ex. No : 13 A SEQUENTIAL FILE ORGANIZATION TECHNIQUE

Date :

Aim:
To implement Sequential File Organization Technique using c.

Algorithm:

1)Define the necessary structures and variables.2)Create a


new sequential file.
3)Read records from the sequential file. 4)Update
a record in the sequential file. 5)Delete a record
from the sequential file. 6)Search for a record in
the sequential file.

Program:

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

struct Student {
int rollNo;
char name[50];
float marks;
};

void writeStudentRecord(FILE* fp, struct Student s) {


fwrite(&s, sizeof(struct Student), 1, fp);
}

void readStudentRecord(FILE* fp) {


struct Student s;
while (fread(&s, sizeof(struct Student), 1, fp) == 1) {
printf("Roll No: %d\nName: %s\nMarks: %.2f\n\n", s.rollNo, s.name, s.marks);
}
}

int main() {
FILE* fp;
struct Student s;

// Write records to file


fp = fopen("students.dat", "wb");if
(fp == NULL) {
printf("Error in opening file.");
return 1;

}
s.rollNo = 1; strcpy(s.name,
"John"); s.marks = 85.5;
writeStudentRecord(fp, s);
s.rollNo = 2; strcpy(s.name,
"Alice"); s.marks = 90.0;
writeStudentRecord(fp, s);

fclose(fp);

// Read records from file


fp = fopen("students.dat", "rb");if
(fp == NULL) {
printf("Error in opening file.");
return 1;
}

readStudentRecord(fp);

fclose(fp);

return 0;
}
Output:

Roll No: 1
Name: John
Marks: 85.50

Roll No: 2
Name: Alice
Marks: 90.00

Result:

Thus to implement Sequential File Organization Technique using c is successfully executed and verified.
Ex. No : 13 B INDEXED FILE ORGANIZATION TECHNIQUE

Date :

Aim:
To implement Indexed File Organization Technique using c.

Algorithm:

1)Define the necessary structures and variables.2)Create a


new Indexed file.
3)Read records from the Indexed file. 4)Update a
record in the Indexed file. 5)Delete a record from
the Indexed file. 6)Search for a record in the
Indexed file.

Program:

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

struct Student {
int rollNo;
char name[50];
float marks;
};

struct Index {
int rollNo;
long int offset;
};

void writeStudentRecord(FILE* fp, struct Student s, struct Index* index, int* indexCount) {
fwrite(&s, sizeof(struct Student), 1, fp);
index[*indexCount].rollNo = s.rollNo; index[*indexCount].offset
= ftell(fp) - sizeof(struct Student);(*indexCount)++;
}

void readStudentRecord(FILE* fp, struct Index* index, int indexCount, int rollNo) { int i;
for (i = 0; i < indexCount; i++) {
if (index[i].rollNo == rollNo) {
fseek(fp, index[i].offset, SEEK_SET);
struct Student s;
fread(&s, sizeof(struct Student), 1, fp);
printf("Roll No: %d\nName: %s\nMarks: %.2f\n\n", s.rollNo, s.name, s.marks);return;
}
}
printf("Record not found.\n");
}
int main() {
FILE* fp;
struct Student s;
struct Index index[100];
int indexCount = 0;

// Write records to file


fp = fopen("students.dat", "wb");if
(fp == NULL) {
printf("Error in opening file.");
return 1;
}

s.rollNo = 1;
strcpy(s.name, "John");
s.marks = 85.5;
writeStudentRecord(fp, s, index, &indexCount);

s.rollNo = 2;
strcpy(s.name, "Alice");
s.marks = 90.0;
writeStudentRecord(fp, s, index, &indexCount);

fclose(fp);

// Read records from file


fp = fopen("students.dat","rb");if
(fp == NULL) {
printf("Error in opening file.");
return 1;
}

int rollNo;

printf("Enter the roll number to search: ");scanf("%d",


&rollNo);

readStudentRecord(fp, index, indexCount, rollNo);

fclose(fp);

return 0;
}
Output:

Enter the roll number to search: 1


Roll No: 1
Name: John
Marks: 85.50

Result:

Thus to implement Indexed File Organization Technique using c is successfullyexecuted and


verified.
Ex. No : 13 C HASHING FILE ORGANIZATION TECHNIQUE

Date :

Aim:
To implement Hashing File Organization Technique using c.

Algorithm:

1)Define the necessary structures and variables.2)Create a


new Hash file.
3)Read records from the Hash file.
4)Update a record in the Hash file. 5)Delete
a record from the Hash file. 6)Search for a
record in the Hash file.

Program:

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

#define SIZE 10

struct Student {
int rollNo;
char name[50];
float marks;
};

void writeStudentRecord(FILE* fp, struct Student s) {


fwrite(&s, sizeof(struct Student), 1, fp);
}

void readStudentRecord(FILE* fp, int index) {


fseek(fp, index * sizeof(struct Student), SEEK_SET);struct
Student s;
fread(&s, sizeof(struct Student), 1, fp);if
(s.rollNo != -1) {
printf("Roll No: %d\nName: %s\nMarks: %.2f\n\n", s.rollNo, s.name, s.marks);
} else {
printf("Record not found.\n");
}
}

int hashFunction(int rollNo) {


return rollNo % SIZE;
}
int main() {
FILE* fp;
struct Student s;
// Initialize the file with empty recordsfp =
fopen("students.dat", "wb");
if (fp == NULL) {
printf("Error in opening file.");
return 1;
}

s.rollNo = -1;
for (int i = 0; i < SIZE; i++) {
writeStudentRecord(fp, s);
}

fclose(fp);

// Write records to file


fp = fopen("students.dat", "r+b");if
(fp == NULL) {
printf("Error in opening file.");
return 1;
}
s.rollNo = 1;
strcpy(s.name, "John");
s.marks = 85.5;
int index = hashFunction(s.rollNo);
writeStudentRecord(fp, s);

s.rollNo = 2;
strcpy(s.name, "Alice");
s.marks = 90.0;
index = hashFunction(s.rollNo);
writeStudentRecord(fp, s);
fclose(fp);

// Read records from file


fp = fopen("students.dat", "rb");if
(fp == NULL) {
printf("Error in opening file.");
return 1;
}
int rollNo;
printf("Enter the roll number to search: ");scanf("%d",
&rollNo);
index = hashFunction(rollNo);
readStudentRecord(fp, index);
fclose(fp);

return 0;
}
Output:

Enter the roll number to search: 2


Roll No: 2
Name: Alice
Marks: 90.00

Result:

Thus to implement Hashing File Organization Technique using c is successfully executed and
verified.
Ex. No : 14 A SEQUENTIAL FILE ALLOCATION STRATEGY

Date :

Aim:
To implement Sequential File Allocation Strategy using c.

Algorithm:

1)Define the necessary structures and variables.2)Initialize


the file system.
3)Allocate a file in the sequential file allocation strategy. 4)Deallocate
a file from the sequential file allocation strategy.5)Display the status
of the file system.

Program:

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

#define MAX_FILE_SIZE 100

typedef struct {
char fileName[20];
int startBlock;
int fileSize;
} File;

void allocateSequential(File files[], int numFiles) {int


currentBlock = 0;

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


files[i].startBlock = currentBlock;
currentBlock += files[i].fileSize;
}
}
int main() {
int numFiles;
printf("Enter the number of files: ");
scanf("%d", &numFiles);

File files[MAX_FILE_SIZE];

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


printf("Enter the file name: ");
scanf("%s", files[i].fileName);
printf("Enter the file size: ");
scanf("%d", &files[i].fileSize);
}
allocateSequential(files, numFiles); printf("\nFile

Allocation Table (Sequential):\n");printf("File

Name\tStart Block\tFile Size\n");for (int i = 0; i <

numFiles; i++) {

printf("%s\t\t%d\t\t%d\n", files[i].fileName, files[i].startBlock, files[i].fileSize);


}

return 0;
}
Output:

Result:

Thus to implement Sequential File Allocation Strategy using c is successfully executed and
verified.
Ex. No : 14 B INDEXED FILE ALLOCATION STRATEGY

Date :

Aim:
To implement Indexed File Allocation Strategy using c.

Algorithm:

1)Define the necessary structures and variables.2)Initialize


the file system.
3)Allocate a file in the Indexed file allocation strategy. 4)Deallocate a
file from the Indexed file allocation strategy.5)Display the status of the
file system.

Program:

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

#define MAX_FILE_SIZE 100


#define MAX_INDEX_SIZE 10

typedef struct {
char fileName[20];
int fileSize;
int indexBlock[MAX_INDEX_SIZE];
} File;

void allocateIndexed(File files[], int numFiles) {int


currentBlock = 0;

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


files[i].indexBlock[0] = currentBlock;currentBlock
+= files[i].fileSize;

for (int j = 1; j < MAX_INDEX_SIZE; j++) {


files[i].indexBlock[j] = -1;
}
}
}

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

File files[MAX_FILE_SIZE];
for (int i = 0; i < numFiles; i++) {
printf("Enter the file name: ");
scanf("%s", files[i].fileName);
printf("Enter the file size: ");
scanf("%d", &files[i].fileSize);
}

allocateIndexed(files, numFiles);

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


printf("File Name\tFile Size\tIndex Block\n");
for (int i = 0; i < numFiles; i++) {
printf("%s\t\t%d\t\t", files[i].fileName, files[i].fileSize);
for (int j = 0; j < MAX_INDEX_SIZE; j++) {
if (files[i].indexBlock[j] != -1) {
printf("%d ", files[i].indexBlock[j]);
}
}
printf("\n");
}

return 0;
}
Output:

Result:

Thus to implement Indexed File Allocation Strategy using c is successfully executed and verified.
Ex. No : 14 C LINKED FILE ALLOCATION STRATEGY

Date :

Aim:
To implement Linked File Allocation Strategy using c.

Algorithm:

1)Define the necessary structures and variables.


2)Initialize the file system.
3)Allocate a file in the Linked file allocation strategy.
4)Deallocate a file from the Linked file allocation strategy.
5)Display the status of the file system.

Program:

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

typedef struct Block {


int blockNumber;
struct Block* nextBlock;
} Block;

typedef struct {
char fileName[20];
int fileSize;
Block* firstBlock;
} File;

void allocateLinked(File files[], int numFiles) {int


currentBlock = 0;

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


files[i].firstBlock = (Block*)malloc(sizeof(Block));
files[i].firstBlock->blockNumber = currentBlock;
files[i].firstBlock->nextBlock = NULL;
currentBlock++;

Block* current = files[i].firstBlock; for

(int j = 1; j < files[i].fileSize; j++) {


current->nextBlock = (Block*)malloc(sizeof(Block));
current->nextBlock->blockNumber = currentBlock;
current->nextBlock->nextBlock = NULL;
currentBlock++;
current = current->nextBlock;
}
}
}

void deallocateLinked(File files[], int numFiles) {for


(int i = 0; i < numFiles; i++) {
Block* current = files[i].firstBlock;
while (current != NULL) {
Block* temp = current; current
= current->nextBlock;
free(temp);
}
files[i].firstBlock = NULL;
}
}

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

File files[numFiles];

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


printf("Enter the file name: ");
scanf("%s", files[i].fileName);
printf("Enter the file size: ");
scanf("%d", &files[i].fileSize);
}

allocateLinked(files, numFiles);

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


Name\tFile Size\tBlocks\n");
for (int i = 0; i < numFiles; i++) {
printf("%s\t\t%d\t\t", files[i].fileName, files[i].fileSize);
Block* current = files[i].firstBlock;
while (current != NULL) {
printf("%d ", current->blockNumber);
current = current->nextBlock;
}
printf("\n");
}

deallocateLinked(files, numFiles);

return 0;
}
Output:

Result:

Thus to implement Linked File Allocation Strategy using c is successfully executed and verified.
Ex. No : 15 A FIRST COME FIRST SERVE (FCFS) DISK SCHEDULING ALGORITHM

Date :

Aim:

To implement First Come First Serve (FCFS) Scheduling Algorithm using c.

Algorithm:

1) Define the necessary structures and variables.


2) Read the number of processes and their attributes from the user. 3)Sort
the processes based on their arrival times.
4) Implement FCFS Disk Scheduling Algorithm.
5)Calculate the waiting time and turnaround time for each process.
6)Calculate the average waiting time and average turnaround time.
7)Display the scheduling results.

Program:

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

int abs(int a) {
return a >= 0 ? a : -a;
}

int main() {
int n, head, i;
int *requests;

printf("Enter the number of requests: ");scanf("%d",


&n);

requests = (int *)malloc(n * sizeof(int));

printf("Enter the request sequence:\n");for(i =


0; i < n; i++)
scanf("%d", &requests[i]);

printf("Enter the initial head position: ");scanf("%d",


&head);

int totalSeek = 0;

printf("Path: ");
printf("%d ", head);
for(i = 0; i < n; i++) {
totalSeek += abs(requests[i] - head);head =
requests[i];
printf("%d ", head);
}
printf("\n");
printf("Total seek time: %d\n", totalSeek);free(requests);

return 0;
}
Output:

Result:

Thus to implement FCFS Disk Scheduling Algorithm using c is successfullyexecuted and verified.
Ex. No : 15 B SHORTEST SEEK TIME FIRST (SSTF) DISK SCHEDULING ALGORITHM

Date :

Aim:

To implement SSTF Disk Scheduling Algorithm using c.

Algorithm:

1) Define the necessary structures and variables.


2) Read the number of processes and their attributes from the user. 3)Sort
the processes based on their arrival times.
4) Implement SSTF Disk Scheduling Algorithm.
5)Calculate the waiting time and turnaround time for each process.
6)Calculate the average waiting time and average turnaround time.
7)Display the scheduling results.

Program:

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

int abs(int a) {
return a >= 0 ? a : -a;
}

int findClosest(int *requests, int n, int head, int *visited) {int


minDist = INT_MAX;
int index = -1;

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


if(!visited[i] && abs(requests[i] - head) < minDist) {
minDist = abs(requests[i] - head);
index = i;
}
}

return index;
}

int main() {
int n, head, i;
int *requests;

printf("Enter the number of requests: ");scanf("%d",


&n);

requests = (int *)malloc(n * sizeof(int));


printf("Enter the request sequence:\n");for(i =
0; i < n; i++)
scanf("%d", &requests[i]);

printf("Enter the initial head position: ");scanf("%d",


&head);

int totalSeek = 0;
int *visited = (int *)calloc(n, sizeof(int));

printf("Path: ");
printf("%d ", head);

for(i = 0; i < n; i++) {


int closest = findClosest(requests, n, head, visited);totalSeek +=
abs(requests[closest] - head);
head = requests[closest];
visited[closest] = 1;
printf("%d ", head);
}

printf("\n");
printf("Total seek time: %d\n", totalSeek);

free(requests);
free(visited);

return 0;
}
Output:

Result:

Thus to implement SSTF Disk Scheduling Algorithm using c is successfullyexecuted and verified.
Ex. No : 16 INSTALLATION OF LINUX USING VMWARE

Date :

Aim:

To install Linux using VMware.

Setting up Ubuntu using VMWare Player

1) Download & Install VMWare Player.


2) Download Ubuntu by choosing the option of downloading it onto a CD or USB stick.
Remember to choose either 32-bit or 64-bit. http://www.ubuntu.com/download/desktop

3) Open the VMWare player application. MAKE SURE TO RUN THE PROGRAM AS AN
ADMINISTRATOR. Click on Create a New Virtual Machine.

4) Choose install from Installer disc image file (iso) and browse for the Ubuntu .iso you just
downloaded. Click Next.
5) Enter the required information then click Next.

6) Enter a name you wish to use for the virtual machine, or you may leave it as is. Click Next.

7) Leave the next box as is and click Next.


8) Click Finish to finalize your virtual machine.

9) If you are prompted to install VMWare tools, then go ahead and do so.

10) You should see this:


11) Once fully installed install the VMWare Client Tools driver.

12) After successfully installing the driver, your new virtual machine should be fully set up!

Result: This installation of LINUX using VMware is successfully executed and verified.

You might also like