Pipeline Executor with Delimiters
This project implements a small command-line utility in C that executes two
programs connected via a pipeline, using a custom ;;
delimiter to separate
commands.
Features
- Runs two commands, connected with a pipe:
- The first command’s output is sent to the second command’s input.
- Uses
;;
as a custom delimiter to split commands. - Forks and executes each command using
execvp
. - Tracks process IDs and command names in a linked list.
- Prints the name of each command that terminates successfully (exit status 0).
- Cleans up dynamically allocated memory for process tracking.
How It Works
- Parses command-line arguments and splits them into separate commands using
;;
as a delimiter. - Creates a pipe before forking processes.
- For the first process:
- Closes the read end of the pipe.
- Redirects stdout to the write end of the pipe.
- For the second process:
- Closes the write end of the pipe.
- Redirects stdin to the read end of the pipe.
- Executes commands via
execvp
. - Waits for all child processes to finish.
- Prints the names of commands that exited with status
0
.
Usage
Compile:
git clone https://git.scratko.xyz/parallel-progs-by-args
cd parallel-progs-by-args
gcc -o pipeline_exec parallel_progs_by_args.c
Run with two commands separated by ;;
Example
./pipeline_exec echo hello world ;; tr a-z A-Z
This will:
- Run echo hello world, sending its output into tr a-z A-Z.
- Print the names of commands that executed successfully.
Notes
- Requires at least one
;;
delimiter to separate commands. - Currently supports exactly two commands in the pipeline.
- Command names in output are taken from the original arguments, not from
the executed binary name after
execvp
.