Difference between Process and Thread
In this article let’s review a very popular interview question: what is the difference between Thread and Process and the reason behind it.
What are Programs, Processes, and Threads?
To better understand, first let’s look at what are those.
Program
A program is a sequence of instructions that a computer can execute or interpret. A computer program in its human-readable form is called source code. Usually, the source code needs to be translated to machine instructions using its language’s compiler. The resulting file is called executable.
Alternatively, source code may execute within the language’s interpreter. Java compiles into an intermediate form which is then executed by a Java interpreter.
Process
While a program is a passive collection of instructions typically stored in a file on disk, a process is the execution of those instructions after being loaded from the disk into memory. A process is the instance of a computer program, a program in execution. Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.
Several processes may be associated with the same program, a process can create another process (child process).
Thread
A thread is the smallest unit of execution within a process. There can be multiple threads within a process.
So let’s do a quick recap.
A Program is an executable file containing a set of instructions and stored passively on a disk.