This project has been created as part of the 42 curriculum by kraksana.
My implementation of pipex for 42 Bangkok.
The goal of this project is to reproduce the behavior of a simple UNIX pipeline using C system calls such as pipe(), fork(), dup2(), and execve().
pipex takes an input file, two commands, and an output file:
./pipex infile "cmd1" "cmd2" outfileIt behaves like the following shell command:
< infile cmd1 | cmd2 > outfileThe program creates two child processes and connects them through a pipe.
- The first command reads from the input file.
- Its output is sent into the pipe.
- The second command reads from the pipe.
- Its output is written to the output file.
- Executables are searched using the
PATHenvironment variable. - The final exit status is taken from the second command.
Through this project, I practiced working with:
- UNIX processes with
fork() - Pipes and inter-process communication
- File descriptors
- Input and output redirection with
dup2() - Running programs with
execve() - Environment variables and
PATH - Process status with
waitpid() - File handling with
open() - Error handling and exit codes
- Parsing command arguments and quoted strings
Compile the project with:
makeThis creates the pipex executable.
Example:
printf "hello\nworld\n" > infile
./pipex infile "cat" "wc -l" outfile
cat outfileOutput:
2
You can compare the result with the shell:
< infile cat | wc -l > expected
cmp outfile expectedmakeCompiles the project.
make cleanRemoves object files.
make fcleanRemoves object files and the executable.
make reRebuilds the project from scratch.
pipex/
├── Makefile
├── README.md
├── include/
│ └── pipex.h
└── src/
├── main.c
├── pipeline.c
├── process.c
├── execute.c
├── path.c
├── split_command.c
├── split_utils.c
├── string_utils.c
├── memory.c
└── error.c
Mandatory part completed.
The implementation supports a two-command pipeline with input/output redirection, PATH resolution, command parsing, error handling, and exit status propagation.
The project compiles with:
-Wall -Wextra -Werror
and passes Norminette.
man 2 pipeman 2 forkman 2 dup2man 2 execveman 2 waitpidman 2 open- Linux man-pages
- POSIX documentation
AI was used to help review edge cases, organise tests, and explain UNIX process and file descriptor concepts. All code and behavior were reviewed and tested before finalising the project.
Kullatida Raksanaves — nuunnuun