Here is the scenario , My parent process has a range (a,b) and a number N.I want to compute all the primes between (a,b). But the processing part is done by N child processes.
So , I create a pipe and then divide the range in N parts.(a1,b1) ... (an,bn) .Then I create N child process.Then in the parent I write each range sequentially to the write end.
Here comes the problem , If there were only one child process I could've followed this answer. If multiple process were trying to write to the pipe , this answer would be acceptable. But Here multiple process is trying to read and a process is trying to read from the pipe should read exactly two integers one after another so this part should be atomic. May be I can try to use mutex , but don't know how to use mutex for interprocess.How can I achieve this ?