Force a program created with `exec` to execute unbuffered I / O

I am trying to interact with an external program in C using pipe, forkand exec. I want to force an external program to execute unbuffered I / O. Here is the corresponding code snippet from my code:

...
pid = fork();
if (pid == (pid_t) 0)
{
    /* child process */

    /* make pipe connections to standard streams */             
    dup2(wpipe[0], STDIN_FILENO);
    dup2(rpipe[1], STDOUT_FILENO);

    /* close pipe endings */
    close(wpipe[0]); close(rpipe[0]);
    close(wpipe[1]); close(rpipe[1]);

    /* unbuffered I/O */
    setvbuf(stdin, NULL, _IONBF, BUFSIZ);
    setvbuf(stdout, NULL, _IONBF, BUFSIZ); 

    if (execl("path/to/some_binary", "path/to/some_binary", (char *) NULL) == -1)
    {
        fprintf(stderr, "exec failed\n");
        return EXIT_FAILURE;
    }   
    return EXIT_SUCCESS;
}
...

This does not work because the threads do not go beyond the calls exec. Thus, using setvbufforced unbuffered I / O does not work because the program image ( some_binary) creates its own streams stdin and stdout and does not use the streams that I called setvbufon.

, some_binary setvbuf . , , exec? , , unix, , cat ls?

+2
2

, ( execve(2) ...)

(, libc, <stdio.h>). execve -ed.

, LD_PRELOAD, setvbuf(stdin, NULL, _IONBF, BUFSIZ); execve ( main....); .

, constructor LD_PRELOAD -ed . printf, fopen,.... ...

, :

.

. , , , poll (2), ( ) . - : (, poll [ ] ) - (. libevent libev, , , GTK Qt ..)

(2), poll - C10K

, Linux...

. .

+1

, . gdb /proc. , fds, /proc.

UPDATE:

glibc, glibc, , .

0

All Articles