CS FundamentalsHardGATE CS

A system call such as getpid() costs about 100 ns, while a plain function call costs about 2 ns. Which is the main reason?

  1. A. getpid must read the disk
  2. B. The kernel must create a new process for each call
  3. C. The mode switch (trap, saving state, entering and leaving the kernel), not the work getpid does
  4. D. System calls always cause a context switch to another process

Correct answer: C. The mode switch (trap, saving state, entering and leaving the kernel), not the work getpid does

getpid does almost nothing; the cost is the trap into kernel mode and back, including saving registers and possible mitigations. A context switch to another process is not required. Mechanisms like vDSO avoid the trap for some calls (e.g. gettimeofday).

More Operating Systems questions

Exams that ask this topic