- 2075 Baisakh · 6 marks
- Year not given
System call; read() execution
Short answer
A system call is a user program's request to the kernel for privileged service, using a library procedure and a TRAP. For read(), parameters are pushed, the system-call number is placed in a register, TRAP switches to kernel; the dispatcher invokes the handler, which performs I/O and returns the byte count.
What is a system call? Illustrate the execution of the system call read() to read a file.
A system call is a request made by a user program to the operating system kernel to perform a privileged service. The call is made through a library procedure that executes a TRAP instruction to enter kernel mode.
Execution of count = read(fd, buffer, nbytes)
The call reads nbytes bytes from the file with descriptor fd into buffer and returns the number of bytes read (-1 on error). The steps (Tanenbaum) are:
- The program pushes the parameters (
fd,buffer,nbytes) onto the stack (steps 1-3). - The program calls the library procedure
read(step 4). - The library procedure puts the system-call number for
readin a register (step 5). - It executes a TRAP instruction, switching from user mode to kernel mode and jumping to a fixed address in the kernel (step 6).
- The kernel's dispatcher examines the system call number and uses it to index a table of pointers to the handlers (step 7).
- The read handler runs: it checks the parameters, finds the file, and starts the disk transfer, blocking the process if necessary (step 8).
- When the work is done, control returns to the library procedure after the TRAP instruction (step 9).
- The library procedure returns to the user program in the normal way, with the result as its return value (step 10).
- The user program cleans up the stack by incrementing the stack pointer (step 11) and continues.
User space: program --> read() library
| TRAP
-----------------------------+------------
Kernel space: dispatcher -> table lookup
|
sys_read handler
|
disk driver / file system
|
return to library --> program
The user-mode to kernel-mode switch keeps the hardware protected, because user code cannot directly run privileged instructions.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- System call; monolithic and VM architecture · Operating System, chapter 1
- OS abstraction, extended machine, system call · Operating System, chapter 1
- Extended machine, kernel, system call · Operating System, chapter 1
- File system layout, i-node, backup · Operating System, chapter 5
- File system layout; i-node vs linked list · Operating System, chapter 5
- Linked list file system; block size impact · Operating System, chapter 5
- Student file read/write and modify by roll · Object Oriented Programming, chapter 8
- Manufacturing execution system and automation · Computer Aided Design, chapter 6
- Google File System architecture · Big Data Technologies, chapter 2 · asked 2×
- File system handling of kernel · Embedded System, chapter 6