top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between process and thread?

+2 votes

Please explain in detail, I know the answer but may not be proper?

posted Dec 15, 2014 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
Best answer

A program in execution is called process. Now for example you have two program and you have compiled them say their binaries are called task1 and task2 now when you run them you see task1 and task2 in the ps list these are processes of binary task1 and task2. CPU keeps on doing context switching between processes based on need or based on time-slice (depend on OS config) where it backup Process Control Block(PCB) in a table and load the CPU with new PCB of another process. That's how multiprocessing was achieved, but remember context switch was a costly operation.

Now in the previous para we discussed that context switch was a costly operation so a new idea of switching to the same processes different area when process goes into block mode appeared so that we can save context switching between process and can improve the efficiency of processing and the concept of thread evolved. Now let me be bit theoretical - A thread is a path of execution within a process i.e. a process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process, when you open multiple files within the same context then you are essentially having multiple thread in the context of OS.

answer Dec 15, 2014 by Salil Agrawal
So.. Thread is been scheduled within a process...I mean Main process will only schedule Threads... Right?
Yes thread is part of process and scheduling happens within the process, and here thread context switch takes place which is lot lighter then pcb switch.
Ohk... Thanks Sir..
+2 votes

Each process runs in a separate address space in the CPU. But threads, on the other hand, may share address space with other threads within the same process. This sharing of space facilitates communication between them. Therefore, Switching between threads is much simpler and faster than switching between processes

Threads also have a great degree of control over other threads of the same process. Processes only have control over child processes.

Also, 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.

Considering the similarities, a thread can do anything that a process can do. They are both able to reproduce (Processes create child processes and threads create more threads), and they both have ID, base priority, execution time and exit status as attributes.

answer Dec 15, 2014 by Sridharan P
Small example:
To understand the actual differences between processes and threads, let us consider a real-life example. Suppose you are driving from city A to city B and you have had only three hours of sleep the night before after a terribly hectic day. Imagine yourself as the CPU and driving to city B as a process. While driving you may have to do a number of smaller tasks such as checking the map on the GPS, making sure that you don’t exceed speed limits, making sure you don’t fall asleep (trust me, it happens!), etc. These little tasks are actually threads of your process because collectively they serve to help in its execution. If any thread fails to execute properly, the entire process may be disrupted. (For instance, imagine what would happen if you actually fell asleep!)
Now let’s assume that there had been a storm the night before. After travelling some distance you see that a toppled over tree is blocking the road ahead. You cannot move any further unless the tree is removed. Therefore, your current process has to be stopped. Now you’ve got a brand new process in your hands- getting the tree out of the way.

So you gather people from a nearby village, which can be thought of as a thread to your new process, and shove the tree out of the way. Then you go back to your car and continue with your journey.
Thanks.. Sridharan P :)
Similar Questions
+5 votes

In the below figure through shared l2 cache what type of data (I mean is it global variables ?) is shared .

l2 cache

+1 vote

Please share your idea about Multiprocessing and Multithreading specially in context of python.

+2 votes

You are given two processes and each process is having four threads. One of the thread is having performance issue. How will you find out that thread which is having problem.

+2 votes

As we heard of terms like multi processor and multi core system

Both are same or some difference exist between them ??

+1 vote

I wrote a multi-threaded program using pthread library, but I want execution of threads in a specific order.
What I have to do ?