Question 1 (11 points, 20 minutes)

Introduction

In the Bourne shell (sh, not csh), commands are executed in the standard way (using fork()/exec()), and you can specify several kinds of file redirection. For example,
cat < f1 > f2
executes 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> f2
this 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>&1
This 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:

The questions

Suppose the following C program is in prog.c
#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> output
Then the following is output: Answer for the following calls. For your convenience, you can use the "Answer Sheet for Question 1."