chapter

    Processes, Threads, System Calls and Context Switching Short Notes for Gate Cs

    Processes, Threads, System Calls and Context Switching short notes for GATE CS: 5 study cards covering concepts, formulas, shortcuts and exam traps, plus solv

    Processes Threads System Calls and Context Switching short notes

    State Transition Cheat Sheet: Quick Reference

    Process States and Context Switching: Quick Reference

    Five States

    1. New: Being created
    2. Ready: Waiting for CPU
    3. Running: Executing instructions
    4. Blocked: Waiting for event (I/O, signal, resource)
    5. Terminated: Finished execution

    Allowed Transitions (6 total)

            New -> Ready (admit)
            Ready -> Running (dispatch)
            Running -> Ready (preempt)
            Running -> Blocked (wait)
            Running -> Terminated (exit)
            Blocked -> Ready (wake up)
          

    Impossible Transitions (The Big 3)

    • Blocked -> Running: must go through Ready
    • Blocked -> Terminated: must wake up first
    • Ready -> Blocked: must be Running to block

    Context Switch Triggers (Always)

    • Timer interrupt (preemption)
    • I/O request (blocking)
    • Wait for event (blocking)
    • Higher priority process ready (preemption)
    • Process termination (exit)

    Ready Queue Entry Counting

    Formula: Ready entries = Number of I/O operations (+ 1 if initial entry counted)

    I/O operations include: scanf, printf, fread, fwrite, fopen, close, etc.

    Key Distinctions

    • Ready versus Blocked: Ready = waiting for CPU (eligible to run). Blocked = waiting for event (NOT eligible to run).
    • Mode Switch versus Context Switch: Mode switch = User <-> Kernel (same process). Context switch = Process A <-> Process B (different processes).
    Memory Hooks:
    Five states: "Never Rush Really Big Tasks" (New, Ready, Running, Blocked, Terminated)
    Impossible transitions: "Blocked cannot Run, Blocked cannot Terminate, Ready cannot Block"
    Context switch: "Save state, load state, pure waste"

    Final Exam Checklist: Process States and Context Switching

    Final Exam Checklist

    Can You...?

    • Draw the Five-State Model: New, Ready, Running, Blocked, Terminated. All six allowed transitions. Three impossible transitions marked.

    Threads: Final Checklist

    Final Checklist

    Core Facts

    • Shared: Code, Data, Heap, Files
    • Private: PC, Registers, Stack, Thread ID

    Context Switch

    Save/Restore: PC, Registers, Stack. Do NOT touch: Page Table.

    Models

    Many-to-One (fast, fragile), One-to-One (parallel, heavy), Many-to-Many (balanced).

    One-line exam method: For any thread option, ask: per-thread or per-process, and does this cross into the kernel?

    2 more cards in this chapter

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    Level 1: Warm-up

    In the standard five-state process model, a process is currently in the 'Running' state. How many distinct valid state transitions are possible directly from the 'Running' state?

    Question 2
    Level 1: Warm-up

    Which of the following process state transitions is/are strictly IMPOSSIBLE in the standard five-state process model, ignoring any non-standard OS optimizations?

    Question 3
    Level 1: Warm-up

    Consider three scenarios starting with a single initial process. Which of the following statements regarding the total number of processes (parent + children) existing after the operations complete is/are TRUE?

    (1) The process executes fork() exactly once.

    (2) The process executes fork() sequentially exactly twice.

    (3) The process executes fork() sequentially exactly three times.

    Question 4
    Level 1: Warm-up

    Consider a program that starts with a single initial process. It executes a loop that calls the fork() system call exactly times sequentially, with no conditional breaks or wait() calls. Assuming all fork() calls are successful, if the total number of child processes created is 31, what is the value of ?

    Question 5
    Level 1: Warm-up

    In a single-CPU system with no I/O devices, what is the maximum number of processes that can be simultaneously in the 'Running' state?

    Question 6
    Level 1: Warm-up

    Assertion (A): Context switching is considered pure overhead in an operating system.

    Reason (R): During a context switch, the CPU executes instructions that do not advance the execution of any user process.

    Question 7
    Level 1: Warm-up

    Consider a process that starts execution, performs 3 scanf operations, 2 printf operations, and 1 fopen operation before terminating normally. Assuming the process enters the ready queue initially and after every I/O operation completion, how many times does this process enter the ready queue during its entire lifetime?

    Question 8
    Level 1: Warm-up

    Which of the following events will ALWAYS trigger a context switch that results in the currently running process moving to a non-running state?

    Question 9
    Level 1: Warm-up

    In a multithreaded process, which of the following resources is strictly private to each individual thread and is NOT shared among threads of the same process?

    Question 10
    Level 1: Warm-up

    During a context switch between two threads of the SAME process, which of the following components is saved and restored by the operating system?

    Free preview ends here

    Login to view the complete short notes

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Processes, Threads, System Calls and Context Switching Short Notes for GATE CS

    Processes, Threads, System Calls and Context Switching short notes for GATE CS: 5 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.

    State Transition Cheat Sheet: Quick Reference

    Process States and Context Switching: Quick Reference

    Five States

    1. New: Being created
    2. Ready: Waiting for CPU
    3. Running: Executing instructions
    4. Blocked: Waiting for event (I/O, signal, resource)
    5. Terminated: Finished execution

    Allowed Transitions (6 total)

            New -> Ready (admit)
            Ready -> Running (dispatch)
            Running -> Ready (preempt)
            Running -> Blocked (wait)
            Running -> Terminated (exit)
            Blocked -> Ready (wake up)
          

    Impossible Transitions (The Big 3)

    • Blocked -> Running: must go through Ready
    • Blocked -> Terminated: must wake up first
    • Ready -> Blocked: must be Running to block

    Context Switch Triggers (Always)

    • Timer interrupt (preemption)
    • I/O request (blocking)
    • Wait for event (blocking)
    • Higher priority process ready (preemption)
    • Process termination (exit)

    Ready Queue Entry Counting

    Formula: Ready entries = Number of I/O operations (+ 1 if initial entry counted)

    I/O operations include: scanf, printf, fread, fwrite, fopen, close, etc.

    Key Distinctions

    • Ready versus Blocked: Ready = waiting for CPU (eligible to run). Blocked = waiting for event (NOT eligible to run).
    • Mode Switch versus Context Switch: Mode switch = User <-> Kernel (same process). Context switch = Process A <-> Process B (different processes).
    Memory Hooks:
    Five states: "Never Rush Really Big Tasks" (New, Ready, Running, Blocked, Terminated)
    Impossible transitions: "Blocked cannot Run, Blocked cannot Terminate, Ready cannot Block"
    Context switch: "Save state, load state, pure waste"

    Final Exam Checklist: Process States and Context Switching

    Final Exam Checklist

    Can You...?

    • Draw the Five-State Model: New, Ready, Running, Blocked, Terminated. All six allowed transitions. Three impossible transitions marked.

    Threads: Final Checklist

    Final Checklist

    Core Facts

    • Shared: Code, Data, Heap, Files
    • Private: PC, Registers, Stack, Thread ID

    Context Switch

    Save/Restore: PC, Registers, Stack. Do NOT touch: Page Table.

    Models

    Many-to-One (fast, fragile), One-to-One (parallel, heavy), Many-to-Many (balanced).

    One-line exam method: For any thread option, ask: per-thread or per-process, and does this cross into the kernel?

    System Calls: Final Checklist

    System Calls: Final Checklist

    Core Facts

    • System Call: Synchronous, software-initiated request.
    • Mode Bit: $0$ = Kernel, $1$ = User.
    • Transition: Trap instruction $\rightarrow$ mode bit flips $\rightarrow$ jump to vector.

    Critical Distinctions

    • Procedure Call: User $\rightarrow$ User (No mode change).
    • System Call: User $\rightarrow$ Kernel (Synchronous).
    • Interrupt: Hardware $\rightarrow$ Kernel (Asynchronous).

    C Library Rules

    Never: strlen, abs.
    Conditional: printf, malloc.
    Always: open, read, fork, exit.

    One-Line Exam Method: To determine if an event guarantees a transition, ask: Does this absolutely require privileged hardware access or OS intervention?

    Processes, Threads, System Calls and Context Switching: Solved Questions with Step-by-Step Explanations (10 Problems)

    Question 1 · Operating System NAT

    In the standard five-state process model, a process is currently in the 'Running' state. How many distinct valid state transitions are possible directly from the 'Running' state?

    Correct Answer:

    3.00

    Step-by-Step Solution

    Key idea: This is a state transition diagram recall question, recognizable because it asks for valid moves from a specific state.

    Step 1: Identify the current state: Running.

    Step 2: List all valid outgoing transitions from the Running state:

    • Running Ready (due to preemption or time quantum expiry)
    • Running Blocked (due to I/O request or waiting for an event)
    • Running Terminated (due to process completion or exit)

    Step 3: Count the valid transitions. There are exactly 3.

    Answer: 3.00

    Question 2 · Operating System MSQ

    Which of the following process state transitions is/are strictly IMPOSSIBLE in the standard five-state process model, ignoring any non-standard OS optimizations?

    1. A.

      New to Ready

    2. B.

      Ready to Blocked

    3. C.

      Blocked to Running

    4. D.

      Blocked to Terminated

    Correct Answer:

    ["B","C","D"]

    Step-by-Step Solution

    Insight: The standard five-state model has strict rules: only Running processes can block or terminate, and Blocked processes must wake up to Ready first.

    Exam route: Evaluate each transition. New Ready is allowed. Ready Blocked is impossible (must be Running). Blocked Running is impossible (must go through Ready). Blocked Terminated is impossible (must wake up first).

    Learning route: The OS enforces state boundaries. A process in the Ready state is waiting for the CPU, so it cannot block (it is not executing anything to request I/O). A process in the Blocked state is waiting for an event; it cannot run or terminate until that event occurs and the OS moves it to the Ready queue. Thus, B, C, and D are impossible.

    Wrong path: Assuming a process can terminate directly from Blocked (ignoring the constraint that it must be cleaned up after running or being explicitly killed from Ready/Running), leading to missing D.

    Question 3 · Operating System MSQ

    Consider three scenarios starting with a single initial process. Which of the following statements regarding the total number of processes (parent + children) existing after the operations complete is/are TRUE?

    (1) The process executes fork() exactly once.

    (2) The process executes fork() sequentially exactly twice.

    (3) The process executes fork() sequentially exactly three times.

    1. A.

      The total number of processes in Scenario (1) is strictly less than in Scenario (2).

    2. B.

      The total number of processes in Scenario (2) is strictly less than in Scenario (3).

    3. C.

      The total number of processes in Scenario (1) is greater than in Scenario (2).

    4. D.

      The total number of processes in Scenario (3) is exactly 6.

    Correct Answer:

    ["A","B"]

    Step-by-Step Solution

    Key idea: Each sequential fork() call doubles the total number of processes. The formula for sequential forks is total processes.

    Step 1: Calculate total processes for Scenario (1). , so total processes = .

    Step 2: Calculate total processes for Scenario (2). , so total processes = .

    Step 3: Calculate total processes for Scenario (3). , so total processes = .

    Step 4: Evaluate Option A. Is ? Yes. (True)

    Step 5: Evaluate Option B. Is ? Yes. (True)

    Step 6: Evaluate Option C. Is ? No. (False)

    Step 7: Evaluate Option D. Is the total for Scenario (3) equal to 6? No, it is 8. The value 6 comes from the incorrect linear formula . (False)

    Answer: Options A and B are true.

    Question 4 · Operating System NAT

    Consider a program that starts with a single initial process. It executes a loop that calls the fork() system call exactly times sequentially, with no conditional breaks or wait() calls. Assuming all fork() calls are successful, if the total number of child processes created is 31, what is the value of ?

    Correct Answer:

    5.00

    Step-by-Step Solution

    Key idea: Use the exponential formula for sequential fork() calls to relate the number of calls to the total number of processes.

    Step 1: Recall the formula for sequential fork() calls starting from 1 process.

    Step 2: Total processes = .

    Step 3: Total child processes = Total processes Initial process = .

    Step 4: Set up the equation based on the given value: .

    Step 5: Solve for : .

    Step 6: Solve for : Since , .

    Answer: 5.00

    Question 5 · Operating System MCQ

    In a single-CPU system with no I/O devices, what is the maximum number of processes that can be simultaneously in the 'Running' state?

    1. A.

      0

    2. B.

      1

    3. C.

      2

    4. D.

      Depends on the scheduling algorithm

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This tests the fundamental constraint of the 'Running' state in the five-state process model.

    Step 1: Recall the definition of the 'Running' state: instructions are being executed.

    Step 2: A single-CPU system has exactly one processing unit.

    Step 3: Therefore, only ONE process can be actively executing instructions on that single CPU at any given instant.

    Answer: B

    Question 6 · Operating System MCQ

    Assertion (A): Context switching is considered pure overhead in an operating system.

    Reason (R): During a context switch, the CPU executes instructions that do not advance the execution of any user process.

    1. A.

      Both A and R are true, and R is the correct explanation of A.

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A.

    3. C.

      A is true, but R is false.

    4. D.

      A is false, but R is true.

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This tests the conceptual understanding of context switching and its impact on system performance.

    Step 1: Evaluate Assertion (A): Context switching involves saving and loading state, which consumes CPU cycles without doing useful work for the user. Thus, it is pure overhead. (True)

    Step 2: Evaluate Reason (R): During this save/load phase, the CPU is executing OS kernel instructions, not the instructions of any user process. (True)

    Step 3: Check the link: R directly explains why A is true. The lack of progress for user processes is the very definition of this overhead.

    Answer: A

    Question 7 · Operating System MCQ

    Consider a process that starts execution, performs 3 scanf operations, 2 printf operations, and 1 fopen operation before terminating normally. Assuming the process enters the ready queue initially and after every I/O operation completion, how many times does this process enter the ready queue during its entire lifetime?

    1. A.

      5

    2. B.

      6

    3. C.

      7

    4. D.

      8

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This tests the formula for counting ready queue entries based on I/O operations.

    Step 1: Identify the initial entry: The process enters the ready queue once when it is first created/admitted. (Count = 1)

    Step 2: Identify all I/O operations: 3 (scanf) + 2 (printf) + 1 (fopen) = 6 I/O operations.

    Step 3: Each I/O operation completion causes the process to re-enter the ready queue. (Count = 6)

    Step 4: Total ready queue entries = Initial entry + I/O completions = 1 + 6 = 7.

    Answer: C

    Question 8 · Operating System MCQ

    Which of the following events will ALWAYS trigger a context switch that results in the currently running process moving to a non-running state?

    1. A.

      The process executes a simple arithmetic instruction

    2. B.

      A timer interrupt occurs

    3. C.

      The process allocates memory from the heap

    4. D.

      The process reads a variable from its own stack

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This tests the specific events that force the OS to perform a context switch.

    Step 1: Evaluate option A: Executing an arithmetic instruction is a normal user-mode action and does not trap to the OS. (False)

    Step 2: Evaluate option B: A timer interrupt forces the OS to regain control and evaluate if the current process should be preempted, always triggering a context switch or preemption check. (True)

    Step 3: Evaluate option C: Heap allocation is typically handled in user space and does not "always" trigger a switch. (False)

    Step 4: Evaluate option D: Reading from the stack is a standard user-mode instruction. (False)

    Answer: B

    Question 9 · Operating System MCQ

    In a multithreaded process, which of the following resources is strictly private to each individual thread and is NOT shared among threads of the same process?

    1. A.

      Heap memory

    2. B.

      Open file descriptors

    3. C.

      Program counter and stack

    4. D.

      Global variables

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This tests the distinction between shared process resources and private thread state.

    Step 1: Recall that threads within the same process share the process's address space and resources.

    Step 2: Identify the shared resources: Heap memory, open file descriptors, and global variables (data segment) are all shared.

    Step 3: Identify the private resources: Each thread must maintain its own independent execution state, which includes its own Program Counter (PC), CPU registers, and Stack.

    Answer: C

    Question 10 · Operating System MCQ

    During a context switch between two threads of the SAME process, which of the following components is saved and restored by the operating system?

    1. A.

      Page table base register

    2. B.

      Heap memory segment

    3. C.

      Program counter

    4. D.

      Open file descriptor table

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: During a thread context switch, only the private state of the thread is saved. Shared process resources are untouched.

    Step 1: Identify the components listed.

    Step 2: Classify each as private (PC, registers, stack) or shared (page table, heap, open files).

    Step 3: Select the private component.

    Answer: Program counter

    More short notes in this unit