Skip to content

adhiraj2001/Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Unix Shell

A feature-rich Unix shell implementation in C with support for job control, piping, I/O redirection, and signal handling.

Features

  • Built-in Commands: cd, pwd, echo, ls, pinfo, history, jobs, fg, bg, sig, repeat
  • Process Management: Run commands in foreground or background (append &)
  • I/O Redirection: Input (<), output (>), and append (>>)
  • Piping: Chain commands with |
  • Job Control: Manage background processes with jobs, fg, bg
  • Signal Handling: Ctrl-Z (SIGTSTP) and Ctrl-C (SIGINT) for process control
  • Command History: Access last 20 commands with history

Quick Start

# Build the shell
make

# Run the shell
./shell

Usage Examples

# Run command in background
sleep 10 &

# I/O redirection
cat < input.txt > output.txt
echo "append" >> file.txt

# Piping
ls -l | grep ".c" | wc -l

# Job control
jobs                    # List background processes
fg 1                    # Bring job 1 to foreground
bg 2                    # Resume job 2 in background
sig 9 1234              # Send signal 9 to PID 1234

# Built-in commands
cd ~                    # Change to shell's root directory
cd -                    # Return to previous directory
pinfo 1234              # Show process info for PID 1234
repeat 3 echo hello     # Execute command 3 times

Directory Structure

The project is organized into feature-based modules:

  • core/ - Core shell logic (execute, parse, prompt)
  • builtins/ - Built-in commands (cd, pwd, echo, ls, pinfo, history, repeat, jobs, fg, bg, sig)
  • io/ - I/O operations (redirect, piped_command)
  • process/ - Process management (list for background jobs)
  • signals/ - Signal handlers (handler1, handler2, handler3)
  • utils/ - Utility functions (read_details, pinfo2)

The Makefile automatically compiles all files across these directories.

Notes

  • Root directory: The shell uses its execution directory as the root (~). All relative paths resolve against this directory.
  • Signal handling: Ctrl-Z (SIGTSTP) and Ctrl-C (SIGINT) affect foreground processes only; the shell itself is protected.
  • Command history: History is maintained for the current session only (last 20 commands). It does not persist across shell restarts.
  • Background processes: Each background process gets its own process group and is tracked until completion.

About

Shell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published