Processes 1: Basics

Overview

This lecture introduces the process control unit. We discuss the goals of process control and the basic system calls used to create and manage processes.

Full lecture notes on process controlTextbook readings

Processes

Process coordination

Basic shell operation

  1. Print a prompt
  2. Wait for user to enter a command line
  3. Execute the command line in a new process or processes
  4. Wait for the command line processes to complete
  5. Repeat

Simple shell commands

$ echo foo
foo
$ sleep 5

Process control system calls

Process = image + identity + environment view

fork creates a new process

Process hierarchy

fork: Which runs first?

The uniq utility

execvp runs a new program

_exit terminates this process

waitpid monitors a child process for completion

minishell.cc

Question

pid_t p1 = getpid();
pid_t p2 = getppid();
pid_t p3 = fork();
pid_t p4 = getpid();
pid_t p5 = getppid();
assert(???);

Some answers

Exit notification as a communication channel