chapter
    Processes, Threads, System Calls and Context Switching PYQs for GATE CS

    Solve 9+ Processes, Threads, System Calls and Context Switching previous year questions for GATE CS with answers and detailed solutions. Free sample questions

    Try a question

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

    Question 1
    2026 Slot Set1 PYQ
    Consider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork() system call is always successful in creating a process.

    int main () {
       int i;
       for (i = 0; i < 3; i++){
          if (fork() == 0){
            continue;
          }
          break;
       }
       printf("Hello!");
       return 0;
    }

    The total number of times that the printf statement gets executed is ________. (answer in integer)
    Question 2
    2025 Slot Set1 PYQ
    Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into I/O queue whenever an I/O related operation is performed. Assume that there will always be a context switch whenever a process requests for an I/O, and also whenever the process returns from an I/O. The number of times the process will enter the ready queue during its lifetime (not counting the time the process enters the ready queue when it is run initially) is _______. (Answer in integer)

    int main()
    {
    int x=0,i=0;
    scanf("%d",&x);
    for(i=0; i<20; i++)
    {
    x = x+20;
    printf("%d\n",x);
    }
    return 0;
    }
    Question 3
    2024 Slot Set2 PYQ

    Consider a process P running on a CPU. Which one or more of the following events will always trigger a context switch by the OS that results in process P moving to a non-running state (e.g., ready, blocked)?

    Question 4
    2024 Slot Set1 PYQ

    Which of the following statements about threads is/are TRUE?

    Question 5
    2024 Slot Set1 PYQ
    Consider the following code snippet using the fork() and wait() system calls. Assume that the code compiles and runs correctly, and that the system calls run successfully without any errors.

    int x = 3;
    while(x > 0) {
        fork();
        printf("hello");
        wait(NULL);
        x--;
    }

    The total number of times the printf statement is executed is _________
    Question 6
    2024 Slot Set1 PYQ

    Which of the following process state transitions is/are NOT possible?

    Question 7
    2023 PYQ

    Which one or more of the following options guarantee that a computer system will transition from user mode to kernel mode?

    Question 8
    2023 PYQ

    Which one or more of the following need to be saved on a context switch from one thread (T1) of a process to another thread (T2) of the same process?

    Question 9
    2021 Slot Set1 PYQ

    Which of the following standard C library functions will <i>always</i> invoke a system call when executed from a single-threaded process in a UNIX/Linux operating system?

    Free preview ends here

    Login to view the complete previous-year questions and solutions

    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.

    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 PYQs for GATE CS

    Solve 9+ Processes, Threads, System Calls and Context Switching previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Processes, Threads, System Calls and Context Switching

    Chapter Journey: 4 Topics, One Clear Path

    This chapter builds your understanding of how the operating system manages execution. Here is what you will master:

    Topic 1: Process States, Ready Queues and Context Switching (Current)
    • Understand the lifecycle of a process: new, ready, running, blocked, terminated
    • Learn how the OS maintains ready queues and decides which process runs next
    • Master context switching: what gets saved, what gets loaded, and the overhead involved
    • Foundation for everything else in this chapter
    Topic 2: Threads and Thread Context
    • Threads as lightweight units of execution within a process
    • What threads share versus what they keep private
    • Thread context switching versus process context switching
    Topic 3: System Calls and User-Kernel Mode Transitions
    • The boundary between user mode and kernel mode
    • How programs request OS services through system calls
    • The mechanism of mode transition and its triggers
    Topic 4: Process Creation using Fork and Wait
    • The fork system call: creating child processes
    • Understanding parent-child relationships
    • The wait system call: synchronization between processes
    What You Will Achieve:

    By the end of this chapter, you will be able to trace process state transitions, calculate context switch overhead, distinguish between process and thread behavior, predict the number of processes created by fork loops, and identify which operations trigger user-to-kernel mode transitions.

    What is a Process? The Unit of Execution

    Process = Program in Execution

    A process is a program in execution. It is the fundamental unit of work in a modern operating system.

    Program versus Process

    AspectProgramProcess
    NaturePassive entityActive entity
    StorageStored on diskLoaded in memory
    AnalogyRecipe in a cookbookThe act of cooking
    LifetimePermanent fileTemporary execution

    What Makes Up a Process?

    A process in memory contains:

    1. Text section: The compiled program code
    2. Program counter: Points to the next instruction to execute
    3. Stack: Temporary data, function parameters, return addresses, local variables
    4. Data section: Global variables
    5. Heap: Dynamically allocated memory (grows during execution)

    Process Control Block (PCB)

    The operating system tracks each process using a Process Control Block (PCB). Think of it as the process identity card. It contains:

    • Process state: current state (new, ready, running, blocked, terminated)
    • Program counter: address of next instruction
    • CPU registers: contents of all registers when process was last running
    • CPU scheduling information: priority, pointers to scheduling queues
    • Memory management information: base and limit registers, page tables
    • Accounting information: CPU time used, time limits, process number
    • I/O status information: list of I/O devices allocated, open files

    The PCB is the key data structure that allows the operating system to support multiple processes simultaneously.

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

    Question 1 · Operating System · 2026_Set1 NAT
    Consider the following program snippet. Assume that the program compiles and runs successfully. Further, assume that the fork() system call is always successful in creating a process.

    int main () {
       int i;
       for (i = 0; i < 3; i++){
          if (fork() == 0){
            continue;
          }
          break;
       }
       printf("Hello!");
       return 0;
    }

    The total number of times that the printf statement gets executed is ________. (answer in integer)
    Question 2 · Operating System · 2025_Set1 NAT
    Suppose in a multiprogramming environment, the following C program segment is executed. A process goes into I/O queue whenever an I/O related operation is performed. Assume that there will always be a context switch whenever a process requests for an I/O, and also whenever the process returns from an I/O. The number of times the process will enter the ready queue during its lifetime (not counting the time the process enters the ready queue when it is run initially) is _______. (Answer in integer)

    int main()
    {
    int x=0,i=0;
    scanf("%d",&x);
    for(i=0; i<20; i++)
    {
    x = x+20;
    printf("%d\n",x);
    }
    return 0;
    }
    Question 3 · Operating System · 2024_Set2 MSQ

    Consider a process P running on a CPU. Which one or more of the following events will always trigger a context switch by the OS that results in process P moving to a non-running state (e.g., ready, blocked)?

    1. A.

      P makes a blocking system call to read a block of data from the disk

    2. B.

      P tries to access a page that is in the swap space, triggering a page fault

    3. C.

      An interrupt is raised by the disk to deliver data requested by some other process

    4. D.

      A timer interrupt is raised by the hardware

    Question 4 · Operating System · 2024_Set1 MSQ

    Which of the following statements about threads is/are TRUE?

    1. A.

      Threads can only be implemented in kernel space

    2. B.

      Each thread has its own file descriptor table for open files

    3. C.

      All the threads belonging to a process share a common stack

    4. D.

      Threads belonging to a process are by default not protected from each other

    Question 5 · Operating System · 2024_Set1 NAT
    Consider the following code snippet using the fork() and wait() system calls. Assume that the code compiles and runs correctly, and that the system calls run successfully without any errors.

    int x = 3;
    while(x > 0) {
        fork();
        printf("hello");
        wait(NULL);
        x--;
    }

    The total number of times the printf statement is executed is _________
    Question 6 · Operating System · 2024_Set1 MSQ

    Which of the following process state transitions is/are NOT possible?

    1. A.

      Running to Ready

    2. B.

      Waiting to Running

    3. C.

      Ready to Waiting

    4. D.

      Running to Terminated

    Question 7 · Operating System · 2023 MSQ

    Which one or more of the following options guarantee that a computer system will transition from user mode to kernel mode?

    1. A.

      Function Call

    2. B.

      malloc Call

    3. C.

      Page Fault

    4. D.

      System Call

    Question 8 · Operating System · 2023 MSQ

    Which one or more of the following need to be saved on a context switch from one thread (T1) of a process to another thread (T2) of the same process?

    1. A.

      Page table base register

    2. B.

      Stack pointer

    3. C.

      Program counter

    4. D.

      General purpose registers

    Question 9 · Operating System · 2021_Set1 MSQ

    Which of the following standard C library functions will <i>always</i> invoke a system call when executed from a single-threaded process in a UNIX/Linux operating system?

    1. A.

      exit

    2. B.

      malloc

    3. C.

      sleep

    4. D.

      strlen

    More previous year questions (pyqs) in this unit