Skip to content

About

Unix-style shell project in C featuring process creation, built-in commands, I/O redirection, pipes, and Linux process analysis.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux Mini Shell

A Unix-style shell implemented in C as a systems programming project for COP 4610 — Operating Systems Principles course at Florida International University.

Project Overview

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.

Features

  • Execute external commands using fork(), execvp(), and wait()
  • Built-in commands: cd, pwd, and exit
  • 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

Academic Context and Attribution

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

Build and Run

Compile the shell:

make

Run the shell:

./mysh

Clean generated binaries:

make clean

Usage Examples

Run external commands:

mysh> ls -l
mysh> echo hello world

Use built-in commands:

mysh> pwd
mysh> cd /tmp
mysh> exit

Redirect standard output to a file:

mysh> echo hello > output.txt

Append output to an existing file:

mysh> echo world >> output.txt

Redirect standard input from a file:

mysh> wc -l < output.txt

Connect two commands with a pipe:

mysh> ls -l | grep .c

How It Works

The shell continuously reads user input, determines the type of command being requested, and executes the appropriate operation.

External Commands

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.

Built-in Commands

Commands that must modify the shell process itself are handled directly without creating a child process:

  • cd changes the shell's current working directory.
  • pwd displays the current working directory.
  • exit terminates the shell.

I/O Redirection

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.

Pipes

A single pipeline connects two processes using pipe().

For a command such as:

mysh> ls -l | grep .c

the shell:

  1. Creates a pipe.
  2. Forks a child for the left command.
  3. Redirects the left child's standard output to the pipe.
  4. Forks a child for the right command.
  5. Redirects the right child's standard input from the pipe.
  6. Closes unused file descriptors.
  7. Waits for both child processes to finish.

Process and System Call Analysis

The project also included observing the shell at the operating-system level using Linux diagnostic tools.

strace

strace was used to inspect system calls generated by the shell and its child processes, including:

  • execve
  • clone / process creation
  • pipe
  • dup2
  • wait4

This made it possible to connect the C implementation directly to the system calls executed by the Linux kernel.

/proc

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

ps was used to inspect process IDs, parent-child relationships, and process states while commands were running.

Key Concepts Demonstrated

  • 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()

Project Structure

linux-mini-shell/
├── mysh.c
├── Makefile
├── .gitignore
├── README.md
└── screenshots/

Screenshots

Screenshots demonstrating the shell's functionality and Linux process analysis will be included in the screenshots/ directory.

Planned examples include:

  • External Command Execution External command execution

  • Built-in commands Built-in commands

  • Input/output redirection I/O redirection

  • Pipeline execution Pipeline execution

Limitations

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.

Technologies and Tools

  • C
  • Linux
  • GCC
  • GNU Make
  • Bash
  • strace
  • ps
  • /proc

What I Learned

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.

About

Unix-style shell project in C featuring process creation, built-in commands, I/O redirection, pipes, and Linux process analysis.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages