Medium ●●

🧵 Processes, Threads & System Calls

Why it matters: The base vocabulary of the subject, plus a reliable fork() question: count the processes or the prints.

Subtopics

Each subtopic has its own page: idea, why, how, example, play, check. Mark each one understood when it clicks. 0 of 4 done.

Formulas

Processes after n sequential forks
2ⁿ in total, 2ⁿ − 1 new children
Fork in a loop (for i in 1..n)
2ⁿ processes (every process, including children, keeps looping)
fork() return value
0 in the child, child pid in the parent, −1 on failure
Context-switch overhead
efficiency = quantum / (quantum + switch time)

What GATE asks from this

Question types seen repeatedly in past papers. More stars means more frequent.

★★★
How many processes / times is something printed after these forks
Draw the tree. Remember that a child inherits the loop counter value at the time of the fork.
★★★
Which operations need kernel mode / which are privileged
I/O instructions, halt, setting the timer and changing the mode bit are privileged; reading the clock may not be.
★★★
Thread versus process properties
What is shared (address space, files) and what is private (stack, registers).
★★★
Which transitions are possible in the state diagram
Waiting → Running and Ready → Waiting do not exist.

Ratings are approximate, based on recurring patterns in past GATE CSE papers.

Previous year questions

15 real questions from the official GATE CSE papers (2012 to 2025), newest first, each with the official answer key and a worked solution. Questions are the property of the GATE organising institutes; this copy is for your personal study.

15 questions · 0 correct of 0 attempted · marks 0 / 16

Year:
GATE 2025 CS1 · Q11MCQ1 mark
Suppose a program is running on a non-pipelined single processor computer system. The computer is connected to an external device that can interrupt the processor asynchronously. The processor needs to execute the interrupt service routine (ISR) to serve this interrupt. The following steps (not necessarily in order) are taken by the processor when the interrupt arrives: (i) The processor saves the content of the program counter. (ii) The program counter is loaded with the start address of the ISR. (iii) The processor finishes the present instruction. Which ONE of the following is the CORRECT sequence of steps?
GATE 2025 CS1 · Q29NAT1 mark
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 ______.
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;
}
GATE 2024 CS1 · Q24MSQ1 mark
Which of the following statements about threads is/are TRUE?

One or more options may be correct. Select all that apply, then submit.

GATE 2024 CS1 · Q25MSQ1 mark
Which of the following process state transitions is/are NOT possible?

One or more options may be correct. Select all that apply, then submit.

GATE 2024 CS2 · Q25MSQ1 mark
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)?

One or more options may be correct. Select all that apply, then submit.

GATE 2024 CS1 · Q57NAT2 marks
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 ______.
GATE 2023 · Q22MSQ1 mark
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?

One or more options may be correct. Select all that apply, then submit.

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

One or more options may be correct. Select all that apply, then submit.

GATE 2021 Set 1 · Q14MSQ1 mark
Which of the following standard C library functions will always invoke a system call when executed from a single-threaded process in a UNIX/Linux operating system?

One or more options may be correct. Select all that apply, then submit.

GATE 2020 · Q12MCQ1 mark
Consider the following statements about process state transitions for a system using preemptive scheduling. I. A running process can move to ready state. II. A ready process can move to running state. III. A blocked process can move to running state. IV. A blocked process can move to ready state. Which of the above statements are TRUE?
GATE 2019 Set 2 · Q17NAT1 mark
The following C program is executed on a Unix/Linux system:
#include <unistd.h>
int main() {
  int i;
  for (i = 0; i < 10; i++) if (i % 2 == 0) fork();
  return 0;
}
The total number of child processes created is ______.
GATE 2018 · Q9MCQ1 mark
The following are some events that occur after a device controller issues an interrupt while process L is under execution. (P) The processor pushes the process status of L onto the control stack. (Q) The processor finishes the execution of the current instruction. (R) The processor executes the interrupt service routine. (S) The processor pops the process status of L from the control stack. (T) The processor loads the new PC value based on the interrupt. Which one of the following is the correct order in which the events above occur?
GATE 2017 Set 1 · Q18MCQ1 mark
Threads of a process share
GATE 2014 Set 1 · Q20MCQ1 mark
Which one of the following is FALSE?
GATE 2012 Code A · Q8MCQ1 mark
A process executes the code
fork();
fork();
fork();
The total number of child processes created is

Common traps

After fork() the child does not restart from the top: it continues after the fork call.
Variables are copied, not shared, between parent and child: a child's change is invisible to the parent.
A user-level thread blocking on I/O blocks the whole process, because the kernel only sees one thread.
Interrupt-driven preemption is not a system call: system calls are requested by the program, interrupts come from hardware.