ECE 2524: Piping

Hi everyone,
Past week we had a unix assignment in which we had to pipe two cpp files. One of the cpp files called “Generator.cpp” counted numbers and printed them to standard out. The other cpp file called “Consumer.cpp” took numbers from standard in took their average and printed it to standard out. Our assignment was to pipe them and also create a make file. Creating a Make file was really easy. The hardest part of this assignment I found was piping the two cpp files. At first I thought if U just use ./generator | ./consumer .. it should work, but I was wrong. The best way to this is to create a seperate cpp file in which you use fork command and also execute ./generator and ./consumer. Everything worked fine then. The key thing was to kill the ./generator using the kill command. One part that I was stuck on was waiting on the ./consumer to end. I used waitpid and wait command; however, it did not work. The generator executable was fine with the waitpid command. But ./consumer was not working. My program would get stuck when I called the wait command twice. If anyone have some thoughts on that then it would be great.

Leave a Reply

Your email address will not be published. Required fields are marked *