I’m trying to learn how to work with fork() to create new processes and pipes to communicate with each process. Let’s say I have a list that contains 20 words, and I create 3 processes. Now, I need to distribute the words between the processes using pipes, and the each process will sort the list of words it receives. The way I want to achieve this is like this:
Word1 => Process1
Word2 => Process2
Word3 => Process3
Word4 => Process1
Word5 => Process2
Word6 => Process3
.
.
.
So each process will have a list of words to sort, and eventually I’ll use MergeSort to merge all the sorted lists returned by each process. I’m not sure how to use pipes to communicate with each process (e.g. feed each process with a word). Any help that would put me on the right track would be appreciated.
Try this code for size. It uses a fixed number of child processes, but you can change that number by adjusting the enum
MAX_KIDS(it was mostly tested with that set at 3; I later changed it to 5 just to make sure).