📝 System Calls in Operating System Structures (30 MCQs)
System Call Interface Between Applications and the Kernel
System calls provide the controlled programming interface through which user applications request services from the operating system kernel. They connect application-level operations with privileged facilities such as process creation, file access, memory management, and device communication. A system call transfers execution across the user-kernel boundary, allowing the kernel to validate requests, enforce protection rules, and perform operations unavailable to ordinary application code.
Why Programs Need a Controlled Kernel Entry Mechanism
Applications execute with restricted privileges and cannot directly perform protected operations such as modifying kernel memory or executing privileged device instructions. Allowing unrestricted access would compromise system stability and security. System calls solve this problem by exposing carefully defined entry points through which applications can request authorised operations without receiving unrestricted kernel privileges.
System Call Execution Through a Trap and Handler
A program invokes a system-call wrapper or library function, which prepares the system-call identifier and arguments. A designated processor instruction transfers control to the kernel entry point. The kernel identifies the requested service, validates arguments and permissions, executes its handler, and places the result in the appropriate return location before restoring user-mode execution.
Tracing an Open File Request Through the Kernel
Suppose a program requests open() for a file named results.txt. Its library wrapper prepares the path and access flags before invoking the system-call mechanism. The kernel checks the path, file permissions, and available resources. If successful, it returns a file descriptor; otherwise, it reports an appropriate error, allowing the application to handle the failure.
System Call Overhead, Protection, and Interface Stability
System calls provide a secure boundary between applications and privileged services, supporting portable access to operating system facilities. Their execution requires privilege transitions, argument validation, and kernel processing, introducing overhead compared with ordinary function calls. Operating systems therefore provide libraries that combine application-friendly interfaces with lower-level system-call mechanisms, while implementation details can differ across processor architectures.
Misconceptions About System Calls and Ordinary Functions
'Every library function is a system call' is incorrect because many library functions execute entirely in user space. 'A system call gives an application permanent kernel privileges' is incorrect because execution normally returns to user mode after servicing the request. 'All operating systems use identical system-call numbers' is incorrect because interfaces and numbering differ.
Exam Focus: Tracing System Call Arguments and Returns
Be able to explain the user-to-kernel transition, identify the role of system-call wrappers and handlers, and trace argument validation and result delivery. Distinguish system calls from library functions, interrupts, and ordinary procedure calls. Questions may examine file descriptors, process identifiers, privilege transitions, error returns, and the protection reasons behind controlled kernel entry.
Key Terms of System Call Interfaces
- System call - Controlled request for kernel service.
- Wrapper - Library function preparing a request.
- Trap - Controlled transfer into kernel execution.
- Handler - Kernel routine processing a request.
- File descriptor - Identifier for an open file.
- Return value - Result delivered to the caller.
📝 All System Calls in Operating System Structures MCQs
Q1. A text editor requests access to a file stored on disk. Which mechanism allows the application to request the protected file operation from the operating system?
📖 Explanation: A system call provides a controlled interface for requesting a kernel service from user mode. The kernel validates the request and performs protected work, such as opening a file, on behalf of the application.
Q2. A programmer calls a library function that opens a file. Which statement best describes how this function may interact with the operating system?
📖 Explanation: A library function can provide a convenient API and invoke a system call when kernel assistance is required. Some library functions perform entirely in user space, so not every function causes a privilege transition.
Q3. A process manager creates a process, waits for its child, and terminates execution. Which system-call category includes these operations?
📖 Explanation: Process-control calls create, execute, synchronize, and terminate processes. Operations such as fork(), exec(), wait(), and exit() belong to this category because they affect process existence or execution rather than file contents.
Q4. A process calls fork() successfully. Which return-value pattern allows the parent and child to follow different execution paths?
📖 Explanation: After a successful fork(), the child receives zero while the parent receives the child's process identifier. This lets each process distinguish its role and choose an appropriate execution path without creating separate source code.
Q5. A running program calls exec() with a valid executable path. What happens when the operation succeeds?
📖 Explanation: Successful exec() replaces the calling process's code, data, and stack with a new program image. The process identity remains the same, and execution begins at the new program's entry point rather than returning to old code.
Q6. A backup application must copy a file using ordinary descriptor-based operations. Which sequence is appropriate?
📖 Explanation: The application opens the source and destination, transfers bytes with read() and write(), and closes the descriptors afterward. These calls provide the normal kernel-mediated path for file access and data transfer.
Q7. A device-management utility needs to change a network adapter setting that is not represented by ordinary byte reads or writes. Which system call is commonly used for such device-specific control?
📖 Explanation: ioctl() provides a general mechanism for device-specific control requests, such as changing device parameters or retrieving status. Ordinary read() and write() transfer data, while ioctl() handles operations that need specialized commands.
Q8. A diagnostic program needs the identifier of the process currently executing it. Which system call supplies this information?
📖 Explanation: getpid() returns the process identifier of the calling process. It reports process identity without creating, replacing, or terminating a process, making it useful for diagnostics, logging, and identifying the executing task.
Q9. A parent and child need a unidirectional byte stream for communication. Which operating-system mechanism is designed for this purpose?
📖 Explanation: A pipe provides a byte stream through read and write file descriptors, allowing processes to exchange data. It is commonly used between related processes, such as a parent and child created with fork().
Q10. A file service receives a request to change permissions on an existing file. Which system-call family most directly supports this operation?
📖 Explanation: File-management system calls include operations for creating, deleting, reading, writing, renaming, and changing file attributes. Permission changes modify file metadata and are performed through the file-system interface after authorization checks.
Q11. A parent process creates a child and then calls waitpid() for that child's PID. The child exits later. What does the parent generally experience while waiting?
📖 Explanation: A blocking waitpid() suspends the parent until the specified child terminates or reaches a reportable state. The kernel later wakes the parent and supplies the child's status, allowing orderly process cleanup.
Q12. A process opens a file and reads 5 bytes. Its child inherits the descriptor through fork(), then reads 3 bytes from that descriptor. Assuming both reads succeed, what is the shared open-file offset afterward?
📖 Explanation: Descriptors inherited through fork() can refer to the same open-file description, which stores the current offset. The first read advances it by 5 bytes and the child's read advances it by 3, giving bytes.
Q13. A network application requests 4,096 bytes from read(), but the call returns 1,200 bytes without an error. What should the application do when it still needs the remaining data?
📖 Explanation: A successful read() may transfer fewer bytes than requested, especially for pipes, terminals, and network sockets. The caller must use the returned count and continue reading when its application protocol requires more data.
Q14. A process closes descriptor 4 and immediately opens another file. The new open() returns descriptor 4. What explains this result?
📖 Explanation: A process descriptor table can reuse a number after close() releases its entry. The descriptor is a process-local handle, not a permanent global identity for a particular file or storage object.
Q15. A data-processing program performs a blocking read() on an empty pipe. The writer later sends data. What typically happens to the reader in the interval?
📖 Explanation: A blocking read on an empty pipe normally places the reader in a waiting state. When data becomes available or the pipe reaches end-of-file, the kernel wakes the process so it can continue execution.
Q16. A system call receives a user-space pointer to a buffer and a length. Why does the kernel check the address range and access permissions?
📖 Explanation: User-supplied addresses and lengths cannot be trusted. The kernel validates the range and permissions before copying or accessing data, preventing invalid memory references from corrupting protected kernel state or exposing unrelated process memory.
Q17. A system-call instruction enters kernel mode, but the same process continues after the service returns. Which statement describes the event accurately?
📖 Explanation: A system call changes privilege level so the kernel can execute protected code. If the scheduler keeps the same process running, no process context switch occurs; the distinction is between execution mode and process identity.
Q18. A database maps a file region into its virtual address space and then accesses data through ordinary memory loads. Which system call is commonly used to establish this mapping?
📖 Explanation: mmap() creates a mapping between a file or other object and a process's virtual address space. The operating system manages the mapping and may load file-backed pages on demand as the process accesses them.
Q19. A child reads from a pipe after the parent has finished writing. It has consumed all buffered bytes. Under what condition does read() report end-of-file?
📖 Explanation: A pipe returns end-of-file after its buffered data is exhausted and all write-end descriptors are closed. An unused write descriptor inherited by a process can keep the pipe logically open and delay EOF.
Q20. A program calls open() and receives -1, then examines errno. Which interpretation is correct?
📖 Explanation: When a system call indicates failure, errno provides an error code describing the condition. Successful calls need not reset errno, so a previously stored value may remain and should not be interpreted after success.
Q21. A privileged file service checks whether a user may access a pathname, then opens it in a separate operation. An attacker replaces a directory component between the check and the open. What is the central flaw?
📖 Explanation: The authorization check and file open are separate operations, so the pathname can change between them. This time-of-check to time-of-use race can cause the service to open an object that was never authorized.
Q22. A kernel copies data from a user buffer of length n into a kernel buffer of capacity 256 bytes. Which validation is essential before copying?
📖 Explanation: The kernel must validate both the buffer length and the accessibility of the complete user address range before copying. Checking bounds prevents overflow, while safe user-memory access handles invalid mappings and protection faults.
Q23. A process creates a child, installs a signal handler, and later receives a signal while executing in user mode. What is the kernel's role in delivering the signal?
📖 Explanation: The kernel records pending signals and, when delivery is permitted, arranges a controlled return to user mode at the registered handler. The process later resumes through a signal-return mechanism that restores its execution context.
Q24. A multithreaded application creates a new thread using a lower-level operating-system primitive that can share the address space and selected resources with an existing task. Which idea does this illustrate?
📖 Explanation: Some operating systems provide task-creation primitives that let a new execution context share selected resources, including an address space. This supports thread implementation while allowing separate resource ownership when sharing flags differ.
Q25. A shell redirects a command's standard output to a file before executing the command. Which sequence correctly performs the descriptor redirection?
📖 Explanation: dup2(file_fd, 1) makes standard output refer to the opened file. Closing an unnecessary descriptor avoids a leak, and exec() then starts the command with the redirected descriptor preserved across program replacement.
Q26. A system-call trace lists these events: open returns 3 ; dup2(3,1) returns 1 ; close(3) returns 0 ; exec succeeds. Which descriptor refers to the opened file when the new program starts?
📖 Explanation: dup2() makes descriptor 1 refer to the same open-file description as descriptor 3. Closing descriptor 3 removes only that reference, so standard output remains connected to the file when exec() succeeds.
Q27. A service accepts a byte count from an untrusted client and computes start_address + count before checking whether the range is valid. What additional bug can make the check unsafe?
📖 Explanation: If addition overflows the integer type, the calculated end address can wrap to a small value and pass an incorrect bounds check. Safe validation checks overflow before arithmetic and verifies the entire range.
Q28. A server uses select() to wait until one of several sockets becomes readable. What does readiness indicate?
📖 Explanation: Readiness notification indicates that an operation such as read() can likely make progress without blocking at the time reported. It does not guarantee that all requested bytes are available or that a later operation cannot race.
Q29. A process calls fork(), and both parent and child inherit a descriptor for the same pipe's write end. The parent finishes its output but forgets to close its own write descriptor. Why might the reader never receive end-of-file?
📖 Explanation: The pipe remains open while any process holds a write-end descriptor. Even after the parent finishes writing, an inherited open reference prevents the reader from observing end-of-file until all writers close it.
Q30. A program opens two files and records this trace: open A returns 3 ; open B returns 4 ; close 3 ; open C returns 3. Which conclusion follows about descriptor allocation?
📖 Explanation: File descriptor numbers are handles maintained in a process descriptor table. When descriptor 3 is closed, its slot becomes available and can be assigned to the next open request, while descriptor 4 remains valid.