Bird
Raised Fist0
Interview Prepoperating-systemseasyAmazonMicrosoftInfosysTCS

Process vs Thread - Key Differences

Choose your preparation mode3 modes available
▶
Steps
setup

Initialize Process A

Process A is created and added to the ready queue. It has its own memory space and resources allocated.

💡 This step sets up the first process, showing that processes are independent execution units with separate resources.
Line:processA = create_process('A') # STEP 1
💡 Processes are distinct entities with their own state and resources.
📊
Process vs Thread - Key Differences - Watch the Algorithm Execute, Step by Step
Watching this step-by-step helps you understand the fundamental distinctions between processes and threads beyond theoretical definitions.
Step 1/13
·Active fill★Answer cell
Transition new → ready pid:A - Process A created and ready to run
A
ready
burst: 10
Ready Queue
A
Waiting Queue
empty
🖥CPUidlet=0
Transition ready → running pid:A - Scheduler dispatched Process A to CPU
A
running
burst: 10
Ready Queue
empty
Waiting Queue
empty
🖥CPUAt=0
Transition new → ready pid:A.T1 - Thread T1 created and ready
A
running
burst: 10
A.T1
ready
burst: 5
Ready Queue
A.T1
Waiting Queue
empty
🖥CPUAt=0
Transition running → running pid:A - Process A executed 1 time unit
A
running
burst: 9
A.T1
ready
burst: 5
Ready Queue
A.T1
Waiting Queue
empty
🖥CPUAt=1
A
Transition ready → running pid:A.T1 - Thread T1 dispatched to CPU
A
ready
burst: 9
A.T1
running
burst: 5
Ready Queue
A
Waiting Queue
empty
🖥CPUA.T1t=1
A
Transition running → running pid:A.T1 - Thread T1 executed 1 time unit
A
ready
burst: 9
A.T1
running
burst: 4
Ready Queue
A
Waiting Queue
empty
🖥CPUA.T1t=2
A
A.T1
Transition new → ready pid:B - Process B created and ready
A
ready
burst: 9
A.T1
running
burst: 4
B
ready
burst: 8
Ready Queue
AB
Waiting Queue
empty
🖥CPUA.T1t=2
A
A.T1
Transition running → terminated pid:A.T1 - Thread T1 completed execution
A
ready
burst: 9
B
ready
burst: 8
Ready Queue
AB
Waiting Queue
empty
🖥CPUidlet=3
A
A.T1
Transition ready → running pid:B - Process B dispatched to CPU
A
ready
burst: 9
B
running
burst: 8
Ready Queue
A
Waiting Queue
empty
🖥CPUBt=3
A
A.T1
Transition running → running pid:B - Process B executed 1 time unit
A
ready
burst: 9
B
running
burst: 7
Ready Queue
A
Waiting Queue
empty
🖥CPUBt=4
A
A.T1
B
Transition ready → running pid:A - Process A dispatched to CPU
A
running
burst: 9
B
ready
burst: 7
Ready Queue
B
Waiting Queue
empty
🖥CPUAt=4
A
A.T1
B
Transition running → terminated pid:A - Process A completed execution and terminated
B
ready
burst: 7
Ready Queue
B
Waiting Queue
empty
🖥CPUidlet=5
A
A.T1
B
A
Transition running → terminated pid:B - Process B completed execution and terminated
Ready Queue
empty
Waiting Queue
empty
🖥CPUidlet=13
A
A.T1
B
A
B

Key Takeaways

✓ Processes have independent memory and resources, while threads share the process's resources but have separate execution contexts.

This difference is often abstract in code but becomes clear when watching resource allocation and scheduling side-by-side.

✓ Threads are scheduled independently but run within the context of their parent process, allowing lightweight concurrency.

Seeing threads enter ready and running states within the same process clarifies how they differ from full processes.

✓ CPU scheduling switches between processes and threads, demonstrating context switching and resource sharing in action.

Visualizing scheduling decisions helps understand how the OS manages multitasking and resource allocation.

Practice

(1/5)
1. Trace the sequence of page faults when using the FIFO algorithm with 3 frames for the reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. How many page faults occur?
easy
A. 8
B. 9
C. 10
D. 7

Solution

  1. Step 1: Initialize FIFO with empty frames

    Frames: []
  2. Step 2: Process each page in order

    1 -> fault, frames: [1]
    2 -> fault, frames: [1,2]
    3 -> fault, frames: [1,2,3]
    4 -> fault, evict 1, frames: [4,2,3]
    1 -> fault, evict 2, frames: [4,1,3]
    2 -> fault, evict 3, frames: [4,1,2]
    5 -> fault, evict 4, frames: [5,1,2]
    1 -> hit
    2 -> hit
    3 -> fault, evict 1, frames: [5,3,2]
    4 -> fault, evict 2, frames: [5,3,4]
    5 -> hit
  3. Step 3: Count faults

    Total faults = 9
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    FIFO evicts oldest page regardless of future use, causing 9 faults here.
Hint: FIFO faults count equals number of unique pages plus evictions [OK]
Common Mistakes:
  • Counting hits as faults
  • Misordering evictions in FIFO
  • Forgetting to update frames after eviction
2. Why does increasing the frequency of context switches beyond a certain point degrade overall system performance?
medium
A. Because saving and restoring CPU registers is a costly operation that consumes CPU cycles
B. Because the scheduler runs out of processes to schedule
C. Because the MMU has to reload page tables more frequently
D. Because the CPU cache is flushed automatically on every context switch

Solution

  1. Step 1: Identify overhead of context switch

    Saving/restoring CPU registers and PCB updates consume CPU time, causing overhead.
  2. Step 2: Scheduler availability

    The scheduler can always select processes; running out is not a cause of performance degradation.
  3. Step 3: MMU and page tables

    MMU page table reloads happen on address space switches, but not necessarily on every context switch.
  4. Step 4: CPU cache behavior

    CPU cache is not flushed automatically on every context switch; cache invalidation is more complex.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Context switch overhead is mainly CPU cycles spent saving/restoring registers.
Hint: More switches -> more register save/restore overhead -> slower system [OK]
Common Mistakes:
  • Believing scheduler runs out of processes
  • Assuming MMU reloads page tables every switch
  • Thinking CPU cache flushes on every context switch
3. Which of the following statements about the convoy effect in FCFS scheduling is INCORRECT?
medium
A. The convoy effect occurs when a long process delays all subsequent shorter processes
B. The convoy effect can be mitigated by introducing preemption in the scheduling algorithm
C. The convoy effect causes the average waiting time to always be minimal in FCFS
D. The convoy effect leads to poor CPU utilization and increased waiting times

Solution

  1. Step 1: Analyze each statement

    A is correct; long processes delaying short ones is the convoy effect.
    B is correct; preemption can reduce the convoy effect.
    C is incorrect; the convoy effect increases average waiting time, not minimizes it.
    D is correct; convoy effect can cause poor CPU utilization and longer waits.
  2. Step 2: Identify the incorrect statement

    Only The convoy effect causes the average waiting time to always be minimal in FCFS falsely claims minimal average waiting time due to the convoy effect.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Convoy effect worsens waiting time, not improves it.
Hint: Convoy effect -> longer waits, not shorter
Common Mistakes:
  • Assuming convoy effect improves waiting time
  • Ignoring preemption as a mitigation
  • Misunderstanding convoy effect impact on CPU utilization
4. If a system using FCFS scheduling introduces a mix of I/O-bound and CPU-bound processes arriving at different times, how does this affect the convoy effect and waiting times, and what strategy could reduce the negative impact?
hard
A. The convoy effect disappears because I/O-bound processes run first, so waiting times decrease automatically
B. The convoy effect worsens as CPU-bound processes block I/O-bound ones, increasing waiting times; introducing preemption can help
C. Waiting times remain unchanged because FCFS ignores process type and arrival time
D. The convoy effect is irrelevant in mixed workloads since I/O-bound processes do not use the CPU

Solution

  1. Step 1: Understand process types in FCFS

    FCFS schedules strictly by arrival order, regardless of process type.
  2. Step 2: Analyze impact of mixed workloads

    CPU-bound processes arriving first can delay I/O-bound processes, worsening the convoy effect and increasing waiting times.
  3. Step 3: Mitigation strategy

    Introducing preemption or priority scheduling can reduce waiting times for I/O-bound processes by allowing them to run sooner.
  4. Step 4: Evaluate options

    A is incorrect; convoy effect does not disappear automatically.
    B is correct; convoy effect worsens and preemption helps.
    C is incorrect; waiting times do change due to process mix.
    D is incorrect; convoy effect is relevant because all processes compete for CPU.
  5. Final Answer:

    Option B -> Option B
  6. Quick Check:

    Mixed workloads worsen convoy effect; preemption mitigates it.
Hint: Mixed CPU/I-O bound + FCFS -> worse convoy; preemption helps
Common Mistakes:
  • Assuming I/O-bound processes run first automatically
  • Believing waiting times don't change with process mix
  • Ignoring convoy effect in mixed workloads
5. If a system uses preemptive SJF scheduling but the burst times of processes are not known in advance and must be estimated, which challenge is most likely to affect scheduling accuracy?
hard
A. Incorrect burst time estimates can cause frequent unnecessary preemptions
B. The scheduler will always pick the wrong process due to estimation errors
C. Non-preemptive scheduling must be used instead to avoid errors
D. Starvation is eliminated because estimates prevent preemption

Solution

  1. Step 1: Understand burst time estimation impact

    Estimations can be inaccurate, causing the scheduler to preempt based on wrong assumptions.
  2. Step 2: Analyze consequences

    Frequent unnecessary preemptions increase overhead and reduce efficiency.
  3. Step 3: Why other options are incorrect

    B: Scheduler won't always pick wrong process; estimates can be close.
    C: Non-preemptive scheduling is a design choice, not forced by estimation.
    D: Starvation is not eliminated by estimates; it depends on scheduling policy.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Estimation errors cause scheduling inefficiency via unnecessary preemptions.
Hint: Bad burst time estimates cause too many preemptions in preemptive SJF [OK]
Common Mistakes:
  • Assuming estimates always cause wrong scheduling
  • Believing estimation removes starvation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard