CSCI 311 Test 1 Spring 2019


  1. History
    1. [4 points] For programmers, why is it important that a set of standards are established and that an API conforms to these standards?

  2. Command Line Arguments and Environment Variables
    1. [5 points] Discuss the type and use of each of the parameters to main in a C/C++ program. Describe any special requirements for the second and third parameters to main.
    2. [4 points] Describe at least four ways a program can obtain a default value for a variable that controls the behavior of a program.
  3. Errors
    1. [3 points] What is the most common method for the kernel to signal that an error has occurred in a system call?
    2. [6 points] In a program, how can a programmer determine what error a system call encountered? Provide a code segment to illustrate this.

  4. Program Suspension
    1. [4 points] Describe the purpose of the system call sleep
    2. [2 points] Describe the conditions when sleep returns.
    3. [6 points] Provide a code segment that will allow a program to sleep for 10 seconds even if the program receives signals.

  5. Program Execution
    1. [4 points] Describe the outcome of calling the system call fork
    2. [12 points] Write a simple program which takes a command line argument -p n and prints Hello World from pid from n different processes. Your program should check the environment and if the variable GREETING is defined, Hello World should be replaced with the value of that string.

      For example, if the program is called prob7:

      $ prob7 -p 3
      Hello World from 17086
      Hello World from 17087
      Hello World from 17088
      $ export GREETING="Hi there"
      $ prob7 -p 3
      Hi there from 17093
      Hi there from 17094
      Hi there from 17095
      
      You do not need to provide headers, but you should comment on each segment describing what you are accomplishing. If you do not know how to accomplish one portion of the problem provide a comment describing what the portion should accomplish.