03 Process18 PDF
03 Process18 PDF
Processes
Lecture 3
Michael O’Boyle
1
Overview
• Process
• Process control block
• Process state
• Context switch
• Process creation and termination
2
What is a “process”?
address space
3
What’s “in” a process?
4
A process’s address space (idealized)
0xFFFFFFFF
stack
(dynamic allocated mem)
SP
static data
(data segment)
code PC
(text segment)
0x00000000
5
The OS process namespace
6
Representation of processes by the OS
7
The PCB
8
This is (a
Process ID
simplification of)
Pointer to parent what each of
those PCBs looks
List of children like inside
Process state
Program counter
stack pointer
(all) register values
Scheduling priority
Accounting info
9
PCBs and CPU state
10
PCBs and CPU state
11
Process context switch
12
Process execution states
13
Process states and state transitions
terminate
running
dispatch / interrupt
schedule (unschedule)
14
State queues
15
State queues
These are PCBs
• There may be many wait queues, one for each type of wait
(particular device, timer, message, …)
16
PCBs and state queues
17
Process creation
18
init
pid = 1
emacs tcsch
ps
pid = 9204 pid = 4005
pid = 9298
19
20
Process creation semantics
21
UNIX process creation details
Parent
address space
(code, static
data, heap,
stack)
23
Parent similar, but different Child
PCB in key ways PCB
24
testparent – use of fork( )
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
26
exec() vs. fork()
27
exec() and fork()
28
Parent similar, but different Child
PCB in key ways PCB
29
Parent Child
PCB PCB
30
Making process creation faster
31
Method 1: vfork()
32
Parent similar, but different Child
PCB in key ways PCB
Parent
address space
(code, static
data, heap,
stack)
Vfork()
33
Method 2: copy-on-write
34
UNIX shells
• Process
• Process control blocck
• Process state
• Context switch
• Process creation and termination
• Next time
– threads
36