A practical collection of Operating Systems laboratory programs for KTU CSE S4.
This repository brings together the source code and reference material completed during the Operating Systems lab. It is useful for revising concepts, preparing for practical examinations, and comparing different OS algorithms through small, readable implementations.
- Linux command reference material and shell scripting exercises
- UNIX process, directory, and file I/O system calls
- CPU scheduling simulations with waiting and turnaround times
- Shared-memory IPC and semaphore-based synchronization problems
- Fixed and variable partition memory allocation
- FIFO, LRU, LFU, and Optimal page replacement
- Banker's safety algorithm and deadlock detection
- FCFS, SCAN, and CSCAN disk scheduling
| Topic | Start here |
|---|---|
| Shell scripting | Cycle 2 |
| System calls and file I/O | Cycles 3-4 |
| CPU scheduling | Cycle 5 |
| IPC and synchronization | Cycles 6-7 |
| Memory management | Cycles 8-9 |
| Deadlocks and disk scheduling | Cycles 10-11 |
| Complete file list | Lab Programs |
| Cycle | Area | Main concepts | Files |
|---|---|---|---|
| 1 | Linux commands | Command-line fundamentals | 1 |
| 2 | Shell scripting | Conditions, loops, search, patterns, arguments | 14 |
| 3 | System calls | fork, exec, stat, directory operations |
4 |
| 4 | File I/O | open, read, write, close |
1 |
| 5 | CPU scheduling | FCFS, SJF, SRTF, Round Robin, Priority | 5 |
| 6 | Shared-memory IPC | shmget, shmat, shmdt, shmctl |
3 |
| 7 | Synchronization | Semaphores and classic problems | 4 |
| 8 | Memory allocation | Fixed and variable partitions | 2 |
| 9 | Page replacement | FIFO, LRU, LFU, Optimal | 5 |
| 10 | Deadlock handling | Safety, resource requests, detection | 4 |
| 11 | Disk scheduling | FCFS, SCAN, CSCAN | 2 |
You will need:
- A Unix-like operating system such as Linux or macOS
- GCC or another C compiler
- Bash or a compatible shell
- POSIX development support for programs using processes, threads, shared memory, or semaphores
git clone https://github.com/ar-ashiq/Operating-Systems-Lab-S4-KTU.git
cd Operating-Systems-Lab-S4-KTUgcc cycle5/fcfs.c -o fcfs
./fcfsFor a program using POSIX threads or semaphores, your platform may require an additional linker flag:
gcc cycle7/producerConsumer.c -o producer_consumer -pthread
./producer_consumerchmod +x cycle2/1grossSalary.sh
./cycle2/1grossSalary.shMost programs are interactive and expect input from the terminal. Read the source before running it so you know the expected input format and algorithm assumptions.
All links below open the corresponding file directly on GitHub.
- Linux commands reference - Reference questions and material for commonly used Linux commands.
- Gross salary - Calculates gross salary using the given HRA and DA rules.
- Armstrong numbers - Prints Armstrong numbers within an input range.
- Smallest of three numbers - Finds the smallest value among three inputs.
- Password validation - Checks password length, letter case, digit, and underscore requirements.
- Three-digit numbers - Generates three-digit numbers made from
0,1,2, and3, without leading zeroes. - Palindromic prime - Finds the smallest palindromic prime greater than a given number.
- Sort numbers - Sorts a list of numbers using bubble sort.
- Linear search - Searches for an element in a list using linear search.
- Number pattern - Prints a repeated-number triangle for a specified number of rows.
- Diamond pattern - Prints a star diamond pattern.
- File names to uppercase - Validates file arguments and displays existing file names in uppercase.
- Reverse arguments - Prints command-line arguments in reverse order.
- Fibonacci - Computes a Fibonacci value for a given position.
- Sum of digits - Displays the digits of a number and calculates their sum.
- Fork, process IDs, exit, and wait - Demonstrates parent-child process creation and synchronization.
- Exec - Replaces the current process with the
ls -lcommand usingexeclp. - Stat - Reads file metadata such as size, device ID, and timestamps.
- Directory operations - Opens a directory, reads its entries, and closes it.
- Open, read, write, and close - Demonstrates basic file I/O system calls using file.txt.
- First Come First Served - Calculates scheduling results for non-preemptive FCFS.
- Round Robin - Simulates time-sliced scheduling with a configurable quantum.
- Shortest Job First - Implements non-preemptive SJF scheduling.
- Shortest Remaining Time First - Implements preemptive SJF scheduling.
- Priority scheduling - Implements non-preemptive priority scheduling.
- Shared-memory writer - Creates or attaches to shared memory and writes user input.
- Shared-memory reader - Reads from shared memory and removes the shared-memory segment.
- Shared-memory key file - File used as the
ftokpath/key source.
- Dining Philosophers - Coordinates philosophers competing for shared chopsticks.
- Producer-Consumer - Synchronizes producers and consumers with counting semaphores and a mutex.
- Readers-Writers - Coordinates concurrent readers and exclusive writers.
- Sleeping Barber - Models waiting customers, barber availability, and limited waiting seats.
- Fixed-partition allocation - Compares First Fit, Best Fit, and Worst Fit for fixed partitions.
- Variable-partition allocation - Compares First Fit, Best Fit, and Worst Fit for variable partitions.
- FIFO page replacement - Simulates FIFO replacement and counts page faults.
- LRU page replacement - Replaces the least recently used page.
- LFU page replacement - Replaces the least frequently used page.
- Optimal page replacement - Selects the page whose next use is farthest in the future.
- Combined page replacement algorithms - Menu-driven implementation of FIFO, LRU, and LFU.
- Banker's algorithm - Checks system safety and attempts to produce a safe sequence.
- Safety algorithm - Determines whether resource allocation can reach a safe state.
- Safety algorithm with resource requests - Tests a tentative resource request before granting it.
- Deadlock detection - Detects deadlocks using allocation, outstanding requests, and available resources.
- Disk scheduling - Simulates FCFS, SCAN, and CSCAN scheduling.
- Extended disk scheduling - Simulates disk scheduling with configurable head direction.
- Begin with shell scripting to practise input, conditions, loops, and functions.
- Move to system calls and file I/O.
- Compare the CPU scheduling algorithms using the same process concepts.
- Study IPC and synchronization before working through deadlocks.
- Finish with memory management, page replacement, and disk scheduling.
Found an error, portability issue, or a missing lab program? Contributions are welcome.
- Fork the repository.
- Create a focused branch for your change.
- Test the program on a Unix-like system.
- Open a pull request with a short explanation of the change.
You can also open an issue or contact ashiqar2002@gmail.com.
Created as a practical study resource for Kerala Technological University (KTU) Computer Science students learning Operating Systems.
This repository is licensed under the MIT License. You are free to use, modify, and distribute the programs with the license notice included.