I'm working on a programming assignment for my Operating Systems class and I'm running into some issues with the way my output is showing up in the terminal.
The purpose of the program is to take input from a file or the STDIN and essentially pass it through 4 pipes to get the frequency of the words. I'm using calls to fork(),execlp(), and pipe() to complete this and am not having any issues with my program, however as the last child executes and prints to the terminal it looks like this:
os-class ~/cs344/Homework3 190% myword text.txt
os-class ~/cs344/Homework3 191% 1 aaaaa
1 aaaaaa
1 aaaaaaa
8 it
5 s
5 sa
(Here I could enter command for 191%, something like 'ls'..)
myword is my executable and text.txt is the file I'm using for testing. I'm mainly confused because it seems like my pipes are lined up correctly with STDIN and STDOUT. Do I need to insert a wait()
somewhere?
Thanks for any suggestions and sorry if there's already an answer to this somewhere! I wasn't exactly sure what to search for.
wait()
(or perhaps severalwait()
calls, maybe in a loop) to ensure that all the output appears beforemyword
exits. – Jonathan Leffler