Duplicate file descriptor after popen
- by alaamh
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.