Difference between Process and Thread

Key difference: Thread and Process are two closely related terms in multi-threading. The main difference between the two terms is that the threads are a part of a process, i.e. a process may contain one or more threads, but a thread cannot contain a process.

In programming, there are two basic units of execution: processes and threads. They both execute a series of instructions. Both are initiated by a program or the operating system. This article helps to differentiate between the two units.

A process is an instance of a program that is being executed. It contains the program code and its current activity. Depending on the operating system, a process may be made up of multiple threads of execution that execute instructions concurrently. A program is a collection of instructions; a process is the actual execution of those instructions.

A process has a self-contained execution environment. It has a complete set of private basic run-time resources; in particular, each process has its own memory space. Processes are often considered similar to other programs or applications. However, the running of a single application may in fact be a set of cooperating processes. To facilitate communication between the processes, most operating systems use Inter Process Communication (IPC) resources, such as pipes and sockets. The IPC resources can also be used for communication between processes on different systems. Most applications in a virtual machine run as a single process. However, it can create additional processes using a process builder object.

In computers, a thread can execute even the smallest sequence of programmed instructions that can be managed independently by an operating system. The applications of threads and processes differ from one operating system to another. However, the threads are made of and exist within a process; every process has at least one. Multiple threads can also exist in a process and share resources, which helps in efficient communication between threads.

On a single processor, multitasking takes place as the processor switches between different threads; it is known as multithreading. The switching happens so frequently that the threads or tasks are perceived to be running at the same time. Threads can truly be concurrent on a multiprocessor or multi-core system, with every processor or core executing the separate threads simultaneously.

In summary, threads may be considered lightweight processes, as they contain simple sets of instructions and can run within a larger process. Computers can run multiple threads and processes at the same time.

Comparison between Process and Thread:

 

Process

Thread

Definition

An executing instance of a program is called a process.

A thread is a subset of the process.

Process

It has its own copy of the data segment of the parent process.

It has direct access to the data segment of its process.

Communication

Processes must use inter-process communication to communicate with sibling processes.

Threads can directly communicate with other threads of its process.

Overheads

Processes have considerable overhead.

Threads have almost no overhead.

Creation

New processes require duplication of the parent process.

New threads are easily created.  

Control

Processes can only exercise control over child processes.

Threads can exercise considerable control over threads of the same process.

Changes

Any change in the parent process does not affect child processes.

Any change in the main thread may affect the behavior of the other threads of the process.

Memory

Run in separate memory spaces.

Run in shared memory spaces.

File descriptors

 

Most file descriptors are not shared.

It shares file descriptors.

File system

There is no sharing of file system context.

It shares file system context.

Signal

It does not share signal handling.

It shares signal handling.

Controlled by

Process is controlled by the operating system.

Threads are controlled by programmer in a program.

Dependence

Processes are independent.

Threads are dependent.

Image Courtesy: cs.jhu.edu, upload.wikimedia.org

Most Searched in Computers and Internets Most Searched Non-Alcoholic Drinks
Most Searched in Arts and Humanities Most Searched in Home and Garden
Parachuting vs Paragliding
Lipstick vs Lip Color
Quality Assurance vs Quality Control
Asus PadFone Infinity vs Galaxy Note II

Comments

please give the real time examples of thread and process.

full size is not showing

Good explanation

Difference is not clear

Add new comment

Plain text

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.