Skip to content
/ PIP Public

A lightweight C implementation of Unix-style pipelines using fork, pipe, dup2, and execve.

Notifications You must be signed in to change notification settings

Sfeso13/PIP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 PIP Isn't PIPEX

C Linux OpenSource

PIP is a lightweight implementation of Unix-style pipelines. It executes commands, redirects their input/output, and connects them using pipes—mimicking the behavior of:

< infile cmd1 | cmd2 | cmd3 > outfile

It is written entirely in C using low-level system calls, with no reliance on external utilities beyond what a POSIX system already provides.


📋 Table of Contents


Film Projector About

PIP is a minimal command pipeline executor. Its purpose is to provide a small, readable, dependency-free implementation of:

  • Process creation fork
  • Inter-process communication pipe
  • Standard stream redirection dup2
  • Command execution execve
  • Error propagation & file handling

It aims to act as a reference for developers who want to understand how shells execute pipelines internally.


Control Knobs Features

  • ✅ Environment-aware command resolution (PATH lookup)
  • ✅ Clean process management and error handling

Mandatory part:

  • ✅ Execute two commands chained via pipes
  • ✅ Redirect input/output from files (< or >)

Bonus part:

  • ⭐ Support for here-documents (<<)
  • ⭐ Support for append-mode (>>)

Card File Box Project Structure

Click to expand
Pip/
├── mandatory/         # Character classification
│   ├── main.c
│   ├── pipe.c
│   ├── utils.c
│   └── pipe.h
│
├── bonus/            # File descriptor I/O utilities
│   ├── main_bonus.c
│   ├── pipe_bonus.c
│   ├── utils_bonus.c
│   └── pipe_bonus.h
| 
├── README.md
├── Makefile
├── libft.h
└── libft.a

Gear Setup

  1. Clone the repository
git clone https://github.com/Sfeso13/pip.git
cd pip
  1. Compile the library
make # for mandatory part

make bonus # for bonus part

This creates a runnable program called pipex/pipex_bonus.

  1. Clean compiled objects
make clean      # remove object files
make fclean     # remove object files and library
make re         # rebuild everything

Abacus Usage

Mandatory part:

In this part the program takes 4 arguments: input file, command1 to run, commad2 to run, outfile:

./pipex infile "cmd1" "cmd2" outfile

equivalent to:

< infile cmd1 | cmd2 > outfile

example:

./pipex infile cat "wc -l" outfile

Bonus part:

  1. In this bonus part, the program support multiple piped commands (as long as the first and last argument are, respectively, the input and output file):

example:

./pipex_bonus infile cmd1 cmd2 cmd3 cmd4 cmd5 outfile

equivalent to:

cmd1 < infile | cmd2 | cmd3 | cmd4 | cmd5 > outfile
  1. It also supports the here_doc and append mode, by specifying here_doc as the first argument

example:

./pipex_bonus here_doc LIMITER cmd1 cmd2 outfile

equivalent to:

cmd1 << LIMITER | cmd2 >> outfile

About

A lightweight C implementation of Unix-style pipelines using fork, pipe, dup2, and execve.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published