Difference between revisions of "Operating Systems 2019W: Assignment 1"

From Soma-notes
Jump to navigation Jump to search
Line 12: Line 12:
# [1] When you run a program from 3000shell, what does that program get for file descriptors 0, 1, and 2?  Assume that you are running 3000shell in a standard terminal on Linux.
# [1] When you run a program from 3000shell, what does that program get for file descriptors 0, 1, and 2?  Assume that you are running 3000shell in a standard terminal on Linux.
# [1] If line 293 from 3000shell.c is removed, <tt>pid = wait(ret_status);</tt>, how will the behavior of 3000shell change?
# [1] If line 293 from 3000shell.c is removed, <tt>pid = wait(ret_status);</tt>, how will the behavior of 3000shell change?
# [2] Are system calls used to set signal handlers?  Use output from <tt>strace</tt> that shows your answer is correct.
# [2] Are system calls used to set signal handlers?  Use output from <tt>strace</tt> to show your answer is correct.
# [1] The system calls 3000shell uses to search for a program to run (in one of the PATH directories) are not the same as those used by standard shells such as bash.  What's the difference?
# [1] How would the behaviour of 3000shell change if lines 299 and 300 were removed?
# [1] How could you change 3000shell so that it generates zombie processes?
# [2] How would the behaviour of 3000shell change if line 286 was removed? (<tt>pid = fork();</tt>)  Why?
# [2] In 3000shell, when are lines 299 and 300 executed?  Why?
# [2] In 3000shell, when are lines 299 and 300 executed?  Why?
# [2] Does using <tt>getenv()</tt> generate any additional library calls (as reported by ltrace)? Does it generate any additional system calls (as reported by strace)Why?
# [2] What system calls (if any) does the plist() function generate?
# [2] Does parse_args() allocate any memory on the heap (i.e., any memory that stays allocated after the function returns)? How do you know? Give a brief argument.
# [1] What does the call to setup_comm_fn() for in line 167 do?
# [2] <tt>execve</tt> overwrites all of a process's memory with that of a new executable.  Does <tt>execve</tt> also close all open file descriptors?  How do you know (from your experience with 3000shell)?
# [2] Does find_env() generate any system calls?  Use output from <tt>strace</tt> to show your answer is correct.
# [2] What happens to an in-progress system call when a process receives a signal(An example is a program waiting for input from a terminal with a blocking <tt>read</tt> call.)  What does "restarting" a system call have to do with this?
# [2] Give the assembly code corresponding to the allocation of pattern[] on line 63. Note that this allocation may be for multiple variables.  How do you know your answer is correct?
# [2] If you changed plist() so it took proc_prefix as an argument (rather than accessing it as a global variable), what output would it produce when given an argument other than "/proc"?  Explain briefly.
# [2] How can <tt>execve</tt> overwrite all of a process's memory while also preserving its file descriptors?  Specifically, does preserving file descriptors require execve to avoid erasing some process memory?
# [2] Is the SA_RESTART flag on a signal handler (e.g., line 243) interpreted by code running in the process or in the kernelGive evidence for your answer.
# [3] Implement a "listfiles" command that lists the files in the current directory.  Give the code for the listfiles() function and show how you'd change the rest of the code so that typing "listfiles" runs this function.
# [2] Describe how you could add output redirection for external programs to 3000shell.
# [2] Describe how you could add output redirection for external programs to 3000shell.

Revision as of 18:55, 20 January 2019

This assignment is not yet finalized, please do not answer these questions yet!

Please submit the answers to the following questions via CULearn by 4 PM on January 28, 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.

Questions

  1. [1] When you run a program from 3000shell, what does that program get for file descriptors 0, 1, and 2? Assume that you are running 3000shell in a standard terminal on Linux.
  2. [1] If line 293 from 3000shell.c is removed, pid = wait(ret_status);, how will the behavior of 3000shell change?
  3. [2] Are system calls used to set signal handlers? Use output from strace to show your answer is correct.
  4. [1] How would the behaviour of 3000shell change if lines 299 and 300 were removed?
  5. [2] In 3000shell, when are lines 299 and 300 executed? Why?
  6. [2] What system calls (if any) does the plist() function generate?
  7. [1] What does the call to setup_comm_fn() for in line 167 do?
  8. [2] Does find_env() generate any system calls? Use output from strace to show your answer is correct.
  9. [2] Give the assembly code corresponding to the allocation of pattern[] on line 63. Note that this allocation may be for multiple variables. How do you know your answer is correct?
  10. [2] How can execve overwrite all of a process's memory while also preserving its file descriptors? Specifically, does preserving file descriptors require execve to avoid erasing some process memory?
  11. [2] Is the SA_RESTART flag on a signal handler (e.g., line 243) interpreted by code running in the process or in the kernel? Give evidence for your answer.
  12. [3] Implement a "listfiles" command that lists the files in the current directory. Give the code for the listfiles() function and show how you'd change the rest of the code so that typing "listfiles" runs this function.
  13. [2] Describe how you could add output redirection for external programs to 3000shell.