Operating Systems 2019F: Assignment 1

From Soma-notes
Revision as of 21:37, 27 September 2019 by Soma (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Please submit the answers to the following questions via CULearn by 4 PM on On September 27, 2019. There are 20 points in 12 questions.

Submit your answers as a single text file named "<username>-comp3000-assign1.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Assignment 1", your name, student number, and the date of submission. You may wish to format your answers in Markdown to improve their appearance.

No other formats will be accepted. Submitting in another format will likely result in your assignment not being graded and you receiving no marks for this assignment. In particular do not submit an MS Word, OpenOffice, or PDF file as your answers document!

Don't forget to include what outside resources you used to complete each of your answers, including other students, man pages, and web resources. You do not need to list help from the instructor, TA, or information found in the textbook.

All questions below refer to 3000shell.c from Tutorial 2. Whet a question asks what some code does, explain what the code does and the purpose of that functionality in the context of the entire program. In other words, explain what that code is and why it is there.

Questions

  1. [1] When you run 3000shell normally in a terminal windown on Linux, what is open on file descriptors 0, 1, and 2? How do you know?
  2. [1] How could you change run_program() so that it has as few arguments as possible, without defining any new global variables? For the arguments you remove, how could run_program() get those values?
  3. [1] How can you change 3000shell so that it outputs the return status of every program run in the foreground (i.e., not backgrounded)? Note the return status is the value returned by main().
  4. [1] How would the behaviour of 3000shell change if line 241 was removed?
  5. [1] What do lines 171-175 do? Explain briefly.
  6. [1] When is the value set on line 317 used? How can you force this value to be used?
  7. [2] In line 240, what will be the contents of the file created by creat()? Also, what will be the owner, group, and permissions of the file created?
  8. [2] What system calls does plist() generate? What are they for?
  9. [2] How could you modify 3000shell so it only calls wait() once, in the signal handler? Specifically, how could it pause until the external command finishes without line 234?
  10. [2] Implement the "cd" command.
  11. [3] Implement a "findhere" command that lists files in the current directory that contain the given pattern in the filename. The pattern allow for standard shell "glob" patterns, e.g., findhere book* should list all the files that start with the word book.
  12. [3] Implement a MS-DOS style pipe command. Make sure it allows for command-line arguments to be passed to the programs. You only need to support one pipe command at a time. For example, when you type ls | wc the shell should
    • write the output of ls to a temporary file by redirecting standard output when running ls, and
    • run wc, redirecting standard input so it reads from the temporary file written to by ls.

Solutions

Assignment 1 Solutions.