Question: Im trying to learn how to pipe and use fork in c. Im trying to pipe data from one program to another. im piping 2

Im trying to learn how to pipe and use fork in c. Im trying to pipe data from one program to another.

im piping 2 strings to another program.

What I did was if had 2 pipe variables.

int fd1[2];

int fd2[2];

in the child, I did

close(fd1[1]);

close(fd2[1]);

dup2(fd_user[0], STDIN_FILENO);

dup2(fd_pass[0], STDIN_FILENO);

close(fd1[0]);

close(fd2[0]);

execl("./name", "./name", NULL);

in parent I had

close(fd1[0]);

close(fd2[0]);

write(fd1[1], buf1, sizeof(buf1));

write(fd2[1], buf2, sizeof(buf2));

close(fd1[1]);

close(fd2{1]);

The problem is that in my other program, when I try to read from stdin_fileno, my error handler says that nothing was read from stdin_fileno.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!