Difference between Process and Thread

Here you will learn about difference between process and thread i.e. process vs thread.

Process: In simple words a process is executing a program. But not all, it’s only an instance of a computing program. Several processes may be associated with the same program. Process contains program code and its current activity.

Thread: We can say thread is a light weight process. A thread of execution is the smallest sequence of programmed instructions that can be managed independently by scheduler. Threads reside inside the process. Each thread belongs to exactly one process. No thread exists outside the process.

Difference between Process and Thread

Image Source

Process vs Thread – Difference between Process and Thread

Process Thread
1) System calls involved in process. 1) No system calls involved.
2) Context switching required. 2) No context switching required.
3) Different process have different copies of code and data. 3) Sharing same copy of code and data can be possible among different threads..
4) Operating system treats different process differently. 4) All user level threads treated as single task for operating system.
5) If a process got blocked, remaining process continue their work. 5) If a user level thread got blocked, all other threads get blocked since they are treated as single task to OS. (Noted: This is can be avoided in kernel level threads).
6) Processes are independent. 6) Threads exist as subsets of a process. They are dependent.
7) Process run in separate memory space. 7) Threads run in shared memory space. And use memory of process which it belong to.
8) Processes have their own program counter (PC), register set, and stack space. 8) Threads share Code section, data section, Address space with other threads.
9) Communication between processes requires some time. 9) Communication between processes requires less time than processes.
10) Processes don’t share the memory with any other process. 10) Threads share the memory with other threads of the same process
11) Process have overhead. 11) Threads have no overhead.

Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications. Another difference between thread and process is that threads within the same process share the same address space, whereas different processes do not.

2 thoughts on “Difference between Process and Thread”

  1. This page is so wrong. In most contexts, threads are implemented by native threads. Native threads are supported by all major OS since about 2 decades. The description is only correct for green threads, and only to a limited extent. Most runtime environments that support green threads do not directly implement green threads, but they implement green threads on top of native threads. A green threads implementation which is not based on native threads would not be able to benefit from multi-core CPUs.
    I seriously hope that nobody uses this page for learning about threads.
    The worst thing that I could imagine is somebody interviewing a programming candidate based on this misinformation.
    The only thing that’s correct is that threads share their memory of the process that they belong to, while processes (per default) don’t share memory. But that’s about all that’s correct on this page.
    On the individual points:
    1. Both, the creation of a process and the creation of a native thread require a system call. The creation of a green thread does not require a system call.
    2. A context switch is always required. In case of a process, the context switch is performed by the OS and switches the CPU and the MMU context. In case of a native thread, the context switch is performed by the OS and switches the CPU only. In case of a green thread, the context switch is performed by the runtime and switches only those parts of the CPU which it knows need to be switched, that is usually the main registers but not special function registers.
    3. That one’s about correct. Processes do not share memory (unless they explicitly allocate and share shared memory). Threads share memory.
    4. Processes and native threads are known to the OS. Native threads usually appear as a single process, unless the user asks the system to explicitly list threads as well. Green threads are not known to the OS.
    5. If a process or a native thread or a green thread makes a blocking call, all other processes and native threads and green threads remain unaffected. Green threads which have been running on the blocked native thread would simply be scheduled on an unblocked thread by the runtime.
    6. This is correct.
    7. This is the same as 3.
    8. This is so misleading that the answer is utmost rubbish. All threads have a separate PC (Program Counter), that’s what defines a thread. The section stuff is about memory, for that see 3./7. The CPU context (PC, registers) is separate for each thread. The MMU context is separate for processes, but multiple threads of the same process share the same MMU context, which is what 3./7. means.
    9. That is correct but very blurred because there are so many ways how to communicate between threads or processes. Processes can use shared memory and then communicate with each other as fast as threads.
    10. This is a repetition of 3. and 7.
    11. This is wrong. Processes have more overhead than native threads. Native threads have more load overhead than green threads but less programming overhead than green threads for the runtime implementor.

Leave a Comment

Your email address will not be published. Required fields are marked *