Question

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?

Choose every correct option
Official answer and solution
Official answer
A and C
From
Official GATE 2021 answer key

Solution

Determine whether each standard library function can complete entirely in user space or requires kernel privilege transitions via system calls.

Let us analyze each function:

  • Option A (exit): The standard library exit() flushes all open stdio streams, invokes functions registered with atexit(), and must terminate the process. Process termination can only be performed by the kernel; hence it must always invoke a system call (exit_group or exit). (Correct)
  • Option B (malloc): The memory allocator maintains a heap memory pool in user space. If there is sufficient free space in the heap arena, malloc() satisfies the request directly in user space without requesting more memory from the kernel via brk() or mmap(). Hence, it does not always invoke a system call. (Incorrect)
  • Option C (sleep): Suspending a process requires relinquishing the CPU and asking the operating system scheduler to wake the process after the requested duration. This requires a timer-based system call such as nanosleep() or clock_nanosleep(). Hence, it always invokes a system call. (Correct)
  • Option D (strlen): Simply counts characters in a string in user-space memory until the null terminator is encountered. It never invokes a system call. (Incorrect)

Thus, options A and C are correct.

Final answer

A, C

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2021 Computer Science and Information Technology (CS, Set-1)
Question
24 of 65, printed as CS Q.14
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.