Question: Please answer correctly and explain in details!! Please the code below!! The following function is supposed to execute a child process, redirecting both input and
Please answer correctly and explain in details!! Please the code below!!
The following function is supposed to execute a child process, redirecting both input and output from/to files given as parameters. Complete thic code to make it work. Note that: Unused file descriptors must be properly closed. In case of error, your code shall exit with a return value of 1. We assung that none of the C library calls can fail except for execvp(). dup2(fd, fd2) calises file descriptor fd2 to refer to the same open file description as fd. /* Does the equivalent of $ program arguments. . outfile. */ void redirection (char *command [], char *infile, char *outfile) int fd [2]; fd[0] = open(infile, O_RDONLY); fd[1] = open(outfile, O_RDWR | O_CREAT | O_TRUNC, 0644); if (fork() == 0) { /* Complete here */ The following function is supposed to execute a child process, redirecting both input and output from/to files given as parameters. Complete thic code to make it work. Note that: Unused file descriptors must be properly closed. In case of error, your code shall exit with a return value of 1. We assung that none of the C library calls can fail except for execvp(). dup2(fd, fd2) calises file descriptor fd2 to refer to the same open file description as fd. /* Does the equivalent of $ program arguments. . outfile. */ void redirection (char *command [], char *infile, char *outfile) int fd [2]; fd[0] = open(infile, O_RDONLY); fd[1] = open(outfile, O_RDWR | O_CREAT | O_TRUNC, 0644); if (fork() == 0) { /* Complete here */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
