A Unix-style shell implemented in C as a systems programming project for COP 4610 — Operating Systems Principles course at Florida International University.
This project demonstrates core operating systems concepts through the implementation of a lightweight command-line shell. The shell supports external command execution, built-in commands, input/output redirection, and a single pipeline between processes.
- Execute external commands using
fork(),execvp(), andwait() - Built-in commands:
cd,pwd, andexit - Output redirection with
> - Append redirection with
>> - Input redirection with
< - Single pipeline support with
| - Error handling for invalid commands, directories, files, and process creation
- Linux process and system-call analysis using
strace,ps, and/proc
This project was developed as part of COP 4610 — Operating Systems Principles at Florida International University. The course provided starter scaffolding, including parts of the shell loop, input-parsing logic, build configuration, and assignment structure. My implementation focused on:
- External command execution
- Built-in shell commands
- Input and output redirection
- Pipe creation and process communication
- Error handling
- Process and system-call analysis
Compile the shell:
makeRun the shell:
./myshClean generated binaries:
make cleanRun external commands:
mysh> ls -l
mysh> echo hello worldUse built-in commands:
mysh> pwd
mysh> cd /tmp
mysh> exitRedirect standard output to a file:
mysh> echo hello > output.txtAppend output to an existing file:
mysh> echo world >> output.txtRedirect standard input from a file:
mysh> wc -l < output.txtConnect two commands with a pipe:
mysh> ls -l | grep .cThe shell continuously reads user input, determines the type of command being requested, and executes the appropriate operation.
External programs are executed by creating a child process with fork(). The child replaces itself with the requested program using execvp(), while the parent shell waits for the child to finish before displaying the next prompt.
Commands that must modify the shell process itself are handled directly without creating a child process:
cdchanges the shell's current working directory.pwddisplays the current working directory.exitterminates the shell.
Redirection is implemented using Linux file descriptors:
>redirects standard output and overwrites the destination file.>>redirects standard output and appends to the destination file.<redirects standard input from a file.
The shell uses open() to access the requested file and dup2() to replace standard input or standard output before executing the command.
A single pipeline connects two processes using pipe().
For a command such as:
mysh> ls -l | grep .cthe shell:
- Creates a pipe.
- Forks a child for the left command.
- Redirects the left child's standard output to the pipe.
- Forks a child for the right command.
- Redirects the right child's standard input from the pipe.
- Closes unused file descriptors.
- Waits for both child processes to finish.
The project also included observing the shell at the operating-system level using Linux diagnostic tools.
strace was used to inspect system calls generated by the shell and its child processes, including:
execveclone/ process creationpipedup2wait4
This made it possible to connect the C implementation directly to the system calls executed by the Linux kernel.
The Linux /proc filesystem was used to inspect running processes and their open file descriptors.
This was particularly useful for analyzing pipe behavior and understanding why a process can remain blocked when a pipe's write end is unintentionally left open.
ps was used to inspect process IDs, parent-child relationships, and process states while commands were running.
- Process creation with
fork() - Program replacement with
execvp() - Parent-child synchronization with
wait() - Unix file descriptors
- Standard input and output redirection
- Inter-process communication with pipes
- Pipe EOF behavior
- Process states and parent-child relationships
- Linux system-call tracing
- Error handling with
perror()
linux-mini-shell/
├── mysh.c
├── Makefile
├── .gitignore
├── README.md
└── screenshots/
Screenshots demonstrating the shell's functionality and Linux process analysis will be included in the screenshots/ directory.
Planned examples include:
This project intentionally implements a small subset of full Unix shell functionality.
Current limitations include:
- Only one pipe per command line
- No combination of pipes and redirection in the same command
- No wildcard expansion
- No environment-variable expansion
- No command history
- No background execution
- No quoted-string parsing
- No job control
These limitations reflect the educational scope of the project and its focus on operating-system concepts such as processes, file descriptors, and inter-process communication.
- C
- Linux
- GCC
- GNU Make
- Bash
straceps/proc
This project strengthened my understanding of how a Unix-style shell interacts with the operating system. Implementing process creation, program replacement, redirection, and pipes provided practical experience with concepts that are normally hidden behind a command-line interface.
Analyzing the shell with strace, ps, and /proc also helped connect high-level C code with the processes, file descriptors, and system calls managed by the Linux kernel.



