Unix Shell Implementation
Project Information
- Category: Systems
- Project date: Fall 2025
Project Overview
A custom Unix-like shell implemented in C++ that supports command parsing, sequential execution (;), and pipelines (|). The shell handles tokenization, process creation, cleanup of resources, and provides a foundation for adding features such as redirection or built-in commands. Demonstrates systems programming: processes, IPC, resource management.
Demo
Supports sequential execution with semicolons (;) and inter-process communication through pipes (|)
Graceful Error Handling
Implements graceful error handling by detecting and reporting malformed commands (e.g., missing pipe operands or multiple semicolons) without terminating the shell, allowing users to continue running valid commands.
Tokenization
Converts raw user input into structured commands by splitting on delimiters (;, |, spaces) and safely allocating memory for each token. This parsing layer ensures the shell can interpret complex input like ls -l ; cat file | grep foo into discrete, executable steps.
Pipeline Execution
Implements Unix-style pipelines by creating child processes with fork(), connecting their input and output streams using pipe() and dup2(). This allows the output of one command to seamlessly become the input of the next, enabling commands like cat file | grep foo to execute as a connected process chain.
Cleanup
Reclaims all dynamically allocated memory and clears process structures after each command cycle. This disciplined resource management prevents leaks and ensures the shell remains stable across repeated executions.
Error Handling
Validates command syntax before execution, detecting issues such as multiple semicolons or pipes missing operands. Instead of crashing, the shell prints an error and returns to the prompt, ensuring robust and uninterrupted user interaction.