🎓 BookMCQ
← Back to 2. Operating System Structure

📝 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.
10
Easy
10
Medium
10
Hard

📝 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?

A.A system call ✅
B.A CPU scheduling quantum
C.A cache replacement policy
D.A shell alias
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.Every library function is implemented inside the kernel
B.The library function may wrap one or more system calls ✅
C.A library function always changes the running process
D.The library function directly controls the storage controller
💡 Difficulty: easy | ✅ Correct: B

📖 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?

A.File management
B.Device management
C.Process control ✅
D.Information maintenance
💡 Difficulty: easy | ✅ Correct: C

📖 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?

A.Both receive zero
B.The parent receives zero and the child receives its own PID
C.The parent receives the child's PID and the child receives zero ✅
D.Both receive the parent's PID
💡 Difficulty: easy | ✅ Correct: C

📖 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?

A.A new child is created and the caller continues unchanged
B.The caller's process image is replaced by the new program ✅
C.The caller only changes its current directory
D.The current program is paused until its parent calls wait()
💡 Difficulty: easy | ✅ Correct: B

📖 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?

A.open(), read(), write(), close() ✅
B.fork(), wait(), exec(), exit()
C.getpid(), getuid(), kill(), sleep()
D.mount(), chdir(), chmod(), umask()
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.wait()
B.ioctl() ✅
C.lseek()
D.getpid()
💡 Difficulty: easy | ✅ Correct: B

📖 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?

A.getpid() ✅
B.exec()
C.close()
D.pipe()
💡 Difficulty: easy | ✅ Correct: A

📖 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?

A.A page table
B.A pipe ✅
C.A CPU register
D.A file permission bit
💡 Difficulty: easy | ✅ Correct: B

📖 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?

A.Process creation
B.Memory mapping
C.File and directory management ✅
D.CPU scheduling
💡 Difficulty: easy | ✅ Correct: C

📖 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?

A.It remains running and consumes a full CPU continuously
B.It becomes blocked until the child changes to a waitable state ✅
C.It is converted into the child's process
D.It loses its open file descriptors immediately
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.3 bytes
B.5 bytes
C.8 bytes ✅
D.15 bytes
💡 Difficulty: medium | ✅ Correct: C

📖 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 5+3=85+3=8 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?

A.Treat the result as guaranteed memory corruption
B.Assume the kernel silently changed the buffer size
C.Process the 1,200 bytes and issue another read when appropriate ✅
D.Discard the returned bytes because the request was incomplete
💡 Difficulty: medium | ✅ Correct: C

📖 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?

A.Closed descriptor numbers can be reused by a later open() ✅
B.A descriptor number permanently identifies one file across the whole system
C.close() duplicates the original file automatically
D.open() always returns the largest unused descriptor
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.It remains running in a tight CPU loop
B.It enters a waiting state and becomes ready when data arrives ✅
C.It terminates because the pipe is temporarily empty
D.It changes into a kernel thread permanently
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.To guarantee the process receives the highest CPU priority
B.To allow the user program to modify kernel memory directly
C.To prevent unsafe access through invalid or unauthorized user addresses ✅
D.To convert the pointer into a process identifier
💡 Difficulty: medium | ✅ Correct: C

📖 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?

A.A process context switch must have occurred
B.A mode switch occurred, but a process context switch was not required ✅
C.The process was terminated and recreated
D.The call necessarily created a new thread
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.mmap() ✅
B.waitpid()
C.ioctl()
D.chdir()
💡 Difficulty: medium | ✅ Correct: A

📖 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?

A.When at least one write descriptor remains open
B.When every descriptor referring to the pipe's write end has been closed ✅
C.Immediately after the first byte is read
D.Only when the parent process is forcibly terminated
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.errno contains the process's exit status
B.errno is meaningful after a call reports failure, according to that interface's contract ✅
C.errno must be zero after every successful system call
D.errno always contains the most recent system-call number
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.A time-of-check to time-of-use race allows the opened object to differ from the checked object ✅
B.The process automatically changes from blocked to ready
C.The file descriptor becomes a physical memory address
D.The CPU scheduler fails to preserve the process identifier
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.Check only whether n is nonzero
B.Check that n does not exceed 256 and that the user range is accessible ✅
C.Assume the system-call transition makes every user address valid
D.Copy first and check the length afterward
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.It directly edits the source code of the running program
B.It records the event and arranges controlled transfer to the registered handler ✅
C.It must always terminate the process before handler execution
D.It converts the signal into a file descriptor
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.Creating a separate file system
B.Using a task-creation interface with configurable resource sharing ✅
C.Performing a disk seek
D.Replacing every thread with a child process image
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.Call dup2(file_fd, 1), close the redundant descriptor, then exec the program ✅
B.Call waitpid() before opening the file
C.Call getpid() and use its result as descriptor 1
D.Call exec() first and redirect the old process afterward
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.Descriptor 0
B.Descriptor 1 ✅
C.Descriptor 3 only
D.No descriptor remains open
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.Integer overflow can wrap the computed end address into a seemingly valid range ✅
B.The process identifier may become negative
C.The CPU quantum may expire during addition
D.The file's directory entry may be renamed
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.The socket has already transmitted every byte in its connection
B.A read operation can likely proceed without blocking at that instant ✅
C.The process has entered kernel mode permanently
D.The socket's data has been written to disk
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.The kernel waits until every inherited write-end reference is closed ✅
B.The reader must call exec() before reading EOF
C.The pipe buffer expands indefinitely and removes EOF
D.fork() changes the read end into a regular file
💡 Difficulty: hard | ✅ Correct: A

📖 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?

A.Descriptor numbers are global file identifiers that cannot be reused
B.The process reuses the lowest available descriptor number after it is released ✅
C.Opening C replaces file B because descriptor numbers must be consecutive
D.close(3) also closes descriptor 4 automatically
💡 Difficulty: hard | ✅ Correct: B

📖 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.

🔗 Related Topics (MCQs)