Threads and process, advantages and disadvantages in Operating systems

What are Threads?

One big process consists of one or multiple small threads. Threads are managed and scheduled separately by the scheduler. 

thread vs process

Figure: Threads

Difference between thread and process

Comparison BasisThreadProcess
WeightA thread is a lightweight.A Process is a heavy weight.
Context switchingThreads require less time for context switchingProcesses require more time for context switching/
Termination TimeThreads require less time for termination.Processes require more time for termination.
BlockedIf a user level thread gets blocked, all of its peer threads also get blocked.If a process gets blocked, remaining processes can continue execution.
Code and data sharingA thread shares the data segments, and files etc. with its peer threads.Processes have independent data and code segments.
Dependent or independentThreads are dependent on process.Individual processes are independent.
Memory SharingA thread may share some memory with its peer threads.Processes don’t share memory.
Resource ConsumptionThreads are Light weight so need less resources..Processes are Heavy weight so need more resources..
Creation TimeThreads require less time for creation.Processes require more time for creation.
CommunicationFasterSlower

Similarities of thread and process:

  • Both can share CPU
  • Both can create a child
  • If one block then other can run

Advantages of threads:

  • Reduce context switching.
  • Increase processing speed.
  • Don’t need for inter-process communication.

Frequently Asked Questions (FAQ)

What do two threads in the same process share?
Threads in the same process share memory and resources.
Do two system threads in the same process share the same call stack and heap space?
Each thread will have its own stack, but all the threads in a process will share the heap.
A process or program that divides itself into multiple threads is said to be……..?
Multi-threaded Process divides itself into multiple threads.
How many threads can a process contain?
The actual limit of having threads for a particular process is always determined by the amount of available memory. There is no special limit, but there are some limits for having the threads.  The logic is simple, When memory runs out, you can’t create more threads.

Find out how many threads a process has…?

We can view the threads of a process with Process Explorer.
Steps are very simple.
Step 1: Select a process
Step 2: open the process properties
Step 3: Click on the Threads tab. (Threads tab shows a list of the threads in the process and three columns of information are visible. For each thread it shows the following important information;
1. percentage of CPU consumed
2. The number of context switches to the thread
3. thread start address.

Can a process have multiple threads?

Yes, a process can have multiple threads.

How ps show threads of a process?
ps -eLf on the shell shall give you a list of all the threads and processes currently running on the system.

What is the linux number of threads limit per process?
Linux doesn’t have any limit on separate threads per process. However,a limit is in Linux on the total number of processes on the system.

Subscribe for Friendship

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]