Notes on the Midterm

  1. Operating Systems
    1. [3 points] Draw a diagram representing an the relationship between the following terms
      • Application
      • Kernel
      • Library Routines
      • Shell
      • System Call

      There should be some form of the diagram on this page. Note that the only way to access the kernel is through system calls.

    2. [2 points] What is the difference between a process and a program?

      A program is a set of instructions in a computer language. A process is a program that is being executed.

      I would give both parts.

  2. Shells
    1. [2 points] What is a shell?
    2. [6 points] Name, and define or describe three different tasks performed by a shell.

      I would give something close to the information outlined in the notes

  3. Command line arguments
    1. [3 points] Describe how command line arguments are provided at the programming level. Give example code.

      main(int argc, char * argv[])
      where argc is the number of command line arguments, including the command
      and argv contains the values delimited by spaces.

    2. [3 points] How would a programmer search command line arguments for the flag --verbose? Give example code.
      bool verbose = false;
      i = 1;
      while (i < argc and not verbose) {
         if (!strcmp(argv[i],"--verbose")) {
             verbose  = true;
         }
         i++;
      }
      	
    3. [2 points] Describe the operation of the system call char *getenv(const char *name);

      getenv will search the environment array for a string in the form "NAME=value" and return a char * to the first letter of "value" if it is found. If no corresponding "NAME=value" is found it will return NULL.

      I would expect that this would be trivial after the homework.

  4. [6 points] There are 7 different types of files on a Unix/linux file system. Name and describe three.

    Your answer should be based on these notes

  5. I/O
    1. [3 points] The following code is used to open a file. Describe the purpose of each of the components in this command.
      fd = open("myFile", O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)
      	
      fd: the return value is the id of a file desriptor which has been opened or -1 on error
      "myFile": is the name of the file to be opened
      O_RDWR: open the file read/write for the process
      O_CREAT : create the file if it does not exist
      O_TRUNC: truncate (or erase) any data in the file
      S_IRUSR: give the user read permission on the file
      S_IWUSR: give the user write permission on the file

      This code is directly from page 73 of the book.

    2. [5 points] the following code is used to write to a file.
      1. Give code to detect and report an error due to executing this code.
      2. What situation, other than errors, might the programmer need to handle as a result of this code executing?
      for part i
      if (-1 == bytesWritten) {
      perror("Write failed");
      }
      for part 2
      If bytesWritten is less than bufferSize, the the write was incomplete and the rest of the data should be written.
      bytesWritten = write(fd, buffer, bufferSize);
      	
    3. [4 points] Describe the result of seeking 1000 bytes past the end of a file and writing data. Does the program crash due to this action and is the data written lost?

      The data will be written 1000 bytes past the end of the file and there will be a hole in the file. No data will be lost and the program will not crash.

    4. [2 points] What happens if the last reference to a file removed (unlinked), while a process still has an open file descriptor referencing that file?

      The file will remain until the last open file descriptor is closed, at which point the file will be removed.

      I understand that it will be removed when the program exits, but that is an upper bound, it has potential to be removed MUCH sooner.

  6. The File System:

    I expect answers close to these notes.

    1. [3 points] Describe the following components of the unix/linux file system.
      • File descriptor
      • Open File Table
      • I-node table.
    2. [2 points] Describe and provide an illustration showing how the above portions of a file system are related.
    3. [4 points] Two different processes have open file descriptors which point to the same entry in the open file table. What is the implication of this and how could it occur?

      The two processes would share access to the file at the same point. This occured because some time in the past, the processes shared a common ancestor which opened the file.