A lightweight Unix-like shell implemented from scratch in C, using low-level POSIX system calls.
This project demonstrates core operating-system concepts such as process creation, inter-process communication, file descriptor management, and signal handling.
This shell supports executing Unix commands, pipelines, I/O redirection, background processes, and basic job control.
It is designed to be educational, minimal, and close to how real shells work internally.
- Execute standard Unix commands
- Argument parsing and PATH-based executable lookup
- Implemented using
fork()andexecvp()
- Supports multi-stage pipelines using
| - Implemented with
pipe()anddup2()
Example: ls -l | grep txt | wc -l
- Input redirection:
< - Output redirection:
> - Append redirection:
>>
Example:
cat input.txt | grep error > output.txt
- Background execution using
& - Foreground execution with blocking waits
- Job tracking using process groups
Example:
sleep 30 & jobs fg 1
cd— change working directoryexit— exit the shellexport— set environment variablesjobs— list background jobsfg/bg— job control
- Handles
SIGINT(Ctrl+C) - Handles
SIGTSTP(Ctrl+Z) - Handles
SIGCHLD(child termination)
The shell itself does not terminate on Ctrl+C / Ctrl+Z.
- Environment variable expansion (
$VAR) - PATH-based command resolution
- Language: C (GNU C / C17)
- System Calls & APIs:
fork,execvppipe,dup2waitpidkillsetpgidsignal
- Headers:
unistd.h,signal.h,fcntl.h,sys/wait.h
make
gcc -std=gnu11 -O2 -Wall -Wextra shell.c -o mysh
./mysh
ls ls -l | grep cpp cat input.txt | grep error > output.txt sleep 10 & jobs fg 1 export PATH=/usr/local/bin:$PATH cd /tmp exit
If you find this project useful, feel free to ⭐ the repository!