I have a quick question about reading from and unnamed pipe in C. I'm forking multiple processes which write to a pipe(using a 2-dimensional array). However, when my parent process tries to read the pipe for each child, it will hang while it waits for a child to write to the pipe. Because I am running multiple processes which are writing multiple messages to a pipe, I want to read them as they come until all pipes are finished(the child processes close their pipes when they are done). So, my question is, how do I stop the read from blocking every time it waits for a child to write? My read looks like this:
//loop through pipes and read them
while(allDone != numChild){
errCheck = read(fd[j][0], line, MAXLINE);
if(errCheck == 0){
allDone++;
close(fd[j][0]);
wait(&status);
}
if(errCheck > 0){
printf("%s\n", line);
}
j++;
if(!(j < numChild))
j = 0;
}
Thank you for the consideration,
JB
This post has been edited by jbedo465: 25 April 2010 - 07:02 PM

New Topic/Question
Reply




MultiQuote





|