I have created two processes using fork(). The child process is producing and writing continuously a variable amount of data (array char) to the pipe. The parent process reads from the pipe and prints the received data to stdout.

The code is very simple:

```
switch (fork()) {
  case -1: 
    exit (1);
    break;
  case 0:
    close(fd[0]);
    generate_data(fd[1]);
    break;
  default:
    close(fd[1]);
    while(1) {
        n = read(fd[0], readbuffer, sizeof(readbuffer));
        readbuffer[n] = 0;
        if (n > 0)
            printf ("read: %s\n", readbuffer);            
        else
            exit(1);
    }   
   break;
}   

```

Where `generate_data(int)` iterates over a list, writing each element (string) to the file descriptor given as argument (the write end of the pipe in this case):

```
void generate_data(int fd) 
{
   node_t node* = list;
   while (node != NULL) {
     write(fd, node->data, strlen(node->data)+1);
     node = node->next();
   }

}

```

The problem here is that the output is always unpredictable: the child process writes data to the pipe when the other process is processing the last `read`, so when it calls to read again the rest of the data is not there anymore.

According to `man 2 pipe`, this shouldn't be happening:

> 
> Data written to the write end of the pipe is buffered by the 
>  kernel until it is read from the read end of the pipe.
> 
> 
> 

Taking a list of 10 elements, some output examples:

Example 1:

```
read: element_4
read: element_8
read: element_9

```

Example 2:

```
read: element_7
read: element_8
read: element_9
read: element_10

```

Example 3:

```
read: element_2
read: element_8

```

Anyone has any idea what's happening here?