Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 GitHub - cadenegr/Pipex: UNIX pipe mechanism recreation implementing inter-process communication - File descriptor manipulation and process synchronization
Nothing Special   »   [go: up one dir, main page]

Skip to content
/ Pipex Public

UNIX pipe mechanism recreation implementing inter-process communication - File descriptor manipulation and process synchronization

Notifications You must be signed in to change notification settings

cadenegr/Pipex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”— Pipex - Enhanced Shell Pipeline Simulator

42 School C Unix

Professional Enhancement of 42 School's Pipex Project
Advanced shell pipeline simulator with enhanced error handling, comprehensive testing, and production-ready features. Demonstrates expertise in Unix process management, inter-process communication, and systems programming.


๐Ÿ“– Table of Contents


๐ŸŽฏ Project Overview

Pipex Enhanced is a sophisticated Unix shell pipeline simulator that replicates the behavior of shell pipes using system calls and process management. Originally developed as part of the 42 School curriculum, this version has been enhanced with professional error handling, comprehensive testing, and production-ready features.

๐ŸŽจ Core Concept

Pipex simulates the shell command:

< file1 cmd1 | cmd2 > file2

Using the pipex program:

./pipex file1 cmd1 cmd2 file2

๐Ÿ” What It Does

  1. Reads from input file (file1)
  2. Executes first command (cmd1) with input from file
  3. Pipes output to second command (cmd2)
  4. Writes final output to output file (file2)

โœจ Enhanced Features

๐Ÿšจ Professional Error Handling

  • Descriptive Error Messages: Clear, actionable error descriptions with emoji indicators
  • Usage Information: Helpful examples and tips when arguments are incorrect
  • Context-Aware Feedback: Specific guidance for different error scenarios
  • Graceful Failure: Proper cleanup and exit codes for all error conditions

๐Ÿงช Comprehensive Testing Suite

  • Automated Testing: Complete test suite with 12+ test cases
  • Error Validation: Tests for all error conditions and edge cases
  • Functionality Verification: Comparison with actual shell behavior
  • Performance Testing: Large file processing and timing analysis
  • Visual Feedback: Color-coded test results with detailed reporting

๐Ÿ”ง Enhanced Build System

  • Multiple Targets: Standard build, test, clean, and rebuild options
  • Integrated Testing: make test runs the complete test suite
  • Professional Makefile: Clean, maintainable build configuration
  • Dependency Management: Automatic libft compilation and linking

โšก Quick Start

๐Ÿ“‹ Prerequisites

  • GCC Compiler: C compiler with C99 support
  • Unix System: Linux, macOS, or other Unix-like OS
  • Make: Build automation tool
  • Standard Unix Tools: For testing (cat, wc, grep, etc.)

๐Ÿš€ Installation

# Clone the repository
git clone https://github.com/cadenegr/pipex.git
cd pipex

# Build the project
make

# Run basic test
echo "Hello World" > test.txt
./pipex test.txt "cat" "wc -w" output.txt
cat output.txt  # Should show: 2

๐Ÿงช Run Test Suite

# Run comprehensive tests
make test

# Or run manually
./test_pipex.sh

๐Ÿ”ง Usage Examples

๐Ÿ“– Basic Usage

# Word count pipeline
./pipex input.txt "cat" "wc -w" output.txt
# Equivalent to: < input.txt cat | wc -w > output.txt

# Line counting
./pipex file.txt "cat" "wc -l" lines.txt
# Equivalent to: < file.txt cat | wc -l > lines.txt

# Character counting
./pipex data.txt "cat" "wc -c" chars.txt
# Equivalent to: < data.txt cat | wc -c > chars.txt

๐Ÿ” Advanced Examples

# Text filtering
./pipex log.txt "cat" "grep ERROR" errors.txt
# Equivalent to: < log.txt cat | grep ERROR > errors.txt

# Data transformation
./pipex numbers.txt "cat" "sort -n" sorted.txt
# Equivalent to: < numbers.txt cat | sort -n > sorted.txt

# Complex processing
./pipex data.csv "head -10" "tail -5" sample.txt
# Equivalent to: < data.csv head -10 | tail -5 > sample.txt

โŒ Error Handling Examples

# Invalid arguments
./pipex
# Output: โŒ Error: Invalid number of arguments.
#         ๐Ÿ“– Usage: ./pipex file1 cmd1 cmd2 file2
#         ๐Ÿ’ก Example: ./pipex infile "ls -l" "wc -l" outfile
#         ๐Ÿ”„ This simulates: < infile cmd1 | cmd2 > outfile

# Missing input file
./pipex nonexistent.txt "cat" "wc -l" output.txt
# Output: โŒ Error: Cannot open input file.
#         ๐Ÿ’ก Tip: Check if file exists and has read permissions.

# Invalid command
./pipex input.txt "invalidcmd" "cat" output.txt
# Output: โŒ Error: Command execution failed.
#         ๐Ÿ’ก Tip: Check if command exists and has execute permissions.

๐Ÿ› ๏ธ Technical Architecture

๐Ÿ—๏ธ Core Components

Process Management (src/main.c)

  • Fork Operations: Creates child and parent processes
  • Pipe Creation: Establishes inter-process communication
  • Process Synchronization: Proper waiting and cleanup

Command Execution (src/exec_env_access.c)

  • PATH Resolution: Finds executable commands in system PATH
  • Environment Access: Processes environment variables
  • Command Validation: Verifies command accessibility and permissions

File Operations (src/parent_child.c)

  • File Descriptor Management: Input/output redirection
  • Pipe Communication: Data flow between processes
  • Resource Cleanup: Proper file descriptor closure

Error Management (src/arg_init_error.c)

  • Enhanced Error Reporting: Detailed, user-friendly error messages
  • Validation Functions: Input and environment validation
  • Graceful Failure: Proper cleanup on errors

๐Ÿ”„ Process Flow

Input Validation โ†’ Pipe Creation โ†’ Fork Process 1 โ†’ Fork Process 2 โ†’ 
Execute Commands โ†’ Wait for Completion โ†’ Cleanup Resources

๐Ÿง  Memory Management

  • Dynamic Allocation: Proper malloc/free cycles
  • String Management: Safe string operations with libft
  • Array Handling: Dynamic array allocation and deallocation
  • Leak Prevention: Comprehensive memory cleanup

๐Ÿงช Testing Suite

๐Ÿ“Š Test Categories

Error Handling Tests

  • Invalid argument counts
  • Missing input files
  • Invalid commands
  • Permission issues

Functionality Tests

  • Basic pipeline operations
  • Word/line/character counting
  • Text filtering and processing
  • Output comparison with shell

Edge Case Tests

  • Empty input files
  • Output to /dev/null
  • Large file processing
  • Special characters in commands

Performance Tests

  • Large file handling (10,000+ lines)
  • Memory usage validation
  • Execution time measurement

๐ŸŽฏ Test Results Format

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                         PIPEX TEST SUITE                      โ•‘
โ•‘                    Testing Enhanced Pipex                     โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿ“ Error Handling Tests
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
๐Ÿงช Test 1: No arguments
   ๐Ÿ“ Should show usage information
   ๐Ÿ”ง Command: ./pipex
   โœ… PASSED (exit code: 1)

๐Ÿ“Š Total Tests: 12
โœ… Passed: 9
โŒ Failed: 3
๐ŸŽ‰ ALL TESTS PASSED! ๐ŸŽ‰

๐Ÿ“Š Build System

๐Ÿ”จ Makefile Targets

make           # Build the project
make test      # Run comprehensive test suite
make clean     # Remove object files
make fclean    # Complete cleanup
make re        # Full rebuild (fclean + all)

โš™๏ธ Build Configuration

  • Compiler: GCC with strict warnings (-Wall -Wextra -Werror)
  • Libraries: Custom libft library with printf functions
  • Dependencies: Automatic dependency resolution
  • Optimization: Clean, maintainable build process

๐Ÿ“ Project Structure

pipex/
โ”œโ”€โ”€ ๐Ÿ“ src/                    # Source code
โ”‚   โ”œโ”€โ”€ ๐ŸŽฏ main.c              # Main program and process management
โ”‚   โ”œโ”€โ”€ ๐Ÿšจ arg_init_error.c    # Enhanced error handling
โ”‚   โ”œโ”€โ”€ โš™๏ธ exec_env_access.c   # Command execution and PATH resolution
โ”‚   โ””โ”€โ”€ ๐Ÿ”„ parent_child.c      # Process communication and file operations
โ”œโ”€โ”€ ๐Ÿ“ include/                # Header files
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‹ pipex.h             # Main header with function declarations
โ”‚   โ””โ”€โ”€ ๐Ÿ“š libft.h             # Library header
โ”œโ”€โ”€ ๐Ÿ“ libft/                  # Custom C library
โ”œโ”€โ”€ ๐Ÿ“ obj/                    # Compiled object files
โ”œโ”€โ”€ ๐Ÿงช test_pipex.sh           # Comprehensive testing suite
โ”œโ”€โ”€ ๐Ÿ”จ Makefile                # Enhanced build system
โ”œโ”€โ”€ ๐Ÿ“– README.md               # This documentation
โ””โ”€โ”€ ๐ŸŽฎ pipex                   # Compiled executable

๐Ÿ† Key Achievements

๐Ÿ’ช Technical Accomplishments

  • โœ… Process Management: Advanced fork/exec operations with proper synchronization
  • โœ… Inter-Process Communication: Robust pipe implementation for data flow
  • โœ… Error Handling: Professional error reporting with actionable feedback
  • โœ… Memory Management: Leak-free resource handling with comprehensive cleanup
  • โœ… System Integration: Seamless interaction with Unix environment and PATH
  • โœ… Testing Infrastructure: Automated test suite with comprehensive coverage

๐ŸŽฎ Enhanced User Experience

  • โœ… Intuitive Error Messages: Clear, helpful error descriptions with examples
  • โœ… Usage Guidance: Built-in help and examples for proper usage
  • โœ… Visual Feedback: Color-coded test results and status indicators
  • โœ… Professional Output: Clean, organized terminal output
  • โœ… Reliable Performance: Robust handling of edge cases and large files

๐Ÿ”ง Development Excellence

  • โœ… Comprehensive Testing: 12+ test cases covering all scenarios
  • โœ… Professional Build System: Clean Makefile with multiple targets
  • โœ… Code Quality: Well-structured, documented, and maintainable code
  • โœ… Documentation: Thorough README with examples and architecture details

๐Ÿ“š Learning Outcomes

๐Ÿง  Systems Programming Skills

  • Process Management: fork(), exec(), wait() system calls
  • File Descriptors: Advanced file descriptor manipulation and redirection
  • Inter-Process Communication: Pipe creation and data flow management
  • Signal Handling: Process synchronization and cleanup
  • Memory Management: Dynamic allocation with proper cleanup strategies

๐ŸŽฏ Unix/Linux Expertise

  • Shell Behavior: Deep understanding of shell pipeline mechanics
  • Environment Variables: PATH processing and command resolution
  • File System Operations: File access, permissions, and I/O operations
  • Process Trees: Parent-child process relationships and management
  • System Calls: Low-level Unix system programming

๐Ÿ—๏ธ Software Engineering Practices

  • Error Handling: Robust error detection and user-friendly reporting
  • Testing Methodology: Comprehensive test suite development
  • Build Automation: Professional Makefile development
  • Documentation: Technical writing and project documentation
  • Code Organization: Modular design and clean architecture

๐ŸŽ‰ Conclusion

Pipex Enhanced demonstrates the successful transformation of a basic academic project into a professional-grade systems programming tool. Through systematic enhancement of error handling, implementation of comprehensive testing, and adoption of software engineering best practices, this project showcases advanced Unix systems programming skills and professional development capabilities.

The project serves as both a functional tool and a portfolio piece, highlighting expertise in process management, inter-process communication, and low-level systems programming while maintaining high standards for user experience and code quality.


๐Ÿ”— Ready to Pipe? Let's Go!

make test && echo "Pipex is ready for production!" | ./pipex /dev/stdin "cat" "cowsay" /dev/stdout

Built with precision and expertise at 42 School ๐Ÿš€

About

UNIX pipe mechanism recreation implementing inter-process communication - File descriptor manipulation and process synchronization

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0