Professional Documents
Culture Documents
Processes
Processes
1 / 44
Processes
2 / 44
Speed
• Multiple processes can increase CPU utilization
- Overlap one process’s computation with another’s wait
emacs wait for input wait for input
gcc
• Multiple processes can reduce latency
- Running A then B requires 100 sec for B to complete
80s 20s
A B
- Running A and B concurrently makes B finish faster
A
B
- A is slower than if it had whole machine to itself,
but still < 100 sec unless both A and B completely CPU-bound
3 / 44
Processes in the real world
5 / 44
Inter-Process Communication
3 Threads
7 / 44
Creating processes
8 / 44
Deleting processes
9 / 44
Running programs
10 / 44
minish.c (simplified)
12 / 44
redirsh.c
14 / 44
pipesh.c (simplified)
17 / 44
Examples
18 / 44
Spawning a process without fork
3 Threads
20 / 44
Implementing processes
ready running
interrupt
I/O or event I/O or event wait
completion
waiting
23 / 44
Scheduling policy
24 / 44
Preemption
25 / 44
Context switch
26 / 44
Context switch details
27 / 44
Outline
3 Threads
28 / 44
Threads
33 / 44
Alternative: User threads
35 / 44
Outline
3 Threads
36 / 44
Background: calling conventions
Procedure call
save active caller registers
push arguments to stack
call foo (pushes pc)
save needed callee registers
...do stuff...
restore callee saved registers
jump back to calling function
restore stack+caller regs.
40 / 44
i386 switch_threads
current next
stack stack
next next
current current
return addr return addr
%esp
%ebx
%ebp
%esi
%edi
%esp
40 / 44
i386 switch_threads
current next
stack stack
next next
current current
return addr return addr
%ebx %ebx
%ebp %ebp
%esi %esi
%edi %edi
%esp %esp
40 / 44
i386 switch_threads
current next
stack stack
next next
current current
return addr return addr
%ebx %ebx
%ebp %ebp
%esi %esi
%edi %edi
%esp %esp
40 / 44
i386 switch_threads
current next
stack stack
next next
current current
return addr return addr
%esp
%ebx
%ebp callee-saved
%esi registers
restored
%edi
%esp
40 / 44
Limitations of user-level threads
41 / 44
User threads on kernel threads
43 / 44
Lessons
44 / 44