Differences between processes and threads in operating systems
Process is a series of actions or steps taken to achieve an end. And the thread is a single sequence stream within in a process.
A
process is a program in execution of an application, whereas a thread is a path
of execution within a process. For example, when we double-click the Microsoft
Word icon, we start a process that runs Word and begins executing the primary
thread of that process.
A process can
contain multiple threads.
Processes are generally used to execute large or
‘heavyweight’ tasks such as running different applications, while threads are
used to carry out much smaller or ‘lightweight’ tasks such as spelling
checking, auto capitalization or saving a document, etc in a program.
Threads are considered
lightweight because they use far less resources than processes.
Each process has its own address space, but the threads
within the same process share that address space. Therefore, Switching between
threads is much simpler and faster than switching between processes
Processes are independent of each other. Threads, since they
share the same address space are interdependent in a process.
Threads are easier to create than processes since they don't
require a separate address space.
Threads also have a great degree of control over other
threads of the same process. Processes only have control over child processes.
Any changes made to the main thread may affect the behavior
of other threads within the same process. However, changes made to the parent
processes do not affect the child processes.
Similarities between process and thread
·
A
thread can do anything that a process can do.
·
They
both have ID- Process has a process ID same way thread has a thread ID.
·
They
are both able to reproduce - Processes create child processes and threads
create more threads.
·
We
can create a process within a process same way we can create thread within a
thread
·
Both
process and thread has priorities.
To understand the differences
between processes and threads, let us consider someone is making a cake which
is a process. And for making a cake he or she need to collect ingredients, have
to make dough, put in the oven for baking, preparing the cream for coating,
decorate the cake, etc. These little tasks are actually threads of his or her
process to make a cake.
Let
us consider another example. Suppose
someone is traveling to abroad. To go from one country to another he or she
needs to process visa, collect ticket, make the luggage, arrive at airport, etc.
All these small tasks are threads for making the process for traveling to abroad.