UNIX System Calls Lab Experiment
Experiment: Execute various UNIX system calls for
i. Process management
ii. File management
iii. Input/output system calls
Objective:
To understand and implement various UNIX system calls related to process management, file
management, and input/output operations.
Requirements:
- UNIX/Linux environment
- GCC compiler
Part A: Process Management System Calls
----------------------------------------
1. fork()
2. exec()
3. wait()
4. getpid()
5. getppid()
Example Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
pid_t pid = fork();
if (pid == 0) {
printf("Child Process. PID: %d\n", getpid());
} else {
wait(NULL);
printf("Parent Process. PID: %d\n", getpid());
return 0;
Part B: File Management System Calls
-------------------------------------
1. open()
2. read()
3. write()
4. close()
5. lseek()
Example Code:
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main() {
int fd = open("file.txt", O_CREAT | O_WRONLY, 0644);
write(fd, "Hello, File System!", 20);
close(fd);
return 0;
Part C: Input/Output System Calls
----------------------------------
1. read()
2. write()
Example Code:
#include <stdio.h>
#include <unistd.h>
int main() {
char buffer[20];
write(1, "Enter input: ", 13);
read(0, buffer, 20);
write(1, buffer, 20);
return 0;
}
Conclusion:
This experiment provides hands-on practice with essential UNIX system calls, helping students
understand process creation, file operations, and I/O handling.
CPU Scheduling Policies Lab Experiment
Experiment: Implement CPU Scheduling Policies
i. SJF (Shortest Job First)
ii. Priority Scheduling
iii. FCFS (First Come First Serve)
iv. Multi-level Queue Scheduling
Objective:
To implement and analyze various CPU scheduling algorithms using C or any programming
language to understand their performance and behavior.
Requirements:
- Programming environment (C/C++/Python)
- Basic knowledge of data structures
Part A: SJF (Shortest Job First)
---------------------------------
SJF schedules the process with the smallest burst time first.
Sample Input:
Process ID | Burst Time
P1 |6
P2 |8
P3 |7
P4 |3
Expected Output:
Average Waiting Time and Turnaround Time.
Part B: Priority Scheduling
----------------------------
Each process is assigned a priority and the process with the highest priority is executed first.
Sample Input:
Process ID | Burst Time | Priority
P1 | 10 |2
P2 |1 |1
P3 |2 |3
Expected Output:
Processes scheduled in order of priority, average waiting time, and turnaround time.
Part C: FCFS (First Come First Serve)
--------------------------------------
The simplest scheduling algorithm where the process that arrives first is executed first.
Sample Input:
Process ID | Arrival Time | Burst Time
P1 |0 |5
P2 |1 |3
P3 |2 |8
Expected Output:
Gantt chart representation, average waiting and turnaround times.
Part D: Multi-level Queue Scheduling
-------------------------------------
Processes are divided into multiple queues based on a specific criterion like priority or memory size.
Example:
Queue 1 (System Processes - Priority Scheduling)
Queue 2 (User Processes - FCFS)
Each queue has its own scheduling algorithm. Processes do not move between queues.
Conclusion:
This experiment demonstrates the functionality and comparison of various CPU scheduling
techniques that are fundamental to operating system design. By implementing them, students gain
insight into how operating systems manage multiple processes efficiently.
Resource Allocation Graph (RAG) Lab Experiment
Experiment: Implementation of Resource Allocation Graph (RAG)
Objective:
To simulate and understand the working of a Resource Allocation Graph (RAG) which is used to
detect deadlocks in an operating system.
Requirements:
- Programming environment (C/C++/Python)
- Understanding of graphs and deadlock detection
Theory:
A Resource Allocation Graph is a directed graph used to represent the state of system resources
and processes.
- Processes are represented as circles (P1, P2, ...).
- Resources are represented as squares (R1, R2, ...).
- An edge from a process to a resource (P -> R) indicates a request.
- An edge from a resource to a process (R -> P) indicates allocation.
If a cycle is detected in the graph and each resource has only one instance, then a deadlock exists.
Algorithm:
1. Take number of processes and resources as input.
2. Take edges representing allocation and request.
3. Construct the adjacency matrix.
4. Detect cycle using DFS or BFS traversal.
Sample Input:
Processes: P1, P2
Resources: R1, R2
Edges:
P1 -> R1 (Request)
R1 -> P2 (Allocated)
P2 -> R2 (Request)
R2 -> P1 (Allocated)
Expected Output:
Cycle detected: Deadlock exists
Conclusion:
By implementing the Resource Allocation Graph, we can visualize the relationship between
processes and resources. This helps to identify deadlocks in systems and understand how resource
allocation affects system stability.