Professional Documents
Culture Documents
Processes&
Threads
24 August, 2010
1
what is a process?
2
resource + execution
3
typical content of a process control block:
etc.
4
OS maintains
process table
(one PCB / process)
5
OS saves and
restores PCBs to
context switch
between processes
6
when to context switch?
7
blocked I/O
e.g. Java InputStreamʼs read( )
8
interrupt
( I/O or Timer )
e.g. time allocated to a process is used up
or when data arrives over the network
9
ready running
10
which ready process to
run next ?
11
what causes a new
process to be created?
12
system initialization
(e.g, Linux init process)
13
explicit creation through
system call
(e.g, fork( ), CreateProcess( ))
14
upon user requests
(e.g., double click an icon, typing a command)
15
what causes a process
to terminate ?
16
finish running
(with or without error)
17
fatal error
(an example from Lab 1)
18
killed by another
process
(e.g., kill( ) , TerminateProcess( ))
19
recall: process-related
system calls
20
fork wait
exec exit
21
consider a
Web browser
22
23
consider a
Web server
24
concurrent multi-process server
while (1)
block until new connection
fork( )
if (is child process)
handle new connection
exit( )
25
fork( ) is expensive
(do we really need to duplicate all the
resources ?)
26
threads
same resource, different executions
27
a multi-threaded process
28
advantages of
multi-threading
29
vs single-threaded
improved responsiveness
exploits parallelism
abstraction for “independent”
sequence of execution
30
vs multi-process
cheaper
allows sharing of resources
31
POSIX Threads API
pthread_create(
)
pthread_exit(
)
pthread_join(
)
pthread_yield(
)
32
thread scheduling
done by either
process or kernel
33