Select() never returns true
<p>I'm trying to use <code>pipe()</code> from parent to children to sum parts of a file.  The children receive a position in a file, sum their designated numbers, send their sum back, and the parent sums the child sums.</p>

<p>I've having issues with the code in the parent section to read from the child when it's done.</p>

<p>Code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;sys/wait.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/select.h&gt;
#include &lt;time.h&gt;

int main(int argc, char *argv[])
{
int numchild;
struct timeval stop, start;
int i, j, len, ret, fpos=0, val, count=0, total=0, alltotal=0;
pid_t pid;
int nums = 1000;
FILE * file;

printf("How many children to use: ");
scanf("%d", &amp;numchild);
printf("\nWill use %d child process(es).\n", numchild);

gettimeofday(&amp;start, NULL);
int fd[numchild][2]; //parent to child. one for each
int results[2]; //all children to parent
pipe(results);

fd_set result_fd;
FD_ZERO(&amp;result_fd);
FD_SET(results[0], &amp;result_fd);
struct timeval tm = {.tv_sec=0, .tv_usec=1};

// create all pipes
for (i=0; i&lt;numchild; i++)
{
    pipe(fd[i]);
}

for (i=0; i&lt;numchild; i++)
{
    if((pid = fork()) == 0) // child process
    {
        pid = getpid();

        // read from parent
        len = read(fd[i][0], &amp;fpos, sizeof(fpos));
        if (len &gt; 0)
        {
            file = fopen("file1.dat", "r");
            fseek (file, fpos, SEEK_SET);
            count = 0;
            total = 0;

            printf("Child(%d): Recieved position: %d\n", pid, fpos);

            // read from file starting at fpos
            // add values read to a total value
            while (count &lt; (nums/numchild))
            {
                fscanf(file, "%i", &amp;val);
                total += val;
                count++;
            }
            //write to parent
            write(results[1], &amp;total, sizeof(total));
            printf("Child(%d): Sent %d to parent.\n", pid, total);
        }
        else
        {
            printf("Child(%d): Error with len\n", pid);
        }
        _exit(0);
    }

    // parent process
    pid = getpid();

    fpos = ((i*nums*5)/numchild); // 5 is the offset of the file values

    // write to child process
    printf("Parent(%d): Sending file position to child\n", pid);
    write(fd[i][1], &amp;fpos, sizeof(fpos));

    // wait for child responce
    ret = select(2, &amp;result_fd, NULL, NULL, &amp;tm);
    printf("\t\t%d\n", (FD_ISSET(results[0], &amp;result_fd)));
    if (FD_ISSET(results[0], &amp;result_fd))
    {
        ret = read(results[0], &amp;total, sizeof(total));

        // output total
        printf("Parent(%d): Recieved %d from child.\n", pid, total);
        alltotal += total;
    }
}
wait(0);
gettimeofday(&amp;stop, NULL);
printf("\tTime elapsed: %lu microseconds\n", stop.tv_usec - start.tv_usec);
}
</code></pre>

<p>Near the bottom, my <code>if (FD_ISSET(results[0], &amp;result_fd))</code> never returns anything other than 0, i believe.  I need it to activate to let my parent sum the child sums.</p>

<p>Do you see what's wrong?</p>