CSCI 311 Test 1 Spring 2017


  1. (6 points) Name and describe three distinct tasks performed by the linux kernel.

    This is fond on page 22-23 of your book.

    Please note, the question asks you to both name and describe. An answer such as devices is almost completely insufficient.

  2. Program Kernel Interaction
    1. (3 points) What is a system call?

      (p 43) A controlled entry point into the kernel allowing a process to request that the kernel perform some action on behalf of the process.

      But if you told me it was a way for a program to request the kernel to perform an action I was probably ok.

    2. (2 points) What is a library function?

      A function contained in (the standard) library.

    3. (2 points) Give an example of a system call and a library function. Label each clearly.

      getpid() - system call.

      atoi() - library function. I would make sure that the thing I listed was clearly an example of each type. For example, perror() is a function.

  3. Errors.
    1. (2 points) How can a programmer determine if an error has occurred during a system call?

      (P 48) By checking the return value. Return values of 0 usually indicate success and -1 usually indicate failure, but this changes from call to call and the user should consult the man pages to be sure.

      I would be very careful here. If you tell me that 0 is always success, this is wrong. Think of read/write.

    2. (3 points) What utilities exist to help the programmer communicate to the user the error that has occurred during a system call.

      perror, strerror, errno, cerr, stderr

  4. (8 points) There are four basic system calls associated with performing file I/O. Name and describe each.

    open, close, read, write.

  5. (3 points) Describe the actions performed by int dup2(int oldfd, int newfd);

    If newfd is open, it is closed. newfd becomes a copy of oldfd.

  6. I/O Redirection.
    1. (2 points) Describe what the following command does at the I/O level who | more

      The standard output of who is supplied as the standard input to more.

    2. (4 points) Draw a diagram showing the execute of these programs, including the shell, over time. Include labels such as fork, exec, and wait. Also include the process names.
    3. (6 points) Provide the code, including system calls, which the shell might use to accomplish the above task. You do not need to have the parameters to the system calls completely correct.
      	pid = fork  // the child will become who
      	if (pid == 0) 
      	    pipe
      	    pid = fork  // the child will become more
      	    if (pid == 0) 
      	       close input of pipe
      	       close stdin 
      	       dup2 (pipe out, stdin);
      	       execute more
                  else
      	       close output of pipe
      	       close stdout
      	       dup2(pipein, stdout)
      	       execute who
      	else // the shell
      	  wait
      	
  7. (2 points each)The File System
  8. (1 point each) Name three different types of files on the linux file system.