cat < f1 > f2executes the cat program and redirects standard input and output so that standard input comes from the file f1 and standard output comes from the file f2. This should be familiar to you. There are two other kinds of redirection:
wc f1 2> f2this executes "wc f1" and redirects file descriptor number 2 (standard error) to the file f2. This will work for any file descriptor (i.e. wc f1 3> f2 will redirect file descriptor number 3 to the file f2.
wc f1 2>&1This executes "wc f1," but before doing so, it calls dup2(1, 2). Again, this works for any file descriptors.
All redirections on the sh command line are performed from left to right.
Given the above description plus your knowledge of how standard file redirection works (i.e. how you implemented it in jsh), answer the following:
#include < stdio.h > main() { int i; char *s = "A\n"; i = open("f1", O_WRONLY | O_CREAT | O_TRUNC, 0666); printf("CS360\n"); fprintf(stderr, "%d\n", i); write(i, s, strlen(s)); write(3, s, strlen(s)); }Show the output on the screen plus the contents of all files created when the following commands are called with sh. If you think your answer might be wrong, explain how you got it.
For example, after calling:
prog 2> outputThen the following is output: