Process
|
Threads
|
Can live on its own
|
Always runs in a process
|
All process have separate address space and stacks
|
Threads of a process share address space with each other. Threads have separate stack and registers as process has.
|
Inter process communication is done using IPC
|
Inter thread communication is done through shared memory.
|
Heavy weight in terms of IPC, context switch and creation
|
Light weight in terms of IPC, context switch and creation.
|
Process has data segment and heap of its own
|
Thread does not have them
|
http://buttercola.blogspot.com/2014/11/interview-knowledge-based-questions-1.html
1. Threads are easier to create than processes since they don't require a separate address space.
2. Multithreading requires careful programming since threads share data strucures that should only be modified by one thread at a time. Unlike threads, processes don't share the same
address space.
3. Threads are considered lightweight because they use far less resources than processes.
4. Processes are independent of each other. Threads, since they share the same address space are interdependent, so caution must be taken so that different threads don't step on each other.
This is really another way of stating #2 above.
5. A process can consist of multiple threads.
any program in execution is called as process. Every process has a process state associated with it like memory, resources, code, data etc. In operating system, process has unique process identifier and associated process controller block (PCB).
Thread is an abstract entity which executes a sequence of instructions.
Threads are light weight as compared to process, their creation is efficient and inter thread communication is fast as they use memory to communicate with each other instead of IPC.
Process context switch is rather very expensive operation as compared to thread switches.
Every program has at least one thread of execution. A thread cannot live on its own, it has to be within some process. A process can have multiple threads.
https://www.quora.com/What-is-the-difference-between-a-process-and-a-thread
- Each process has its own code, data and kernel context (VM structures, descriptor table, etc). While the threads of a process, they share the same code, data and kernel context.
- Process context switch is much heavier than a thread context switch for the OS kernel because there is much more state to change.
- Each process is started with a primary thread, but can create additional threads when required
- Process run in separate address space, but threads of a process share address space
- Threads have direct access to data segment of its process; process have their own copy of data segment of parent process. refer to point #2.
- Threads can directly communicate with other threads of that process; processes must use inter-process communication to communicate with sibling processes, directly follows from point #2.
- New threads are easily created; new process require duplication of parent process, and allocation of memory and resources for it are costly.
- Changes to main thread [cancellation, priority change] may affect behavior of other threads of that process; changes to parent process does not affect child or peer processes
- Context switching between threads in the same process is typically faster than context switching between processes.
- In certain OSes, a thread is also known as a lightweight process(lwp), Solaris is one such OS.
- Kernel Thread works on kernel mode only, and owns kernel stack running system context with the same system process address space.
- User Thread works on user mode or kernel mode, and owns kernel stack and user stack running a process address space.
1) Both process and Thread are independent path of execution but one process can have multiple Threads.
2) Every process has its own memory space, executable code and a unique process identifier (PID) while every thread has its own stack in Java but it uses process main memory and share it with other threads.
3) Threads are also refereed as task or light weight process (LWP) in operating system
4) Threads from same process can communicate with each other by using Programming language construct like wait and notify in Java and much simpler than inter process communication.
5) Another difference between Process and Thread in Java is that it's How Thread and process are created. It's easy to create Thread as compared to Process which requires duplication of parent process.
6) All Threads which is part of same process share system resource like file descriptors , Heap Memory and other resource but each Thread has its own Exception handler and own stack in Java.
1. A process can contain more than one thread.2. A process is considered as “heavyweight” while a thread is deemed as “lightweight”.
3. Processes are heavily dependent on system resources available while threads require minimal amounts of resource.
4. Modifying a main thread may affect subsequent threads while changes on a parent process will not necessarily affect child processes.
5. Threads within a process communicate directly while processes do not communicate so easily.
6. Threads are easy to create while processes are not that straightforward.
https://hellosmallworld123.wordpress.com/2014/07/26/more-java-programming-questions/
2) Every process has its own memory space, executable code and a unique process identifier (PID) while every thread has its own stack in Java but it uses process main memory and share it with other threads.
4) Threads from same process can communicate with each other by using Programming language construct like wait and notify in Java and much simpler than inter process communication.
5) Another difference between Process and Thread in Java is that it’s How Thread and process are created. It’s easy to create Thread as compared to Process which requires duplication of parent process.
6) All Threads which is part of same process share system resource like file descriptors , Heap Memory and other resource but each Thread has its own Exception handler and own stack in Java.
http://yuanhsh.iteye.com/blog/2246862- Threads share the address space of the process that created it; processes have their own address space.
- Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.
- Threads can directly communicate with other threads of its process; processes must use interprocess communication to communicate with sibling processes.
- Threads have almost no overhead; processes have considerable overhead.
- New threads are easily created; new processes require duplication of the parent process.
- Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes.
- 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.
Also refer to Algorithms and Me: Anatomy of a Process
Read full article from Algorithms and Me: Process Vs Threads
Read full article from Algorithms and Me: Process Vs Threads