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?
- A. getpid must read the disk
- B. The kernel must create a new process for each call
- C. The mode switch (trap, saving state, entering and leaving the kernel), not the work getpid does
- 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
- In which order does the long-term, medium-term and short-term scheduler act on a process, and which one runs most frequently?
- Which scheduling algorithm can be implemented as a special case of priority scheduling where priority = 1 / (predicted next CPU burst)?
- Which scheduling algorithms can lead to STARVATION? 1. FCFS 2. Non-preemptive SJF 3. SRTF 4. Round Robin 5. Priority without aging
- A system uses Round Robin with quantum q. As q → ∞ it becomes FCFS. What does it approach as q → 0 (ignoring switch overhead)?
- Under a fair-share / proportional-share scheduler, user A runs 1 process and user B runs 4 processes, all CPU-bound, and the two users…
- Lottery scheduling gives process A 30 tickets, B 20 and C 50. Over many scheduling decisions, what fraction of the time does B run, and…