Question: C Programming I need the code to include this step (1) if you are the child process then redirect standard input (STDIN_FILENO) to the input

C Programming

I need the code to include this step

(1) if you are the child process then redirect standard input (STDIN_FILENO) to the input end of the parent-to-child pipe, and redirect standard output (STDOUT_FILENO) to the output end of the child-to-parent pipe.

Current code

#include

#include

int main()

{

int pipefds[2];

int status;

int pid;

char write[BUFSIZ];

char read[BUFSIZ];

status = pipe(pipefds);

if (status == -1)

{

printf("Unable to create pipe ");

return 1;

}

pid = fork();

// Child process

if (pid == 0)

{

close(pipefds[1]);

read(pipefds[0], read, BUFSIZ);

printf("You Entered: %s", read);

}

else

{

close(pipefds[0]);

//Parent process

printf("Enter an integer or end to quit: \t");

fgets(write, BUFSIZ, stdin);

write(pipefds[1], write, BUFSIZ);

}

return 0;

}

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!