kernel thread
Download
Report
Transcript kernel thread
Times to process
EOS STUT
1
Relationship of processes
EOS STUT
2
Getting and setting process group
EOS STUT
3
Create a session
EOS STUT
4
example
EOS STUT
5
Thread
EOS STUT
6
Thread
A thread is contained inside a process. Multiple
threads can exist within the same process and
share resources such as memory, while different
processes do not share these resources.
Thread可以分成三類
User space thread
Kernel space thread
這類thread在user space執行,通常以library的方式存在,kernel本
身不知道user space thread的存在,因此kernel還是以process為排
程單位
這類thread在kernel space執行,kernel可以直接以它作為排程單位,
由於切換需要進入kernel,所以其速度比user thread稍慢
Hybrid
前兩者的混合體
EOS STUT
7
Threads compared with processes
processes are typically independent, while threads exist as subsets
of a process
processes carry considerable state information, where multiple
threads within a process share state as well as memory and other
resources
processes have separate address spaces, where threads share
their address space
processes interact only through system-provided inter-process
communication mechanisms.
Context switching between threads in the same process is typically
faster than context switching between processes.
Systems like Windows NT and OS/2 are said to have "cheap"
threads and "expensive" processes; in other operating systems
there is not so great a difference except the cost of address
space change which implies a TLB flush.
EOS STUT
8
Processes, kernel threads, user threads, and fibers
A process is the "heaviest" unit of kernel scheduling
A kernel thread is the "lightest" unit of kernel scheduling.
Threads are sometimes implemented in userspace libraries,
thus called user threads. The kernel is not aware of them,
they are managed and scheduled in userspace. Some
implementations base their user threads on top of several
kernel threads to benefit from multi-processor machines
(N:M model).
Fibers are an even lighter unit of scheduling which are
cooperatively scheduled: a running fiber must explicitly
"yield" to allow another fiber to run, which makes their
implementation much easier than kernel or user threads. A
fiber can be scheduled to run in any thread in the same
process.
EOS STUT
9
Single and Multithreaded Processes
EOS STUT
10