OPERATING SYSTEM LAB MANUAL (KCS-
451)
Experiment 1: Study of Hardware and Software Requirements of Different
Operating Systems
Objective: Understand the basic requirements of different operating systems.
Theory:
- Hardware Requirements: Processor type, RAM, Hard disk space, Peripheral devices.
- Software Requirements: File systems, compilers, libraries, device drivers.
Operating Systems Covered:
- UNIX: CLI-based, multitasking, multiuser OS.
- LINUX: Open-source version of UNIX, modular and secure.
- Windows XP/7/8: GUI-based, user-friendly, multimedia support.
Observation Table:
| OS | Type | File System | RAM Requirement | Interface |
|----------|---------|--------------|------------------|-----------|
| UNIX | CLI | UFS | 256 MB+ | CLI |
| LINUX | CLI/GUI | ext3/ext4 | 512 MB+ | GUI/CLI |
| Windows7 | GUI | NTFS | 1 GB+ | GUI |
Conclusion: All OSs have different requirements and purposes. UNIX/Linux is more
developer-oriented while Windows is user-friendly.
Experiment 2: Program to Simulate Multithreading
Objective: Simulate a basic multithreading scenario using POSIX pthreads in C.
Program:
#include <stdio.h>
#include <pthread.h>
void* threadFunc(void* arg) {
printf("Hello from Thread\n");
return NULL;
}
int main() {
pthread_t thread;
pthread_create(&thread, NULL, threadFunc, NULL);
pthread_join(thread, NULL);
printf("Thread finished\n");
return 0;
}
Output:
Hello from Thread
Thread finished
Conclusion: Multithreading allows concurrent execution of multiple parts of a program.
Experiment 3: CPU Scheduling Algorithms (FCFS Example)
Objective: Implement and compare various CPU scheduling algorithms.
FCFS Program:
#include<stdio.h>
int main() {
int bt[] = {5, 8, 12}, wt[10], tat[10], n = 3;
wt[0] = 0;
for(int i = 1; i < n; i++) wt[i] = wt[i-1] + bt[i-1];
for(int i = 0; i < n; i++) tat[i] = wt[i] + bt[i];
for(int i = 0; i < n; i++) {
printf("P%d \tBT:%d \tWT:%d \tTAT:%d\n", i+1, bt[i], wt[i], tat[i]);
}
return 0;
}
Conclusion: FCFS is simple but suffers from convoy effect.
Other Algorithms: SJF, Priority, Multi-Level Queue
Experiment 4: File Storage Allocation Techniques
Objective: Implement and understand different allocation methods.
- Sequential Allocation: Use array to simulate storage blocks.
- Linked Allocation: Use structures with next pointers.
- Indexed Allocation: Use an index block containing all block addresses.
Conclusion: Sequential is easy, linked avoids fragmentation, indexed allows random access.
Experiment 5: Contiguous Memory Allocation Techniques
Objective: Simulate First Fit, Best Fit, Worst Fit strategies.
- First Fit: Assigns first available block.
- Best Fit: Finds the smallest sufficient block.
- Worst Fit: Finds the largest available block.
Conclusion: Best Fit minimizes waste, Worst Fit gives large leftover.
Experiment 6: Internal and External Fragmentation
Objective: Calculate fragmentation from allocation.
- Internal Fragmentation: Block size - Process size (if allocated).
- External Fragmentation: Total free memory not in contiguous form.
Conclusion: External fragmentation wastes more space in dynamic allocation.
Experiment 7: Banker's Algorithm
Objective: Avoid deadlock using resource allocation safety checks.
Concept:
- Input available, max, allocation matrices
- Calculate need matrix
- Run safety algorithm
Conclusion: Banker’s algorithm prevents unsafe resource allocation.
Experiment 8: Disk Scheduling Algorithms
Algorithms:
- FCFS: Services in order of arrival.
- SCAN: Moves in one direction and reverses.
- C-SCAN: Moves in one direction only and jumps back.
Conclusion: SCAN and C-SCAN reduce seek time compared to FCFS.
Experiment 9: Page Replacement Algorithms
Algorithms:
- FIFO: Replace oldest page.
- LRU: Replace least recently used page.
- Optimal: Replace page not needed for longest time.
Conclusion: Optimal gives best result, LRU is practical.
Experiment 10: Bounded Buffer (Producer-Consumer Problem)
Objective: Solve synchronization using semaphores.
Concept:
- Use wait() and signal() with semaphores
- Shared buffer between producer and consumer
Conclusion: Proper semaphore use prevents race condition.
Experiment 11: Dining Philosopher’s Problem
Objective: Avoid deadlock and starvation using semaphores.
Concept:
- Five philosophers share forks
- Use mutex and semaphores
Conclusion: Semaphore control avoids deadlock.