Skip to content

A feature-rich Unix-like shell implemented in C, featuring custom built-ins, multi-stage piping, I/O redirection, and robust process management.

License

Notifications You must be signed in to change notification settings

Visheshs3/c-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

C-Shell

A custom shell implementation in C, supporting various built-in commands, process management, and I/O redirection.

Features

Built-in Commands

  • hop: Changes the current working directory.

    • Usage: hop <path>
    • Supports flags: . (current), .. (parent), ~ (home), - (previous).
  • reveal: Lists files and directories.

    • Usage: reveal <flags> <path>
    • Flags: -a (show hidden), -l (long format).
    • Color-coded output for files, directories, and executables.
  • log: Manages command history.

    • Usage: log (show history), log purge (clear history), log execute <index> (run command from history).
    • Stores up to 15 commands. Prevents duplicates.
  • activities: Lists all currently running processes spawned by the shell.

    • Shows PID, Command Name, and State (Running/Stopped).
  • ping: Sends a signal to a specific process.

    • Usage: ping <pid> <signal_number>
  • fg: Brings a background process to the foreground.

    • Usage: fg <pid>
  • bg: Changes a stopped background process to running (in the background).

    • Usage: bg <pid>

System Capabilities

  • Command Execution: Executes standard system commands (e.g., ls, cat, sleep) using execvp.
  • Background Processes: Supports running commands in the background using &.
  • I/O Redirection:
    • >: Output redirection (overwrite).
    • >>: Output redirection (append).
    • <: Input redirection.
  • Piping: Supports piping between commands using |.
  • Signal Handling:
    • Ctrl+C (SIGINT): Interrupts the foreground process.
    • Ctrl+Z (SIGTSTP): Pushes the foreground process to the background (stopped).
    • Ctrl+D: Logs out of the shell.

Compilation and Usage

  1. Navigate to the shell directory:

    cd shell
  2. Compile the shell:

    make
  3. Run the shell:

    ./shell.out

File Structure

  • src/: Source code files (.c).
  • include/: Header files (.h).
  • Makefile: Build configuration.

Implementation Details

  • Parser: Tokenizes input handling spaces, tabs, and special characters.
  • Process Management: Tracks background processes and updates their status.
  • History: Persists command history across sessions (stored in a log file).

About

A feature-rich Unix-like shell implemented in C, featuring custom built-ins, multi-stage piping, I/O redirection, and robust process management.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published