Skip to content

A simple Unix-style shell implemented for CS 392 (Systems Programming). Features custom command parsing, process inspection via /proc, signal handling, and execution of external programs using fork() and execvp(). Demonstrates understanding of UNIX and processes, and programmed entirely in C.

Notifications You must be signed in to change notification settings

JacobChoi5/minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Minishell

A mini Unix shell implemented in C demonstrating process control, signal handling, and interaction with the Linux /proc filesystem. Developed for CS 392 Systems Programming.

Overview

Minishell is a custom command-line interpreter built from scratch in C. The project showcases low-level systems programming techniques including subprocess creation, directory and filesystem traversal, manual parsing, resource management, and signal-safe I/O.

The repository includes a compiled executable (minishell) as well as the full source implementation.

Core Capabilities

Built-in Commands

Command Description
cd, cd <path> Changes the working directory; supports home directory (~), absolute, and relative paths.
pwd Prints the full current working directory.
lf Lists non-hidden files in the current directory.
lp Enumerates active system processes by scanning the /proc filesystem.
exit Frees allocated resources and exits the shell.

External Program Execution

If a command is not a built-in, the shell delegates execution to the OS using:

  • fork() to spawn a child process
  • execvp() to replace the child process image
  • wait() to synchronize with the parent

Supports variable-length argument lists up to 50 tokens.

Process Listing (lp)

lp replicates a simplified version of top by reading from /proc/[pid]/:

  • Extracts PID from directory names
  • Reads the program’s command line from cmdline
  • Retrieves the associated user from system password entries
  • Stores results in an array of process structs
  • Sorts the list numerically by PID

This demonstrates direct interaction with the Linux /proc virtual filesystem and parsing of kernel-generated process information.

Signal Handling

Minishell implements a custom handler for SIGINT (Ctrl+C):

  • Foreground child processes receive the interrupt
  • The shell itself remains active
  • Interruptions during getline() are detected through a volatile sig_atomic_t flag

Running the Shell

Optional: Recompile from source

gcc minishell.c -o minishell 

Using the executable:

./minishell

About

A simple Unix-style shell implemented for CS 392 (Systems Programming). Features custom command parsing, process inspection via /proc, signal handling, and execution of external programs using fork() and execvp(). Demonstrates understanding of UNIX and processes, and programmed entirely in C.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages