Question: Please, have a look at this sample code which is using a very well established programming pattern to redirect `stdout` to a pipe.

```
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    int fd[2];
    pipe(fd);

    pid_t pid = fork();
    if (pid == 0) {
        close(fd[0]);
        dup2(fd[1], 1);
        printf("A string");
        _exit(0);
    }

    close(fd[1]);
    char text[1000];
    size_t size;
    int p = 0;
    while ((size = read(fd[0], text+p, 1)) == 1) {
        p++;
    }
    close(fd[0]);
    text[p] = '\0';
    printf("%s", text);

    return 0;
}

```

The code, as it is, is not working. As correctly suggested in a comment by @kaylum, calling `exit` instead of `_exit` in the child process makes the code working properly.

Answer: 
`exit()` flushes all the open streams as part its termination whereas `_exit()` doesn't flush - so any buffered output is lost when calling `_exit()`.

You can make it "work" either:

1) by calling `fflush(stdout);` to flush the buffered output *before* the call to `_exit()` or  

2) disabling the buffering for stdout with: `setbuf(stdout, 0);` at the beginning of the main().

POSIX requires that streams are flushed by [`exit()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html):

> 
> The exit() function shall then flush all open streams with unwritten
>  buffered data and close all open streams. Finally, the process shall
>  be terminated [CX] with the same consequences as described in
>  Consequences of Process Termination.
> 
> 
> 

Similarly, requires that streams are *not* flushed by [`_exit()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/_Exit.html):

> 
> The \_Exit() [CX] and \_exit() functions shall not call functions
>  registered with atexit() nor any registered signal handlers. [CX]
>  Open streams shall not be flushed. Whether open streams are closed
>  (without flushing) is implementation-defined. Finally, the calling
>  process shall be terminated with the consequences described below.
> 
> 
>
`exit` is a C-level function that flushes and then closes every C-level streams (stdin, stdout and stderr are C-level streams).

`_exit` is a POSIX-level function that closes every system-level streams (descriptors like 0, 1, 2, etc are system-level streams). In this case, buffering is an system internal concern.

You've made a redirection to let `printf` (C-level function) finally writes to descriptor 1 (system-level), but `printf` buffers while buffer is not full and the C-string does not contains `\n` (it is your case). Then terminating by a call to `_exit` will simply lost the unflushed buffer content.

On POSIX systems, `exit` flushes every C-stream and then call `_exit` (which in turn closes every system-stream before really terminating the execution).