OS Lab Manual
OS Lab Manual
Submitted by
Contents
● Program Outcomes
● Course Outcomes
● List of Experiments
Vision
Mission
1. Quality Education: Providing Education with quality and shaping up Technocrats and
building managers with a focus on adapting to changing technologies.
2. Focused Research & Innovation: Focusing on Research and Development and fostering
Innovation among the academic community of the Institution.
3. People Focused: Accountable and committed to institutional operations for effective
functioning by Faculty members, Staff and Students.
4. Holistic Learning: Focus on conceptual learning with practical experience and experimental
learning with strong Industrial connections and collaborations.
5. Service to Society: Providing Technical and Managerial services to society for betterment of
their quality of life with best of the skills, compassion and empathy.
Transforming the life of the graduates by providing excellent education in the field of Computer Science
& Engineering.
M1: Create student centric learning ambience so as to produce graduates who are well informed
about the latest technological trends and advancement in the world of computing, technology and
research.
M2: Produce professionals who are capable to work in diversified fields, find workable solutions to
complex problems with awareness and concern for society and environments.
M3: Continuously upgrade faculty through training so that they function effectively.
M4:Encourage industry institute collaborations through consultancies and research, helping students
to have conceptual learning.
1. To impart in depth concepts of the subject in terms of both theoretical and practical aspects to
achieve excellent University Outputs.
2. To produce technically sound engineering graduates who would fulfill the latest requirements of
computer science and IT industry at modest cost with the calibre of solving intricacies of deeper
programming concepts.
3. To inculcate the lessons of communication skills, teamwork spirit and professional attitude to the
budding engineering graduates.
4. In order to get versatile growth of the students, participation of students in extracurricular
activities is also made compulsory; and also to develop ethical attitudes in the graduates so that
they can also become good citizens of the nation.
5. To develop leadership and entrepreneurship qualities in budding graduates so that they will
cherish and nourish the society and the nation with modern trends of digitization and blossom it
with their unparalleled technical expertise.
PSO 1: Proficiency in Computer Systems: Capability to understand, analyze and develop computer
programs in the areas related algorithms, system software, multimedia, web design, cloud computing
and networking enable designing of computer systems that are efficient and support the degree of
complexity.
PSO 2: Proficiency in Software Development: Ability to understand the structure and methodologies of
software systems with keen knowledge about software design process and practical expertise in the
programming languages and the open system platform.
PSO 3: Proficiency in Mathematics and science concepts: Capable of applying mathematics and science
concepts to solve computation tasks and model real world problems using suitable algorithms and data
structures.
PSO 4: Successful career as a Computer Science Engineer: Ability to employ themselves as computer
professionals, to be an entrepreneur having innovative ideas and sound knowledge in various domains
leads to enthusiasm in higher studies and research.
CO1: Define the fundamental concepts of operating systems, including their functions, types, and
characteristics.
CO2: Apply file system concepts, disk organization, and directory structures. Evaluate and choose disk
allocation methods, and analyze disk scheduling algorithms
CO3: Implement CPU scheduling algorithms and comprehend memory management techniques,
including partitioning, swapping, segmentation, and paging. Apply the concept of virtual memory
through demand paging.
CO4: Design and construct solutions utilizing semaphores to manage concurrent processes effectively,
mitigating deadlock concerns.
CO5: Analyze case studies of Unix/Linux, Windows, and other network, distributed, and multiprocessor
operating systems to understand their architecture and functionalities.
The following Regulations and Safety Rules must be observed in all concerned laboratory locations.
1. It is the duty of all concerned parties who use any electrical laboratory to take all reasonable
steps to safeguard the HEALTH and SAFETY of themselves and all other users and visitors.
2. Make sure that all equipment is properly working before using it for laboratory exercises.
Any defective equipment must be reported immediately to the Lab. Instructors or Lab. Technical
Staff.
3. Students are allowed to use only the equipment provided in the experiment manual or
equipment used for senior project laboratory.
4. Power supply terminals connected to any circuit are only energized with the presence of the
Instructor or Lab. Staff.
5. Students should keep a safe distance from the circuit breakers, electric circuits or any
moving parts during the experiment.
6. Avoid any part of your body to be connected to the energized circuit and ground.
7. Switch off the equipment and disconnect the power supplies from the circuit before leaving
the laboratory.
8. Observe cleanliness and proper laboratory housekeeping of the equipment and other related
accessories.
9. Wear proper clothes and safety gloves or goggles required in working areas that involve
fabrications of printed circuit boards, chemicals process control system, antenna communication
equipment and laser facility laboratories.
10. Double check your circuit connections specifically in handling electrical power machines,
AC motors and generators before switching “ON” the power supply.
11. Make sure that the last connection to be made in your circuit is the power supply and the
first thing to be disconnected is also the power supply.
12. Equipment should not be removed, transferred to any location without permission from the
laboratory staff.
13. Software installation in any computer laboratory is not allowed without the permission from
the Laboratory Staff.
14. Computer games are strictly prohibited in the computer laboratory.
15. Students are not allowed to use any equipment without proper orientation and actual hands
on equipment operation.
Program:
#include <stdio.h>
printf(" %d | %d | %d | %d | %d\n",
processes[i].id, processes[i].arrival_time, processes[i].burst_time,
processes[i].waiting_time, processes[i].turnaround_time);
}
return 0;
}
Sample Output:
Process | Arrival Time | Burst Time | Waiting Time | Turnaround Time
1 | 0 | 5 | 0 | 5
2 | 1 | 3 | 4 | 7
3 | 2 | 8 | 7 | 15
4 | 3 | 6 | 13 | 19
Program:
#include <stdio.h>
#include <stdbool.h>
// Find the process with the shortest burst time that has arrived
for (int i = 0; i < n; i++) {
if (!processes[i].completed && processes[i].arrival_time <= current_time && processes[i].burst_time <
min_burst) {
min_burst = processes[i].burst_time;
shortest = i;
}
}
if (shortest == -1) {
// No process is ready to execute, increment time
current_time++;
continue;
}
printf(" %d | %d | %d | %d | %d\n",
processes[shortest].id, processes[shortest].arrival_time, processes[shortest].burst_time,
processes[shortest].waiting_time, processes[shortest].turnaround_time);
}
// Calculate and display average times
double avg_wait_time = (double) total_wait_time / n;
double avg_turnaround_time = (double) total_turnaround_time / n;
int main() {
// Input: List of processes with their IDs, arrival times, and burst times
struct Process processes[] = {
{1, 0, 6, 0, 0, false},
{2, 1, 8, 0, 0, false},
{3, 2, 7, 0, 0, false},
{4, 3, 3, 0, 0, false}
};
int n = sizeof(processes) / sizeof(processes[0]);
// Call the function to demonstrate SJF scheduling
sjf_scheduling(processes, n);
return 0;
}
Sample Output:
Process | Arrival Time | Burst Time | Waiting Time | Turnaround Time
1 | 0 | 6 | 0 | 6
4 | 3 | 3 | 3 | 6
3 | 2 | 7 | 7 | 14
2 | 1 | 8 | 13 | 21
Program:
#include <stdio.h>
#include <stdbool.h>
printf("Process | Arrival Time | Burst Time | Priority | Waiting Time | Turnaround Time\n");
// Find the process with the highest priority that has arrived
for (int i = 0; i < n; i++) {
if (!processes[i].completed && processes[i].arrival_time <= current_time && processes[i].priority >
max_priority) {
max_priority = processes[i].priority;
highest_priority = i;
}
}
if (highest_priority == -1) {
// No process is ready to execute, increment time
current_time++;
continue;
}
printf(" %d | %d | %d | %d | %d | %d\n",
processes[highest_priority].id, processes[highest_priority].arrival_time,
processes[highest_priority].burst_time,
processes[highest_priority].priority, processes[highest_priority].waiting_time,
processes[highest_priority].turnaround_time);
}
int main() {
// Input: List of processes with their IDs, arrival times, burst times, and priorities
struct Process processes[] = {
{1, 0, 6, 2, 0, 0, false},
{2, 1, 8, 1, 0, 0, false},
{3, 2, 7, 3, 0, 0, false},
{4, 3, 3, 4, 0, 0, false}
};
return 0;
}
Process | Arrival Time | Burst Time | Priority | Waiting Time | Turnaround Time
3 | 2 | 7 | 3 | 5 | 12
4 | 3 | 3 | 4 | 2 | 5
1 | 0 | 6 | 2 | 0 | 6
2 | 1 | 8 | 1 | 7 | 15
Program:
#include <stdio.h>
#include <stdbool.h>
printf(" %d | %d | %d | %d | %d\n",
processes[i].id, processes[i].arrival_time, processes[i].burst_time,
processes[i].waiting_time, processes[i].turnaround_time);
}
}
}
if (!progress) {
current_time++;
}
Operating System (CS 405)
}
int main() {
// Input: List of processes with their IDs, arrival times, and burst times
struct Process processes[] = {
{1, 0, 6, 6, 0, 0},
{2, 1, 8, 8, 0, 0},
{3, 2, 7, 7, 0, 0},
{4, 3, 3, 3, 0, 0}
};
return 0;
}
Sample Output:
Program:
#include <stdio.h>
#include <stdbool.h>
printf("\nFCFS Scheduling:\n");
display_results(processes, n, total_wait_time, total_turnaround_time);
}
int main() {
struct Process processes[] = {{1, 0, 6, 0, 0, 6}, {2, 1, 8, 0, 0, 8}, {3, 2, 7, 0, 0, 7}, {4, 3, 3, 0, 0, 3}};
int n = sizeof(processes) / sizeof(processes[0]);
int quantum = 4;
fcfs_scheduling(processes, n);
round_robin_scheduling(processes, n, quantum);
return 0;
}
FCFS Scheduling:
Process | Waiting Time | Turnaround Time
1 | 0 | 6
2 | 5 | 13
3 | 10 | 17
4 | 12 | 15
Program:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
int buffer[BUFFER_SIZE];
int count = 0; // Number of items in the buffer
// Producer function
void* producer(void* arg) {
for (int i = 0; i < 10; i++) { // Produce 10 items
pthread_mutex_lock(&mutex);
// Consumer function
void* consumer(void* arg) {
for (int i = 0; i < 10; i++) { // Consume 10 items
pthread_mutex_lock(&mutex);
int main() {
pthread_t producer_thread, consumer_thread;
Program:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
// Reader function
void* reader(void* arg) {
int id = *(int*)arg;
free(arg);
pthread_mutex_lock(&mutex);
reader_count++;
if (reader_count == 1) {
pthread_mutex_lock(&write_lock); // First reader locks the writers
}
pthread_mutex_unlock(&mutex);
pthread_mutex_lock(&mutex);
reader_count--;
if (reader_count == 0) {
pthread_mutex_unlock(&write_lock); // Last reader unlocks the writers
}
pthread_mutex_unlock(&mutex);
return NULL;
}
// Writer function
void* writer(void* arg) {
int id = *(int*)arg;
free(arg);
pthread_mutex_unlock(&write_lock);
return NULL;
}
int main() {
pthread_t readers[5], writers[2];
// Initialize mutexes
pthread_mutex_init(&mutex, NULL);
pthread_mutex_init(&write_lock, NULL);
// Destroy mutexes
pthread_mutex_destroy(&mutex);
pthread_mutex_destroy(&write_lock);
Sample Output:
Reader 1: Read shared data = 0
Reader 2: Read shared data = 0
Reader 3: Read shared data = 0
Writer 1: Updated shared data to 1
Reader 4: Read shared data = 1
Reader 5: Read shared data = 1
Writer 2: Updated shared data to 2
Operating System (CS 405)
Experiment 8: Develop a solution to the Dining Philosophers problem, applying deadlock avoidance strategies
and analyzing outcomes.
Program:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#define NUM_PHILOSOPHERS 5
// Philosopher function
void* philosopher(void* arg) {
int id = *(int*)arg;
free(arg);
while (1) {
// Thinking
printf("Philosopher %d is thinking.\n", id);
sleep(1);
pthread_mutex_lock(&forks[right_fork]);
printf("Philosopher %d picked up right fork %d.\n", id, right_fork);
} else {
// Odd-numbered philosophers pick the right fork first
pthread_mutex_lock(&forks[right_fork]);
printf("Philosopher %d picked up right fork %d.\n", id, right_fork);
pthread_mutex_lock(&forks[left_fork]);
printf("Philosopher %d picked up left fork %d.\n", id, left_fork);
}
// Eating
printf("Philosopher %d is eating.\n", id);
sleep(2);
return NULL;
}
int main() {
pthread_t philosophers[NUM_PHILOSOPHERS];
// Initialize mutexes
for (int i = 0; i < NUM_PHILOSOPHERS; i++) {
pthread_mutex_init(&forks[i], NULL);
}
// Destroy mutexes
for (int i = 0; i < NUM_PHILOSOPHERS; i++) {
pthread_mutex_destroy(&forks[i]);
}
return 0;
}
Program:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define PAGE_COUNT 10
return page_faults;
}
int page_faults = 0;
Operating System (CS 405)
for (int i = 0; i < page_count; i++) {
int page = pages[i];
int page_found = 0;
// Find the page that will not be used for the longest time
for (int j = 0; j < frame_count; j++) {
int found = 0;
for (int k = i + 1; k < page_count; k++) {
if (frames[j] == pages[k]) {
found = 1;
break;
}
}
if (!found) {
replace_index = j;
break;
}
if (farthest < 0) {
farthest = i;
replace_index = j;
}
}
frames[replace_index] = page;
}
page_faults++;
}
}
return page_faults;
}
int page_faults = 0;
if (!page_found) {
int lru_index = -1;
int oldest = i;
for (int j = 0; j < frame_count; j++) {
if (frames[j] == -1) {
lru_index = j;
break;
} else if (last_used[j] < oldest) {
oldest = last_used[j];
lru_index = j;
}
}
frames[lru_index] = page;
last_used[lru_index] = i;
page_faults++;
}
}
return page_faults;
}
int page_faults = 0;
if (!page_found) {
int lfu_index = -1;
int min_freq = INT_MAX;
return page_faults;
}
// Display results
printf("Page Reference String: ");
for (int i = 0; i < page_count; i++) {
printf("%d ", pages[i]);
}
printf("\n");
Sample Output:
Program:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
visited[next_request] = 1;
total_seek_time += min_distance;
current_position = requests[next_request];
count++;
}
return total_seek_time;
Operating System (CS 405)
}
// Move towards 0
for (int j = i-1; j >= 0; j--) {
total_seek_time += abs(current_position - sorted_requests[j]);
current_position = sorted_requests[j];
}
return total_seek_time;
}
current_position = 0;
return total_seek_time;
}
// FCFS Evaluation
int fcfs_seek_time = fcfs(requests, n, start);
printf("FCFS Seek Time: %d\n", fcfs_seek_time);
Operating System (CS 405)
// SSTF Evaluation
int sstf_seek_time = sstf(requests, n, start);
printf("SSTF Seek Time: %d\n", sstf_seek_time);
// SCAN Evaluation
int scan_seek_time = scan(requests, n, start, max_track);
printf("SCAN Seek Time: %d\n", scan_seek_time);
// C-SCAN Evaluation
int cscan_seek_time = cscan(requests, n, start, max_track);
printf("C-SCAN Seek Time: %d\n", cscan_seek_time);
return 0;
}
Sample Output:
Program:
#include <stdio.h>
#include <stdbool.h>
int count = 0;
while (count < P) {
bool found = false;
// Find a process whose needs can be satisfied with the available resources
for (int p = 0; p < P; p++) {
if (!finish[p]) {
bool canFinish = true;
for (int i = 0; i < R; i++) {
if (need[p][i] > work[i]) {
canFinish = false;
break;
}
}
if (canFinish) {
// If the process can finish, simulate the release of resources
for (int i = 0; i < R; i++) {
work[i] += allocation[p][i];
}
finish[p] = true;
Operating System (CS 405)
count++;
found = true;
}
}
}
if (!found) {
return false; // If no process can proceed, the system is not in a safe state
}
}
return true; // All processes can finish, the system is in a safe state
}
int main() {
Operating System (CS 405)
int available[] = {3, 3, 2}; // Available resources
int max[][R] = {{7, 5, 3},
{3, 2, 2},
{9, 0, 2},
{2, 2, 2},
{4, 3, 3}}; // Maximum resource demand
// Example request
int request[] = {1, 0, 2}; // Request by process 1 for resources
int process = 1;
return 0;
}
Sample Output:
Requesting resources for Process 1: Resources not available, process must wait.
Request denied.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <pthread.h>
// Create socket
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
perror("Socket failed");
exit(EXIT_FAILURE);
}
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(PORT);
// Client function
void client_function() {
int sock = 0;
struct sockaddr_in server_address;
char buffer[MAX_BUF];
// Create socket
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("Socket failed");
exit(EXIT_FAILURE);
}
server_address.sin_family = AF_INET;
server_address.sin_port = htons(PORT);
int main() {
pthread_t server_tid;
// Wait for the server to set up and then run the client
sleep(1); // Give the server a second to start
return 0;
}
Program:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/uaccess.h>
device_open = 1;
try_module_get(THIS_MODULE); // Increment module usage count
printk(KERN_INFO "Device opened successfully.\n");
return 0;
}
module_init(simple_device_init);
module_exit(simple_device_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple character device driver for hardware interaction.");
Sample Output: