Overview

In the last reading, we were introduced to the concept of a process, which is a program in execution. In this reading we’ll learn how to control processes, including how to create them, how to make them stop, and how to make them change what they are doing.

Required Reading

Sections 8.3 - 8.4 (pp. 737-756) from the course textbook.

Learning Objectives

BASIC Learning Objectives

Each student will be responsible for learning and demonstrating proficiency in the following objectives PRIOR to the class meeting. The reading quiz will test these objectives.

  1. Describe the basic operation of the fork system call.
  2. Compare and contrast a parent process and one of its children processes.
  3. Given C code with calls to fork and exit, draw a process graph.
  4. Summarize the functionality of execve and describe how it differs from the fork function.
  5. Describe how fork and execve are used by a shell.
  6. Trace C code that involves the following system calls: getpid, getppid, exit, fork, wait, sleep, and execve.

ADVANCED Learning Objectives

The following objectives should be mastered by each student DURING and FOLLOWING the class session through active work and practice.

  1. Given a C program with calls to fork, determine how many processes there will be each point during execution.
  2. Given C code, determine whether there will be any zombies that will NOT be reaped before the parent terminates.
  3. Write C programs that make use of process control system calls (e.g. fork and execve).

Pre-class Exercises

These exercises are geared towards mastering the BASIC learning objectives listed above. You are expected to submit them before class and it is highly recommended that you complete them before attempting the reading quiz.

  1. Give a one sentence summary of the functionality of the following system calls. Use your own words (i.e. don’t just copy from the book).

  2. What is meant by the statement, “fork is called once but returns twice?” Again, use your own words, not the book’s.

  3. Draw a process graph for the following code, using the style show in Figure 8.17 in your textbook. Assume that calls to Fork always succeed.

    int main() {
        if (Fork() == 0) {
            Fork();
            printf("yay!");
            exit(0);
        }
        printf("woohoo!");
        Fork();
        exit(0);
    }
  4. How does the address space of a newly create process compare with the address space of its parent?

  5. How does a shell use the fork and execve to execute a program that you type in?