Overview
This bridge 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 control — Textbook readings
You know what’s cooler than one process?
-
…
-
More than one process
About process control
- Processes are cool
- Isolation (a process can die without taking down the system)
- Strong modularity (a process has independent behavior)
- Are processes components?
- A modular component contributes to a larger system
- Wheels + gear + pedal = bicycle
- Whole greater than the sum of its parts
- Requires coordination mechanisms
- Like a bicycle chain
Process coordination
- Want to coordinate multiple processes to accomplish complex tasks
- Implement many tasks by coordinating existing processes
- Take advantage of more computing resources
- When one process is paused (e.g., reading from storage), run another
- A process must coordinate the operation of others
- Prototypical coordination program: the shell
Process control system calls
- What sub-tasks are required for process coordination?
- Create a process:
fork
- Run a program:
exec
family - Exit a process:
_exit
- Stop a process:
kill
- Await completion:
waitpid
fork1.cc
Process = program image + identity + environment
- Program image: contents of memory and registers
- Code, data, (initially empty) stack and heap
- Command line arguments (
argc
,argv
) - Directly managed by process
- Identity: process names
- Process ID
- Process relationships (parent process ID)
- Ownership, timing, etc.
- Managed by kernel; process influence constrained by policy
- Environment: connections among processes and devices
- Open file descriptors, file positions
- Lives in kernel, managed by process using system calls
- Process has its own view of the environment (the file descriptor table)
- But the underlying world is shared
fork
creates a new process
- New process has:
- Cloned program image
- New identity
- Cloned environment view
- Shared underlying environment
fork2.cc
Process hierarchy
- Every process has a parent process
getpid
system call: Return current process IDgetppid
system call: Return parent process IDfork
creates a new child process
- Root of process hierarchy is process with ID 1 (
init
)- What happens if a parent process dies before its child?
Process control and caches
- The stdio cache is stored in process memory
- That is, it is part of the program image
- Process control + stdio can be fun!
./fork2 > x
./forkmix
./forkmix | less
./forkmix > x