System calls in operating systems
API, system-call interface and the system-call table.
Module 1
Session 1.3
Lesson 4 of 7
System Calls in Operating Systems
How a system call runs: copy, the trap, and how arguments reach the kernel
Source: in.txt
➔ ➔ ➔
Destination: out.txt
Acquire input file name ("in.txt")
Write prompt to screen
Accept input
Acquire output file name ("out.txt")
Write prompt to screen
Accept input
Open the input file (abort if missing)
Create output file (abort if existing)
Loop: Read from input file
Loop: Write to output file
Until read fails (EOF)
Close output file
Write completion message to screen
Terminate normally
System Call Sequence for 'cp'
Even a simple command like
Click any step or use the controls to trace how the OS prompts the user, verifies files, transfers data in loops, and safely closes file handles.
cp in.txt out.txt triggers dozens of low-level system calls behind the scenes.
Click any step or use the controls to trace how the OS prompts the user, verifies files, transfers data in loops, and safely closes file handles.
Concept: A user program cannot directly read or write to disk; every operation must invoke kernel system calls.
User Mode (Unprivileged)
☁️ User Application calls
open("in.txt", O_RDONLY)
Kernel Mode (Privileged)
Syscall Table
...
i ➔ sys_open
...
Implementation of open()
1. Verify file existence
2. Check read permissions
3. Allocate file descriptor
4. Return handle
System Call Interface & Indexed Mapping
Applications rarely invoke hardware instructions directly. Instead, they call API functions provided by system libraries (like glibc).
The System Call Interface intercepts these calls and looks up the requested function in an indexed table (Index i). It switches hardware execution from User Mode to Kernel Mode, runs the kernel implementation, and returns the result back across the boundary.
Why? Protection. The OS hides hardware complexity and prevents user applications from executing unsafe memory/hardware operations directly.
Passing Parameters to System Calls
When invoking a system call, applications must pass input parameters (e.g., filenames, buffer sizes).
Three general approaches are used by OS architectures to pass these parameters across the user/kernel boundary.
Three general approaches are used by OS architectures to pass these parameters across the user/kernel boundary.
Linux Hybrid Rule: If there are \(\le 5\) parameters, Linux passes them directly in registers. If there are more than 5, it uses the Block/Table memory approach!