This repository contains the solutions for the Operating Systems Laboratory assignments. The code demonstrates proficiency in Linux shell scripting, system calls, process management, and file handling in a UNIX environment.
| Abhinav Mishra | 24AI004 |
- OS: Ubuntu Linux (22.04 LTS / 24.04 LTS)
- Shell: Bash (Bourne Again SHell)
- Compiler: GCC (GNU Compiler Collection)
- Debuggers/Tools:
strace,gdb,top,bc
Objective: To understand basic Linux commands for file handling (touch, cat, cp, mv) and hierarchical directory management.
- File:
assignment1.sh - Description: An automated shell script that:
- Creates a directory structure (
ProjectWorkspace/Docs,Code, etc.). - Performs file creation and redirection (
echo,>). - Analyzes file statistics (
wc). - Demonstrates pattern matching by moving files based on wildcards.
- Creates a directory structure (
- Execution:
chmod +x assignment1.sh ./assignment1.sh
Objective: To implement logic using control structures (loops, conditions) and design menu-driven programs.
-
File:
factorial.sh -
Logic: Calculates
$n!$ using aforloop. Handles negative number validation.
- File:
addressbook.sh - Logic: A menu-driven program to Create, Read, Update, and Delete contacts in a persistent text file (
contacts.txt). Usesgrepandsedfor data manipulation.
- File:
rename_jpg.sh - Logic: Automatically renames all
.jpgfiles in the directory by prefixing the current date (YYYY-MM-DD).
- File:
geometry.sh - Logic: Calculates Area and Circumference for various shapes. Uses
bc(Basic Calculator) for high-precision floating-point arithmetic.
Objective: To understand the boundary between user-space and kernel-space by implementing standard Linux system calls in C and analyzing them with system monitoring tools.
- File:
syscall_demo.c - Description: A C program that bypasses standard library functions (
fopen,fprintf) to interact directly with the kernel. - Key Concepts Implemented:
- File I/O: Used
open()(with flagsO_CREAT|O_WRONLY),write(), andclose()for direct file manipulation. - Process Creation: Used
fork()to create a child process. - Process Identification: Used
getpid()to retrieve Process IDs for both parent and child. - Synchronization: Implemented
wait()to ensure the parent process waits for the child to terminate, preventing "zombie" processes.
- File I/O: Used
Objective: Apply debugging techniques to observe system-level behavior.
-
Tool:
strace(System Call Tracer)- Used to intercept and record the system calls invoked by the process.
- Observation: Verified that
printfinternally callswriteandforkinternally callsclone. - Command:
strace ./syscall_demo
-
Tool:
gdb(GNU Debugger)- Used for step-by-step execution and inspecting file descriptors.
- Observation: Inspected the file descriptor integer values (typically returning
3for the first open file). - Command:
gdb ./syscall_demo
-
Tool:
top(Process Monitor)- Used to observe the process status and CPU consumption during the execution loop.
# Compile with debugging information included
gcc -g syscall_demo.c -o syscall_demo
# Execute the program
./syscall_demo
# Verify the output file created by system calls
cat syscall_output.txt