Skip to content
Official PYQ · 2021

GATE CS 2021 Set 1 Q14 — System Calls

Explain with AI

Which of the following standard CC library functions will always invoke a system call when executed from a single-threaded process in a UNIX/Linux\text{UNIX/Linux} operating system?

Select all correct options
View worked solution

Answer: A;C

To determine which C library functions always invoke a system call, let's analyze each option:

  • A. exit\textsf{exit}: This function performs user-space cleanup (such as flushing standard I/O buffers and executing registered atexit handlers) and then always invokes the _exit() (or exit_group()) system call to terminate the process. Thus, it always invokes a system call.
  • B. malloc\textsf{malloc}: This function manages a memory pool (heap) in user space. It only invokes system calls like brk, sbrk, or mmap when the pool does not have enough free space to satisfy the allocation request. If there is sufficient pre-allocated memory in the pool, malloc returns a pointer entirely in user space without any system call.
  • C. sleep\textsf{sleep}: To suspend the execution of a process for a specified duration, the operating system scheduler must be involved to yield the CPU. This is achieved by invoking system calls such as nanosleep or select. Therefore, sleep always invokes a system call.
  • D. strlen\textsf{strlen}: This function calculates the length of a null-terminated string by scanning memory. It operates entirely in user space and never needs to interact with the kernel, so it never invokes a system call.

Hence, the correct options are A and C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore System Calls questions