Skip to content

tuanadurmus/Linux-Shell-Interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Linux-Shell-Interpreter

SUShell is a simplified UNIX shell developed in C that simulates core operating system functionalities. It manages the execution of system commands, handles input/output redirection, and implements a robust pipeline architecture, including a unique "LoopPipe" structure for repetitive command execution.

Features

Process Hierarchy Management: SUShell operates as a parent process that orchestrates the creation and synchronization of child processes using fork(), execvp(), and wait().

Sequential Pipelining: For a pipeline of n commands, the shell creates n-1 unidirectional communication channels (pipes).

LoopPipe Implementation: A specialized feature that flattens complex structures (Before | Loop | After) into a single linear pipeline before execution.

I/O Redirection: Supports input (<) and output (>) redirection by manipulating file descriptors via dup2().

Concurrent Execution: Commands in a pipeline are forked sequentially but run in parallel, synchronized naturally by the kernel's data availability on the pipes.

System Architecture

Process Hierarchy & Pipelining

When a pipeline command is entered, the shell forks children sequentially from left to right. Each command runs as an independent child process. The parent process is responsible for:

  1. Arranging pipes for correct data flow.
  2. Setting up redirection with dup2().
  3. Closing unused pipe ends to ensure EOF propagation and avoid leaks.

Synchronization

The shell relies on UNIX pipes' implicit synchronization. No explicit locking is required because: Read Blocking: A process attempts to read from an empty pipe and blocks until data is written.

Write Blocking: A process attempts to write to a full pipe and blocks until the next command reads.

LoopPipe Logic

The LoopPipe structure allows a set of commands to be repeated while maintaining a continuous data flow.

Flattening: The shell flattens the entire command line into a single unified pipeline prior to execution.

Example: A structure like A | (B | C)_2 | D is expanded to A | B | C | B | C | D.

Input Handling: Input can originate from a redirection file, a preceding pipeline, or the standard terminal.

About

Core execution engine of a UNIX-like shell written in C (pipes, fork/exec, I/O redirection, LoopPipe)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages