<
<html>
  <head>
    <title>Pipex</title>
  </head>
function buildAmazingProject() {
  const innovation = true;
  return success;
}
git commit -m "feat: 42 Abu Dhabi Project"
git push origin main
🚀 Deployment successful!
// Clean, maintainable code
const result = await deploy();
console.log('Project live! 🎉');
01001000 01100101 01101100 01101100 01101111
01010111 01101111 01110010 01101100 01100100
01000011 01101111 01100100 01100101
01001001 01101110 01101110 01101111 01110110 01100001 01110100 01100101
01000010 01110101 01101001 01101100 01100100
01000100 01100101 01110000 01101100 01101111 01111001
01010011 01110101 01100011 01100011 01100101 01110011 01110011
$ npm run build
</> Code
{
}
</>
42 Abu Dhabi Project

Pipex

Shell Pipe Implementation

Scroll to explore

Project Overview

Implementation of shell pipe functionality in C, handling process communication, command execution, and inter-process data flow similar to shell pipe operations.

3 weeks
Development Time
Individual Project
Team Size
Pipex - Project Screenshot showcasing technical implementation

Technology Stack

Cutting-edge technologies and tools that power this project

C

Programming Language

Pipes

IPC Mechanism

Process Management

Fork & Exec

File Descriptors

I/O Redirection

Stack Overview

This project leverages a modern tech stack combining 4 powerful technologies to deliver exceptional performance, scalability, and user experience.

Key Features

Innovative features that make this project stand out from the crowd

Pipe Communication

Implemented pipe mechanism for inter-process communication, enabling data flow between commands.

Learn more

Command Execution

Executes shell commands with proper argument parsing and environment variable handling.

Learn more

File Redirection

Handles input and output redirection, reading from files and writing results to output files.

Learn more

Process Management

Manages child processes using fork() and execve() with proper error handling and cleanup.

Learn more

Feature Highlights

These 4 key features work together to create an exceptional user experience, combining functionality with modern design principles.

Development Journey

Key milestones and phases that shaped this project from concept to completion

Phase 1

Process Architecture Design

Designed the process communication architecture and established the basic pipe mechanism for inter-process data flow.

Process Design Pipe Architecture IPC Planning
Phase 2

Command Execution

Implemented command parsing and execution using fork() and execve() with proper argument handling and PATH resolution.

Command Parsing Fork/Exec PATH Resolution
Phase 3

Pipe Communication

Established pipe communication between processes with proper file descriptor management and data flow control.

Pipe Communication FD Management Data Flow

Code Spotlight

Core pipex implementation with process communication

pipex.c
C
// Main pipex function handling pipe communication
int main(int argc, char **argv, char **envp)
{
    int     pipe_fd[2];
    pid_t   pid1, pid2;
    
    if (argc != 5)
    {
        ft_putstr_fd("Usage: ./pipex file1 cmd1 cmd2 file2\n", 2);
        return (1);
    }
    
    if (pipe(pipe_fd) == -1)
        error_exit("Pipe creation failed");
    
    pid1 = fork();
    if (pid1 == 0)
        first_child(argv, envp, pipe_fd);
    
    pid2 = fork();
    if (pid2 == 0)
        second_child(argv, envp, pipe_fd);
    
    close(pipe_fd[0]);
    close(pipe_fd[1]);
    
    waitpid(pid1, NULL, 0);
    waitpid(pid2, NULL, 0);
    
    return (0);
}

// First child process handling
void first_child(char **argv, char **envp, int *pipe_fd)
{
    int infile;
    
    infile = open(argv[1], O_RDONLY);
    if (infile == -1)
        error_exit("Input file error");
    
    dup2(infile, STDIN_FILENO);
    dup2(pipe_fd[1], STDOUT_FILENO);
    
    close(pipe_fd[0]);
    close(pipe_fd[1]);
    close(infile);
    
    execute_command(argv[2], envp);
}

// Second child process handling
void second_child(char **argv, char **envp, int *pipe_fd)
{
    int outfile;
    
    outfile = open(argv[4], O_WRONLY | O_CREAT | O_TRUNC, 0644);
    if (outfile == -1)
        error_exit("Output file error");
    
    dup2(pipe_fd[0], STDIN_FILENO);
    dup2(outfile, STDOUT_FILENO);
    
    close(pipe_fd[0]);
    close(pipe_fd[1]);
    close(outfile);
    
    execute_command(argv[3], envp);
}

Code Explanation

This code snippet demonstrates key functionality and implementation patterns used throughout the project.

Technical Challenges

Complex problems encountered during development and the innovative solutions that overcame them

Process Synchronization

Challenge

Coordinating multiple processes and ensuring proper data flow through pipes without deadlocks or race conditions.

Solution

Implemented proper process creation and waiting mechanisms with signal handling and systematic pipe management.

Deep dive

File Descriptor Management

Challenge

Managing file descriptors and ensuring proper cleanup to prevent resource leaks and maintain system stability.

Solution

Developed systematic approach to file descriptor handling with proper closing and comprehensive error checking.

Deep dive

Command Execution

Challenge

Properly parsing and executing shell commands with argument handling and environment variable management.

Solution

Implemented robust command parsing with PATH resolution and proper argument formatting for execve() calls.

Deep dive

Ready to Explore?

Experience the project firsthand or dive into the source code to see how it all comes together. Your feedback and contributions are always welcome!

Star on GitHub
Share Project
Give Feedback