Difference between Threads and Processes

What is the difference between Threads and Processes?

A process is a collection of virtual memory space, code, data, and system resources. A thread is code that is to be serially executed within a process. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. A process can have multiple threads in addition to the primary thread
A thread is stream of executable code within process. They are light weight process. All thread with in a process share process instruction,code & data segment,open file descriptor,signal handler,userID and GroupID. Thread has its own set of register including program counter,stack pointer

1.Threads(Light weight Processes) share the address space of the process that created it; processes have their own address.

2.Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.

3.Threads can directly communicate with other threads of its process; processes must use interprocess communication to communicate with sibling processes.

4.New threads are easily created; new processes require duplication of the parent process.

5.Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the process; changes to the parent process does not affect child processes

你可能感兴趣的:(thread,Access)