Compare the Difference Between Similar Terms

Difference Between Process and Thread

Process vs Thread
 

In order to let computers do more than one activity at a time, both process and thread provide a great service, but there is difference between them in the way they operate. All the programs running on a computer uses at least one process or thread. Process and thread let the processor switch smoothly among several tasks while sharing computer’s resources. So it is the duty of a programmer to use threads and processes in an efficient way to make a processor with high performance. The implementation of threads and processes differs according to the operating system available.

What is a Process?

A process, in general, is a continuous series of actions to achieve a specific result. But, in the world of computers, a process is an instance of an executing computer program. In other words, it is an idea of a single occurrence of a running computer program. Simply processes are running binaries that contain one or more threads.

According to the number of threads involved in a process, there are two types of processes. They are single-thread processes and multi-thread processes. As its name suggests, a single-thread process is a process that has only one thread. Therefore, this thread is a process, and there is only one activity happening. In a multi-thread process, there are more than one thread, and there are more than one activity that are happening.

Two or more processes can communicate within each other using inter-process communication. But it is quite difficult and need more resources. When making a new process a programmer has to do two things. They are duplication of the parent process and allocation of memory and resources for the new process. So this is really expensive.

What is a Thread?

In the world of IT, a thread is the smallest execution of instructions of a computer program that can be managed independently according to a schedule. A thread is a simple path of execution within a process. A thread is as powerful as a process because a thread can do anything that a process can do. A thread is a light-weight process and needs only fewer resources. Threads can read from and write to the same variables and data structures variable. Thread can communicate between threads easily.

Today multi-threading has become a natural approach to many problems. A big work is divided into parts and each of them is assigned to a unit of execution called a thread. This is simply multi-threading. This requires careful programming because threads share data structures that are modified by another thread at a time and also because threads shares the same address space. One more advantage of threads is that threads provide an efficient and effective way of achieving parallelism. A throughput of a system can be increased by letting multiple threads run on multiple processors because thread is an independently schedulable entity.

Mutli-threading

What is the difference between Process and Thread?

• Processes are difficult to create because it needs a duplication of the parent process and memory allocation whereas threads are easy to create since they do not require a separate address space.

• Threads are used for simple tasks while processes are used for heavy-weight tasks such as execution of an application.

• Processes do not share the same address space, but threads within the same process share the same address space.

• Processes are independent of each other, but threads are inter-dependent as they share the same address space.

• A process can consist of multiple threads.

• Since threads share same address space, virtualized memory is only associated with processes but not with threads. But a distinct virtualized processor is associated with each and every thread.

• Each process has its own code and data whereas the threads of processes share same code and data.

• Every process starts with a primary thread, but it can create additional threads if required.

• Context switching between processes is much slower than the context switching between threads of the same process.

• Threads can have a direct access to its data segments, but processes have their own copy of data segments.

• Processes have overheads but not threads.

Summary:

Process vs. Thread

Process and thread are two techniques used by programmers in order to control the processor and the execution of instructions on a computer in an efficient and effective manner. A process can contain several threads. Threads provide an efficient way to share memory although it operates multiple executions than processes. Therefore, threads are an alternative to multiple processes. With the growing trend towards multi-core processors, threads will become the most important tool in the world of programmers.

 

Images Courtesy:

  1. Example of mutithreading by Mattias.Campe (CC BY 2.0)