blob: 41a40805b75bd76cf994bd984d7a48856dd15250 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# 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
1. Parses command-line arguments and splits them into separate commands using `;;` as a delimiter.
2. Creates a pipe before forking processes.
3. For the **first process**:
- Closes the read end of the pipe.
- Redirects stdout to the write end of the pipe.
4. For the **second process**:
- Closes the write end of the pipe.
- Redirects stdin to the read end of the pipe.
5. Executes commands via `execvp`.
6. Waits for all child processes to finish.
7. Prints the names of commands that exited with status `0`.
## Usage
Compile:
```bash
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
```bash
./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`.
|