L-1.11: Process Vs Threads in Operating System
11:17

L-1.11: Process Vs Threads in Operating System

Gate Smashers

7 chapters7 takeaways13 key terms5 questions

Overview

This video explains the fundamental differences between processes and threads in operating systems, particularly within a multitasking environment. It clarifies that processes are heavy-weight tasks with independent memory, code, and data, created using system calls like 'fork'. Threads, on the other hand, are light-weight tasks within a process that share code and data but have their own stacks and registers. The video highlights how this distinction impacts system calls, resource sharing, context switching speed, and blocking behavior, emphasizing that threads offer efficiency but also introduce interdependencies.

How was this?

Save this permanently with flashcards, quizzes, and AI chat

Chapters

  • Operating systems often run multiple tasks concurrently (multitasking).
  • Processes are considered 'heavy-weight' tasks.
  • Threads are considered 'light-weight' tasks, existing within a process.
  • In a single-CPU system, multitasking is achieved through time-sharing or by using threads.
Understanding the basic distinction between processes and threads is crucial for comprehending how operating systems manage and execute multiple tasks efficiently.
A print server receiving multiple print requests from different clients illustrates a scenario where the same process (printing) needs to be executed multiple times, potentially benefiting from threads.
  • A process includes its own code, data, stack, and registers.
  • Creating a child process (e.g., using the 'fork' system call) results in a near-exact copy of the parent process.
  • Each child process has its own independent copy of data and code, leading to higher overhead.
  • The operating system treats each process, including child processes, as a distinct entity with a unique Process ID (PID).
Knowing how processes are created and structured helps explain why they consume more system resources and are isolated from each other.
The analogy of a CPU creating a 'clone' process with its own hands (registers) and memory (data) to perform a task illustrates the concept of process duplication.
  • Threads are created within an existing process and share the process's code and data.
  • Each thread has its own independent stack and registers for its execution context.
  • Thread creation is typically managed at the user or application level, not directly by the operating system kernel (for user-level threads).
  • Sharing resources like code and data makes threads much more efficient and faster to create than processes.
Understanding thread structure reveals why they are more efficient for tasks that require shared information and faster execution within a single application.
Instead of creating a whole clone (process), creating an 'extra hand' (thread) that uses the same body (process code/data) to help with a task illustrates how threads share resources.
  • Creating a new process requires a system call (like 'fork') and involves the operating system kernel.
  • Creating user-level threads does not typically involve the kernel; it's handled by the application itself.
  • Kernel involvement in process creation leads to higher overhead compared to user-level thread creation.
The difference in kernel involvement explains why process management is slower and more resource-intensive than thread management.
The 'fork' system call is explicitly mentioned as the mechanism for creating child processes, highlighting the kernel's role.
  • Processes have separate memory spaces for their code and data.
  • Threads within the same process share the same memory space for code and data.
  • This sharing of memory allows threads to communicate and access data more easily and quickly.
Resource sharing is a key factor determining the efficiency and communication capabilities between concurrent execution units.
Threads sharing the same 'data' and 'code' segments of a process, unlike separate copies made for child processes.
  • Context switching is the process of saving the state of one task and loading the state of another.
  • Context switching between processes is slower because the operating system must save and load more information (e.g., entire PCB).
  • Context switching between threads is faster because only registers and stack pointers need to be saved/loaded, as they share most resources.
  • This speed difference is a significant advantage of using threads for certain types of multitasking.
The efficiency of context switching directly impacts the overall performance and responsiveness of a multitasking system.
Saving the entire Process Control Block (PCB) for a process takes longer than just switching registers for threads.
  • If a process is blocked (e.g., waiting for I/O), other independent processes are not affected.
  • If one thread within a process is blocked (e.g., waiting for I/O), the entire process and all its other threads are also blocked.
  • This is because the kernel, unaware of individual threads, treats the entire block as a single process request.
  • Threads are interdependent due to shared resources, while processes are independent.
The blocking behavior highlights a critical difference in fault tolerance and execution flow between processes and threads.
A single thread requesting disk access causes the entire process (and all its threads) to halt, whereas a blocked process does not stop other unrelated processes.

Key takeaways

  1. 1Processes are independent units of execution with their own resources, while threads are lighter units sharing resources within a process.
  2. 2Creating processes involves the OS kernel and is resource-intensive; creating threads is typically user-level and more efficient.
  3. 3Threads offer faster context switching due to shared memory and fewer state components to save/load.
  4. 4Processes are isolated, meaning one process crashing doesn't affect others, but threads are interdependent.
  5. 5A blocked thread can block its entire parent process, a behavior not seen when one process blocks another.
  6. 6Threads are ideal for tasks within a single application that need to share data and perform concurrent operations efficiently.
  7. 7Processes are better suited for running separate applications or when strong isolation between tasks is required.

Key terms

ProcessThreadMultitaskingHeavy-weight taskLight-weight taskSystem CallForkKernelUser-level threadProcess Control Block (PCB)Context SwitchingBlockingShared Memory

Test your understanding

  1. 1What are the primary components that define a process, and how do these differ from what threads within that process possess?
  2. 2Why is creating a new process considered a 'heavy-weight' operation compared to creating a thread?
  3. 3How does the operating system's involvement (or lack thereof) in thread creation affect performance?
  4. 4Explain the impact of blocking on other concurrent tasks when dealing with processes versus threads.
  5. 5What is context switching, and why is it generally faster between threads than between processes?

Turn any lecture into study material

Paste a YouTube URL, PDF, or article. Get flashcards, quizzes, summaries, and AI chat — in seconds.

No credit card required

L-1.11: Process Vs Threads in Operating System | NoteTube | NoteTube