IAE Academy

GATE 2023 CS Q.23: solution and answer

GATE 2023 · CSQ.23 · 1 mark · 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

See the question in the paper

Answer and solution

ANSWER

The options that guarantee a user-to-kernel mode switch are (C) Page Fault and (D) System Call.

Official answer: C, DSource: Official answer key, GATE 2023 CS (IIT Kanpur)

  1. A switch from user mode to kernel mode happens only through a trap (system call), an interrupt or an exception (such as a page fault). The question asks which events are certain to cause one.

  2. (A) An ordinary function call is a jump within user code. It stays in user mode, so it does not guarantee a switch.

  3. (B) malloc is a C library routine. It usually serves requests from the heap the library already holds. It calls brk or mmap only when the heap must grow, so a kernel entry is not guaranteed.

  4. (C) A page fault is a hardware exception. The CPU saves the state and enters kernel mode to run the page-fault handler. This happens every time, so it is guaranteed.

  5. (D) A system call executes a trap instruction (a software interrupt). The CPU switches to kernel mode and runs the kernel service routine. This is guaranteed.

  6. So (C) and (D) always cause the transition, while (A) never does and (B) only sometimes does.

KEY IDEA

The CPU enters kernel mode only through a trap, an interrupt or an exception. A system call and a page fault always do this. A plain function call never does, and a library call such as malloc does so only when it has to ask the kernel for more memory.

WATCH OUT FOR

Treating malloc as a system call. It is a library routine that enters the kernel (through brk or mmap) only when the heap must grow, so it does not guarantee a mode switch.

From the GATE 2023 CS paper. Every question of this paper · Download the full paper · All 9 Processes & threads questions, with notes

More Processes & threads questions