System-call flow, end to end
A complete walk-through from printf to the device driver.
How System Calls Work
A system call is the programmatic way a computer program requests a service from the kernel of the operating system. Click any layer below to trace the full journey from user code to hardware and back.
System Call Flow
Every system call follows a predictable path through four distinct layers. Select a layer to see what happens inside.
System Call Categories
Six fundamental categories every systems programmer should know. Click any card to explore real-world examples and use cases.
Process control system calls let programs spawn new processes, replace their own image, and manage child processes. They are the foundation of multitasking operating systems.
-
fork()— Creates a child process that is an exact copy of the parent. Returns0to the child and the child's PID to the parent. -
exit(status)— Terminates the calling process and returns an exit code to the parent viawait(). -
wait(&status)— Parent blocks until a child terminates, collecting its exit status to prevent zombie processes. -
exec(path, args)— Replaces the current process image with a new program. Never returns on success. -
CreateProcess()— Windows equivalent that creates a new process and its primary thread with full control over security and environment.
Every file operation in user space eventually translates into a kernel system call. The kernel maintains file descriptors, buffer caches, and enforces access permissions.
-
open(path, flags)— Opens a file and returns a file descriptor (non-negative integer). Flags control read/write/append/create behavior. -
read(fd, buf, count)— Reads up tocountbytes from file descriptorfdinto the user-providedbuf. -
write(fd, buf, count)— Writescountbytes frombufto file descriptorfd. May buffer in kernel before physical write. -
close(fd)— Closes the file descriptor, flushing buffers and releasing all kernel resources associated with it. -
lseek(fd, offset, whence)— Repositions the read/write file offset. Supports SEEK_SET, SEEK_CUR, and SEEK_END.
Device management calls bridge the gap between generic file operations and device-specific control. They handle everything from disk drives to network cards and GPUs.
-
ioctl(fd, request, arg)— Device-specific input/output control. The "catch-all" for hardware commands that don't fit read/write semantics. -
mmap(addr, len, prot, flags, fd, off)— Maps files or devices directly into process memory for zero-copy I/O and shared memory. -
request_device()— Acquires exclusive or shared access to a hardware device, preventing race conditions. -
release_device()— Releases a previously acquired device, allowing other processes to claim it.
Information system calls provide read-only access to kernel-maintained data structures. They require no special privileges and are among the most frequently used calls.
-
getpid()— Returns the process ID (PID) of the calling process. Cached in userspace by glibc for performance. -
gettimeofday(&tv, &tz)— Retrieves the current time with microsecond precision using the kernel's high-resolution clock. -
uname(&buf)— Fills a structure with system identification: kernel name, version, release, machine architecture, and domain name. -
sysinfo(&info)— Returns system statistics: uptime, load averages, total/free RAM, shared memory, and buffer cache sizes.
Communication calls enable processes to exchange data — on the same machine or across a network. They form the backbone of distributed systems and microservices.
-
pipe(fd[2])— Creates a unidirectional data channel.fd[0]is read end,fd[1]is write end. Only between related processes. -
socket(domain, type, protocol)— Creates an endpoint for network communication. Supports TCP, UDP, Unix domain, and raw sockets. -
send(fd, buf, len, flags)/recv()— Send and receive data over a connected socket. Returns bytes transferred or -1 on error. -
shmget(key, size, flags)— Allocates a System V shared memory segment for the fastest possible IPC between processes.
Protection calls enforce the security boundary between users, processes, and the kernel. They manage who can read, write, or execute what — and under what identity.
-
chmod(path, mode)— Changes file permissions using octal mode (e.g.,0644) or symbolic strings. Controls r/w/x for owner, group, and others. -
chown(path, uid, gid)— Changes the owner and group of a file. Requires CAP_CHOWN capability or superuser privileges. -
setuid(uid)— Sets the effective user ID of the calling process. Used by setuid binaries likesudoto temporarily elevate privileges. -
set_permission()— Generic permission-setting call for fine-grained access control beyond traditional Unix permissions.