Which of the following standard library functions will always invoke a system call when executed from a single-threaded process in a operating system?
View worked solution
Answer: A;C
To determine which C library functions always invoke a system call, let's analyze each option:
- A. : This function performs user-space cleanup (such as flushing standard I/O buffers and executing registered
atexithandlers) and then always invokes the_exit()(orexit_group()) system call to terminate the process. Thus, it always invokes a system call. - B. : This function manages a memory pool (heap) in user space. It only invokes system calls like
brk,sbrk, ormmapwhen the pool does not have enough free space to satisfy the allocation request. If there is sufficient pre-allocated memory in the pool,mallocreturns a pointer entirely in user space without any system call. - C. : 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
nanosleeporselect. Therefore,sleepalways invokes a system call. - D. : 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.
