A lightweight, custom Unix shell implemented entirely in C. This project is a hands-on exploration of Operating System principles, designed to parse and execute commands just like standard shells (e.g., bash, zsh), while managing processes, file descriptors, and inter-process communication under the hood.
- Command Execution: Runs standard Unix system commands using the
execfamily of system calls. - Built-in Commands: Native support for essential shell commands like
cd(change directory) andexit. - I/O Redirection: Supports redirecting standard input (
<) and standard output (>) to files. - Piping (
|): Connects the standard output of one command to the standard input of another, allowing command chaining. - Background Processes (
&): Executes commands in the background without blocking the shell prompt.
microbash.c: The core source code containing the shell loop, string parsing logic, and system call invocations.Makefile: The build configuration file for easy compilation.microbash.pdf: Detailed project specification and architectural documentation.test.txt: A sample text file used to verify I/O redirection and piping functionalities.
- Language: C
- API: POSIX (Portable Operating System Interface)
- Process Management:
fork(),execvp(),waitpid() - Inter-Process Communication (IPC):
pipe() - File Operations:
open(),close(),dup2()
- Open your terminal in the project directory.
- Compile the shell using the provided Makefile:
make
- Run the compiled executable to start the shell interface:
./microbash
(To exit the shell, simply type exit or press Ctrl+D)
Building a shell from the ground up is a classic and rigorous exercise in Systems Programming. Through microbash, I developed a deep understanding of:
- Process Lifecycle: How the OS creates child processes (fork), replaces their memory images (exec), and synchronizes with the parent (wait).
- File Descriptors: How Unix treats files and I/O streams, and how to safely manipulate them using dup2 to achieve redirection.
- Inter-Process Communication: Creating anonymous pipes to establish one-way data channels between concurrent processes.
- C String Manipulation: Safely tokenizing user input, handling dynamic memory, and dealing with pointers in a low-level environment.