Following Function Supposed Execute Child Process Redirecting Input Output Files Given Par Q43864472
Please answer correctly and explain in details!! Please the codebelow!!
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. . < infile > 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 */ Show transcribed image text 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 */
Expert Answer
Answer to The following function is supposed to execute a child process, redirecting both input and output from/to files given as …
OR