Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions