Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by mkhandaq.

pipex

Description

pipex is a program that recreates the pipe mechanism found in Unix shells. It executes two commands in sequence, connecting them via a pipe so that the output of the first command becomes the input of the second command, mimicking the behavior of the shell pipe operator |.

The program takes four arguments: an input file, two commands, and an output file. It behaves like the following shell command:

< file1 cmd1 | cmd2 > file2

The goal of this project is to understand and implement fundamental Unix concepts including inter-process communication through pipes, process creation with fork(), file descriptor manipulation with dup2(), command execution with execve(), and process synchronization with waitpid().

Instructions

Compilation

To compile the project, use the provided Makefile:

make        # Compiles the pipex executable
make clean  # Removes object files
make fclean # Removes object files and the executable
make re     # Recompiles everything from scratch

Execution

The program requires exactly 4 arguments:

./pipex file1 cmd1 cmd2 file2

Where:

  • file1 is the input file
  • cmd1 is the first command to execute
  • cmd2 is the second command to execute
  • file2 is the output file

Examples:

./pipex infile "grep hello" "wc -l" outfile

This is equivalent to: < infile grep hello | wc -l > outfile

./pipex input.txt "cat" "grep 42" output.txt

This is equivalent to: < input.txt cat | grep 42 > output.txt

The program will execute cmd1 with file1 as input, pipe the output to cmd2, and write the final result to file2. Error messages are printed to stderr when files cannot be accessed or commands are not found. The program returns the exit status of the last successfully executed command.

Resources

Documentation

  • [pipe(2) - Linux manual page] - Create an interprocess channel
  • [fork(2) - Linux manual page] - Create a child process
  • [execve(2) - Linux manual page] - Execute a program
  • [dup2(2) - Linux manual page] - Duplicate a file descriptor
  • [waitpid(2) - Linux manual page] - Wait for process state changes
  • [access(2) - Linux manual page] - Check user's permissions for a file

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages