This project has been created as part of the 42 curriculum by akdovlet.
pipex is a C program that reproduces the behaviour of the Unix shell pipe operator (|). It chains commands together so that the standard output of one becomes the standard input of the next, while reading from an input file and writing the final result to an output file — exactly as a shell would when you type:
< infile cmd1 | cmd2 > outfileThe project deepens understanding of core Unix concepts: file descriptors, process creation with fork, inter-process communication with pipe, program execution with execve, and proper resource management.
- Chains an arbitrary number of commands (bonus) via Unix pipes
- Resolves command paths from the
PATHenvironment variable, with a hardcoded fallback when the environment is empty - Supports commands given as absolute paths (e.g.
/usr/bin/cat) - here_doc mode (bonus): reads input interactively from stdin until a delimiter is found, mimicking
<< DELIMITERshell syntax - Mirrors bash's error handling and exit codes (missing files, invalid commands, permission errors, etc.)
- Catches and propagates child process signals (e.g.
SIGSEGV) - No memory leaks — full cleanup on every exit path
- A C compiler (
cc) - GNU
make - A POSIX-compatible system (Linux / macOS)
# Standard binary (exactly two commands)
make
# Bonus binary (multiple commands + here_doc support)
make bonus
# Build both
make bothThe make command also builds the bundled libft library automatically.
make clean # remove object files
make fclean # remove object files and binaries
make re # fclean + rebuildStandard mode — mirrors < infile cmd1 | cmd2 > outfile:
./pipex infile "cmd1" "cmd2" outfileBonus mode — supports multiple commands:
./pipex_bonus infile "cmd1" "cmd2" ... "cmdN" outfilehere_doc mode (bonus) — replaces the input file with stdin, appends to outfile:
./pipex_bonus here_doc DELIMITER "cmd1" "cmd2" ... "cmdN" outfile# Equivalent to: < /etc/passwd grep root | wc -l > out.txt
./pipex /etc/passwd "grep root" "wc -l" out.txt
# Multiple pipes (bonus)
./pipex_bonus /etc/passwd "grep root" "tr ':' '\n'" "head -5" out.txt
# here_doc (bonus) — type lines, end with EOF
./pipex_bonus here_doc EOF "cat" "wc -l" out.txtpipe(2)man page — creating inter-process communication channelsfork(2)man page — process duplicationexecve(2)man page — replacing a process image with a new programdup2(2)man page — redirecting file descriptorswaitpid(2)man page — waiting for child processes and retrieving exit codesaccess(2)man page — checking file permissions- The Linux Programming Interface — Michael Kerrisk, chapters on processes, pipes, and file I/O
- Advanced Programming in the UNIX Environment — W. Richard Stevens & Stephen Rago
AI (Claude) was used exclusively for the redaction of this README. It was not used at any stage of the development, debugging, or research process. All code, design decisions, and problem-solving were done independently.