Skip to content
Advertisement

Multi-Process Shell in C, using Pipes [Linux]

I’m trying to code a shell in C that supports multi-pipe process handling, depending on the amount of separate processes given by the user, and each separated by a “|” symbol. The shell forks the amount of processes into a child for each process.

Here’s an example:

JavaScript

result: 1

But I’m having trouble with communicating between children and finally to the parent process.

Here’s my current code for the execpipe function, which executes the pipe process, being argv1 and argv2 the 2 separate processes given by user input: (Example: ls -l | wc -l)

JavaScript

Advertisement

Answer

The parent must close the pipe’s write end to indicate the second process that no more data will come:

JavaScript

Little note: instead of

JavaScript

why not

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement