Originally Posted by
Nominal Animal
You really should just include your code within [CODE][/CODE] tags; I too almost skipped your post because I couldn't see the code right away. We humans are fickle creatures.
You're very close, actually.
The two thins you need is a second pipe, say pfd2, just like the one you already have; and another fork() instead of the else you already have.
Connect the write end of the new pipe (pfd2[1]) to the standard output (descriptor 1) of the grep process, and its read end ( pfd2[0]) to the standard input (descriptor 0) of the wc process.
It's just about the same as your existing code, except that for the grep process, you'll connect one pipe to standard output and another to its standard input.
If you wrote the code yourself, instead of just blindly copying it from someone/somewhere else, it should not be too difficult, just add another pipe, and extend your if-else chain by one step, adding another fork(). The fact that you attached the code instead of listed it right there in your message is quite suspicious, though.