Skip to content

Process and Threads

  • A process is a program in execution.
  • A thread is a lightweight process.
  • We achieve parallelism in OS by dividing a process into multiple threads.

Similarity between Threads and Processes –

  • Only one thread or process is active at a time
  • Within process both execute sequential
  • Both can create children

Differences between Threads and Processes –

  • Threads are not independent, processes are.
  • Threads are designed to assist each other, processes may or may not do it

Advantages of Thread over Process

  1. Responsiveness

  2. If the process is divided into multiple threads, if one thread completes its execution, then its output can be immediately returned.

  3. Faster context switch

  4. Context switch time between threads is lower compared to process context switch.

  5. Process context switching requires more overhead from the CPU.

  6. Effective utilization of multiprocessor system

  7. If we have multiple threads in a single process, then we can schedule multiple threads on multiple processor.

  8. This will make process execution faster.

  9. Resource sharing

  10. Resources like code, data, and files can be shared among all threads within a process. Note: stack and registers can’t be shared among the threads.

  11. Each thread has its own stack and registers.

  12. Communication

  13. Communication between multiple threads is easier, as the threads shares common address space.

  14. While in process we have to follow some specific communication technique for communication between two process.

  15. Enhanced throughput of the system

  16. If a process is divided into multiple threads, and each thread function is considered as one job, then the number of jobs completed per unit of time is increased, thus increasing the throughput of the system.

Types of Threads:

  1. User Level thread (ULT)

  2. User threads are implemented by users.

  3. Operating System doesn’t recognize user level threads.
  4. Context switch time is less.
  5. If one user level thread performs blocking operation then entire process will be blocked.
  6. Multithreaded applications on user-level threads cannot benefit from multiprocessing.

  7. Kernel Level Thread (KLT)

  8. Kernel threads are implemented by Operating System (OS).

  9. Kernel threads are recognized by Operating System.
  10. Context switch time is more.
  11. If one kernel thread perform blocking operation then another thread can continue execution.
  12. Transferring control within a process from one thread to another necessitates a mode switch to kernel mode.