Difference Between Process And Threads,!
For anyone who has worked in a large company, this analogy might strike close to home. Threads are like different rooms in one building (different Threads in one process) and different buildings for one company ( different processes for one company). It is so much easier for different folks in one building to work together as they have easy access to each other and that buildings resources.
A process has Its own private virtual memory space, and its own handle table ( so handles to files, and other kernel object). So whatever you do in that address space does not affect other processes , so for example writing to address Ox07000000 has no effect on that address in another process.
Threads on the other hand share the virtual memory space in a single process, so 0x07000000 updated by thread A affects threas B in the same process. You can clearly see this can be advantageous to share data easily and handles, etc but also makes it easy to make mistakes. It makes a difference from a security boundary, for example if you want to really really isolate code, a different process is better than a different thread. To bring back the analogy, different departments have different buildings in a university.
It used to be that processes were significantly heavier to create than threads but that has decreased with newer OS architectures.
Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.
Process:
Each process provides the resources needed to execute a program. A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution. Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.
Thread:
A thread is the entity within a process that can be scheduled for execution. All threads of a process share its virtual address space and system resources. In addition, each thread maintains exception handlers, a scheduling priority, thread local storage, a unique thread identifier, and a set of structures the system will use to save the thread context until it is scheduled. The thread context includes the thread's set of machine registers, the kernel stack, a thread environment block, and a user stack in the address space of the thread's process. Threads can also have their own security context, which can be used for impersonating clients.
Source:Stackoverflow and Quora.
Comments
Post a Comment