Skip to content

0xAttra/pipex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pipex - 42 School Project

Description

Pipex is a program that simulates the shell's pipe behavior. It handles command execution, file redirection, and implements features like here_doc and multiple pipes. The project aims to deepen understanding of Unix processes, file descriptors, and pipe mechanisms.

Status

  • Completion Date: 10/01/2025
  • Grade: 125/100 ✨

Features

  • Basic pipe functionality (cmd1 | cmd2)
  • Multiple commands support
  • Here_doc implementation (<<)
  • Error handling
  • Memory management
  • Path resolution for commands

Installation

git clone <repository_url>
cd pipex
make        # For mandatory part
make bonus  # For bonus features

Usage

Basic Usage

./pipex infile cmd1 cmd2 outfile

This is equivalent to: < infile cmd1 | cmd2 > outfile in shell

Multiple Commands (Bonus)

./pipex infile cmd1 cmd2 cmd3 ... cmdn outfile

This is equivalent to: < infile cmd1 | cmd2 | cmd3 ... | cmdn > outfile

Here_doc (Bonus)

./pipex here_doc LIMITER cmd1 cmd2 outfile

This is equivalent to: << LIMITER cmd1 | cmd2 >> outfile

Project Structure

Core Files

  • pipex.c: Main program implementation
  • init_pipex.c: Initialization functions
  • exec_cmds.c: Command execution logic
  • parse_cmds.c: Command parsing and path resolution
  • parse_args.c: Argument parsing
  • exit.c: Cleanup and exit handling

Bonus Files

  • pipex_bonus.c: Extended main program
  • exec_cmds_bonus.c: Multiple command execution
  • heredoc_bonus.c: Here_doc implementation
  • init_pipex_bonus.c: Enhanced initialization
  • Other bonus variants of core files

Headers

  • pipex.h: Main header file
  • pipex_bonus.h: Bonus features header

Implementation Details

Key Features

  1. Process Creation: Uses fork() to create child processes
  2. Pipe Communication: Implements pipe mechanism for inter-process communication
  3. File Handling: Manages file descriptors for input/output redirection
  4. Command Resolution: Searches system PATH for command executables
  5. Memory Management: Proper allocation and deallocation of resources

Data Structure

typedef struct s_pipex
{
    int     in_fd;          // Input file descriptor
    int     out_fd;         // Output file descriptor
    int     *pipefd;        // Pipe file descriptors
    pid_t   *pids;          // Process IDs
    int     child_id;       // Current child process ID
    char    **envp;         // Environment variables
    char    **cmd_path;     // Command paths
    char    ***cmd_args;    // Command arguments
    int     cmd_nb;         // Number of commands
    bool    heredoc;        // Here_doc flag
}   t_pipex;

Error Handling

  • File access permissions
  • Command existence and execution rights
  • Memory allocation failures
  • Pipe creation errors
  • Fork failures
  • Invalid number of arguments

Memory Management

  • All allocated memory is properly freed
  • File descriptors are properly closed
  • Temporary files (here_doc) are cleaned up
  • Handles both success and failure cases

Testing

The program has been tested with various scenarios:

  • Basic pipe operations
  • Multiple commands
  • Here_doc functionality
  • Invalid commands
  • Missing files
  • Permission issues
  • Memory leaks (using Valgrind)

Notes

  • The program follows 42 School's coding standards (Norminette)
  • Error messages are displayed on standard error
  • The program handles environment variables properly
  • Command paths are resolved dynamically
  • Supports both relative and absolute paths for commands

License

This project is developed at 42 School and follows its guidelines. Usage and redistribution are permitted under the school's terms.


Author: macuesta Last Updated: 12/01/2025

About

pipex: a 42 school project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors