CSCI 311 Test 1 Spring 2018


  1. Environment Variables
    1. [2 points] What is an environment variable?
    2. [2 points] Give an example of a "standard" environment variable and describe how this environment variable is used.
    3. [6 points] A c++ programmer wishes to check to value of an environment variable. Describe two ways this can be done. (I expect code or pseudo-code)
  2. Program Execution
    1. [3 points] What does the fork system call do? What are the return values?
    2. [3 points] Describe the operation of the waitpid system call.
      pid_t waitpid(pid_t pid, int *wstatus, int options);
      
    3. [2 points] What does the option WNOHANG do when passed to waitpid.
    4. [2 points] What happens to a process which has exited but the parent does not call wait, waitpid or handle a SIGCHLD signal?
  3. Pipes
    1. [2 points] What is a pipe?
    2. [2 points] Describe the conditions required for two processes to use a pipe for communications.
    3. [6 points] Provide a code segment which uses a pipe to communicate between two processes. The first process should send the numbers 1 through 10 to the pipe. The second process should read these numbers and print them out to the standard output. This segment should begin with creation of the pipe.
  4. Errors
    1. [3 points] Describe how a programmer can detect that an error has occurred during a system call.
    2. [3 points] Describe how a programmer can determine which error has occurred during a system call.
  5. Misc
    1. [6 points] Name and describe three tasks performed by the shell.
    2. [6 points] Describe a situation where a programmer might choose to implement a program in BASH, Python and C++? Justify your selection. (There should be three answers like: BASH would be good for xxx because yyy).
    3. [2 points] Name and describe one task performed by process-id 1.