Mini Shell (C)

A C shell project exploring processes, signals, redirection, and job control.

Concept illustration of a shell coordinating foreground and background execution
Concept illustration of command execution and job coordination.

Learn the shell by building one

In this group systems project, we implemented a small shell in C for the UCI OpenLab environment. It accepts commands, runs programs in the foreground or background, supports a set of built-ins, and manages jobs through signals.

Using a shell every day can hide the coordination behind a prompt. This assignment exposed it: parsing a command is only the beginning. The shell also needs to know which process is running, what a signal should affect, and when a finished child needs to be collected.


The execution path

The parser separates command arguments, a trailing &, and the supported redirection operators: <, >, and >>. Built-ins such as cd and pwd run in the shell process. External commands use fork and exec, with the parent waiting for foreground work or returning to the prompt for background work.

Input and output redirection are applied with open and dup2. The assignment supports at most one input and one output redirection, keeping the parser’s contract limited and explicit.


Job state and signals

A job table records process identifiers, status, and the original command. The jobs, fg, bg, and kill commands use that table, with job identifiers or process identifiers accepted where appropriate.

Signal handling connects terminal input to job behavior: interrupting or stopping a foreground child, resuming a job, and reaping completed children. The table needs to describe the actual process state, rather than just the command that was most recently entered.


Example build and session

gcc -o shell hw2.c
./shell
prompt > pwd
prompt > counter &
prompt > jobs
prompt > fg %1

The helper program counter is supplied by the assignment. A redirection example is add < number.txt > added_number.txt.


What the project clarified

The main lesson was that process management is a set of related state transitions. A shell can successfully launch a program and still mishandle the next interruption or background exit. Building the prompt, execution path, job table, and handlers together made those relationships visible.

Implementing whitespace-based parsing, built-ins, and job control in this course shell gave me a practical foundation for understanding tools that orchestrate other processes.