Duplicate file descriptor after popen

Posted by alaamh on Stack Overflow See other posts from Stack Overflow or by alaamh
Published on 2010-05-06T12:12:50Z Indexed on 2010/05/06 12:18 UTC
Read the original article Hit count: 203

Filed under:
|

I am using popen to execute a command under linux, then 4 process wile use the same output. I am trying to duplicate the file descriptor again to pass it to each process. here is my code:

FILE* file_source = (FILE*) popen(source_command, "r");
int fd = fileno(file_source);
fdatasync(fd);

int fd[4],y, total = 4 ;
    for (y = 0; y < total; y++) {
        dest_fd[y] = dup(fd);
    }

actually if total set to 1 it work fin, after changing total = 4 it does not work anymore.

© Stack Overflow or respective owner

Related posts about c

    Related posts about filedescriptor