Skip to content

A C-based Multi-file POSIX Shell that supports I/O redirection, pipelining, background processes, multi-command inputs and other custom functions.

Notifications You must be signed in to change notification settings

SiddharthMago/POSIX-Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Custom Shell in C

Operating Systems and Networks Project in C.

📑 Table of Contents

  1. Project Overview
  2. Features
  3. Prerequisites
  4. Installation & Build
  5. Usage
  6. Built-in Commands
  7. Internal Architecture & Functions
  8. Key Implementation Highlights
  9. Code Organization
  10. Testing
  11. Contributing
  12. License

📌 Project Overview

This is a Unix-style custom shell implemented in C as an Operating Systems and Networks Project. The shell replicates core functionalities of standard terminals including command parsing, background execution, built-in utilities, job control, history logging, aliasing, piping, redirection, and networked manual pages. It includes modular signal handling, CLI responsiveness, and persistent shell states.


🚀 Features

  • Dynamic Prompt — Displays <user@host:cwd> using ~ for home directory
  • Built-in Commands — Includes hop, reveal, log, seek, proclore, alias, activities, ping, and a bonus neonate
  • Background Process Handling — Signals, exit notifications, job tracking
  • External Command Execution — Uses fork and exec, supports & and time tracking
  • History Logging — Up to 15 entries, with support for purge and re-execution
  • Aliasing — Dynamic alias creation and recall during sessions
  • Redirection and Piping — Custom logic for both native and external commands
  • Modular Codebase — Clean separation of logic across files
  • Signal Safety — Handles ctrl+C, ctrl+Z, and ctrl+D gracefully
  • iMan — Fetches formatted man pages via networking sockets
  • Bonus: Neonate Mode — Real-time monitoring of system PIDs

📦 Prerequisites

  • GCC Compiler (v9.0 or higher recommended)
  • Unix/Linux-based OS
  • Terminal with POSIX support

⚙️ Installation & Build

make
./a.out

Alternatively:

gcc *.c -o mysh
./mysh

🧪 Usage

Launch the shell using ./a.out. Sample usage:

<user@host:~> hop Documents
<user@host:~/Documents> reveal -la .
<user@host:~/Documents> sleep 5 &
<user@host:~/Documents> log
<user@host:~/Documents> alias ll = reveal -la
<user@host:~/Documents> ping google.com
<user@host:~/Documents> iMan ls

Use ctrl+D to exit safely.


🔧 Built-in Commands

Command Description
hop Change directory (~, ., .., -, full path)
reveal Enhanced ls with color, -a, -l flags
log View past commands, purge log, or re-execute (log execute n)
proclore Inspect process details using /proc
seek Recursive file/directory search with -d for directory-only mode
alias Define and display dynamic aliases
activities Show all shell-created background processes
ping Ping utility from within the shell
neonate Monitor latest PIDs in real time
iMan Fetch formatted man pages using sockets

🧠 Internal Architecture & Functions

🗂 Header File

  • functions.h — Contains all library includes, globals, and function declarations

🧱 Core Files

  • main.c — Initializes shell, calls main loop
  • main-logic.c — Handles the core input → parse → execute loop

🔨 Feature Modules

  • hop.c — Implements directory navigation
  • reveal.c — Custom ls with sorting, coloring, and permission logic
  • log.c — Persistent command logging system
  • proclore.c — Process inspection from /proc/<pid>
  • seek.c — Uses nftw() for recursive search
  • alias.c — Dynamic aliasing logic and storage
  • activities-ping.c — Background process tracking and signal handling
  • neonate.c — Real-time PID monitoring
  • networking.c — Fetches and formats man pages (iMan)

⚙️ Utility Modules

  • syscom.c — Executes system-level commands via exec
  • redirection-piping.c — Implements custom redirection and piping
  • misc.c — Time tracking and prompt formatting functions

💡 Key Implementation Highlights

  • CLI remains intact even after asynchronous signals
  • Logs include errors but ignore commands related to log itself
  • Only latest long-running commands get reported with execution time
  • Redirection errors from built-in commands are redirected to file
  • Aliases are stored dynamically and logged with original command
  • Activities are sorted by PID (not lexicographically)
  • ctrl+D only triggers exit when no foreground job is active
  • Global process array tracks all background shell jobs
  • Signal handling ensures child/background processes are cleaned properly

🧩 Code Organization

.
├── Makefile
├── functions.h
├── main.c
├── main-logic.c
├── hop.c
├── reveal.c
├── log.c
├── syscom.c
├── proclore.c
├── seek.c
├── alias.c
├── redirection-piping.c
├── activities-ping.c
├── neonate.c
├── networking.c
├── misc.c

Each module handles a specific functionality to ensure readability and modularity.


✅ Testing

  • Sequential and piped command execution
  • Foreground and background job management
  • Error handling in custom commands
  • Alias resolution and redefinition
  • Persistent and accurate logging
  • Neonate PID monitoring via /proc
  • Socket response validation for iMan

🤝 Contributing

Pull requests are welcome!
Please maintain modularity and consistency in naming and structure.
Document all added functions with inline comments.


📄 License

This project is licensed under the MIT License.


About

A C-based Multi-file POSIX Shell that supports I/O redirection, pipelining, background processes, multi-command inputs and other custom functions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published