• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

Formal Definition

“A system call is a mechanism through which a user program requests a service from the operating system kernel.”

“System calls provide an interface between a process and the operating system.”

Explanation

System calls are the only legal way for user-space programs to get privileged work done. When a Python script calls open("file.txt"), that innocent-looking line triggers a chain: the standard library invokes a system call, the CPU switches from user mode to kernel mode, and the kernel performs the actual file read. System calls exist because applications cannot be trusted with direct hardware access — a malicious or buggy program could corrupt memory, steal data, or crash the system. The syscall interface enforces a controlled gateway: the kernel validates every request before executing it.

How It Works

  • A user program calls a library function (e.g., read() in C, open() in Python)
  • The library function places arguments in CPU registers and triggers a software interrupt or a special syscall instruction
  • The CPU switches from user mode to kernel mode (mode switch)
  • The kernel’s system call handler looks up the requested operation in a syscall table
  • The kernel validates arguments (checking pointers, permissions) and performs the operation
  • Results are placed in registers, the CPU switches back to user mode, and control returns to the application
  • Categories of system calls include: process control (fork, exec, exit), file management (open, read, write, close), device management (ioctl), information maintenance (gettimeofday), and communication (socket, send, recv)

Visual Explanation

system_call APP Application (User Mode) LIBC libc Wrapper APP->LIBC open("f.txt") SYS syscall Instruction LIBC->SYS set args + trap KERN Kernel Handler (Kernel Mode) SYS->KERN mode switch RESULT Return to User Mode KERN->RESULT complete + return

Semantic Network

semantic_system_calls THIS System Calls KERN Kernel THIS--KERN built from UMODE User Mode THIS--UMODE built from KMODE Kernel Mode THIS--KMODE built from MODE Mode Switching THIS--MODE builds into PROC Process Control THIS--PROC related FILE File Management THIS--FILE related COMM Communication IPC THIS--COMM builds into

Key Properties

  • Enables user-space programs to request kernel services
  • Triggers a mode switch from user mode to kernel mode
  • Categorized into process control, file management, device management, information maintenance, and communication
  • System calls are more expensive than normal function calls due to mode switching overhead
  • Experienced programmers batch operations (read large chunks) rather than making many small syscalls

Connections

  • Built from: Kernel — the kernel implements and handles system calls
  • Built from: User Mode — programs must exit user mode via syscalls to perform privileged work
  • Built from: Kernel Mode — the syscall handler executes in kernel mode
  • Builds into: Mode Switching — each system call causes a user-to-kernel mode switch
  • Contrasts with: function calls — function calls stay in user mode and have no hardware access; system calls switch to kernel mode
  • Related: Inter-Process Communication — IPC often relies on communication-related system calls

Edge Cases & Gotchas

  • System calls are NOT the same as library functions — printf() is a library function that internally calls write() syscall
  • Too many small system calls kills performance: reading a file one byte at a time causes a syscall per byte, while buffered reading uses one syscall per buffer
  • Some system calls block (e.g., read from a socket with no data) — the process is suspended until data arrives
  • Students often confuse function call (user mode only) with system call (requires kernel mode switch) — the key distinction is privilege escalation