Operating Systems Cheatsheet

System Calls

Use this Operating Systems reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

What is a System Call?

A system call is the mechanism by which a user-space process requests a service from the OS kernel. It is the only sanctioned way to transition from user mode (ring 3) to kernel mode (ring 0).

Execution path:

User program
  → calls library wrapper (e.g., libc write())
  → wrapper puts syscall number in register (Linux: RAX)
  → executes SYSCALL instruction (x86-64) / SVC (AArch64)
  → CPU raises privilege; jumps to kernel entry point
  → kernel dispatches via syscall table
  → kernel executes service, places result in RAX
  → SYSRET; CPU lowers privilege
  → library returns to program

Key point: the application never directly executes kernel code — it traps into it.

x86-64 Linux Syscall Convention

RegisterRole
raxSyscall number (in), return value (out)
rdiArgument 1
rsiArgument 2
rdxArgument 3
r10Argument 4
r8Argument 5
r9Argument 6

Negative return value = errno negated (e.g., -2 = ENOENT).

; write(1, "hi\n", 3)
mov rax, 1       ; sys_write
mov rdi, 1       ; fd = stdout
lea rsi, [msg]   ; buf
mov rdx, 3       ; count
syscall

System Call Categories

Process Control

SyscallSignatureDescription
forkpid_t fork(void)Clone process
execveint execve(path, argv[], envp[])Replace process image
exitvoid exit(int status)Terminate process
wait / waitpidpid_t wait(int *status)Wait for child
getpid / getppidpid_t getpid(void)Get process ID
killint kill(pid_t pid, int sig)Send signal
signal / sigactionint sigaction(signum, act, old)Install signal handler
niceint nice(int inc)Adjust scheduling priority
clonelong clone(flags, …)Create thread (Linux-specific)

File Management

SyscallSignatureDescription
openint open(path, flags, mode)Open/create file
closeint close(int fd)Close file descriptor
readssize_t read(fd, buf, count)Read bytes
writessize_t write(fd, buf, count)Write bytes
lseekoff_t lseek(fd, offset, whence)Reposition
stat / fstatint fstat(fd, struct stat*)Get file metadata
unlinkint unlink(path)Delete file
renameint rename(old, new)Rename/move
chmodint chmod(path, mode)Change permissions
dup / dup2int dup2(oldfd, newfd)Duplicate fd

Directory & Filesystem

SyscallDescription
mkdir(path, mode)Create directory
rmdir(path)Remove empty directory
chdir(path)Change working directory
getcwd(buf, size)Get working directory
opendir / readdirIterate directory entries (libc wrappers)
mount(src, tgt, fs, flags, data)Mount filesystem
umount(path)Unmount
link(old, new)Create hard link
symlink(target, path)Create symbolic link
readlink(path, buf, n)Read symlink target

Memory Management

SyscallSignatureDescription
brk / sbrkint brk(void *addr)Extend/shrink heap (old)
mmapvoid *mmap(addr, len, prot, flags, fd, off)Map file/anonymous memory
munmapint munmap(void *addr, size_t len)Unmap
mprotectint mprotect(addr, len, prot)Change page permissions
madviseint madvise(addr, len, advice)Hint to OS (MADV_DONTNEED, …)
msyncint msync(addr, len, flags)Sync mmap'd region to disk

Inter-Process Communication

SyscallDescription
pipe(fd[2])Create anonymous pipe
socket(domain, type, proto)Create socket
bind, listen, accept, connectTCP/UDP setup
send / recvSocket I/O
shmget, shmat, shmdtSystem V shared memory
semget, semop, semctlSystem V semaphores
msgget, msgsnd, msgrcvSystem V message queues
mq_open, mq_send, mq_receivePOSIX message queues
eventfd(initval, flags)File descriptor for event notification
signalfd, timerfd_createSignal/timer as fd (Linux)

Device & I/O Control

SyscallDescription
ioctl(fd, request, arg)Device-specific control
select(n, readfds, …, timeout)Wait for fd readiness
poll(fds, nfds, timeout)Wait for fd events
epoll_create, epoll_ctl, epoll_waitScalable event polling
read / write on /dev/*Character/block device I/O
fsync(fd)Flush data + metadata to disk
fdatasync(fd)Flush data only (faster)

Errno: Common Error Codes

CodeValueMeaning
EPERM1Operation not permitted
ENOENT2No such file or directory
EINTR4Interrupted by signal
EIO5I/O error
EBADF9Bad file descriptor
EAGAIN / EWOULDBLOCK11Resource temporarily unavailable (aliases on Linux)
ENOMEM12Out of memory
EACCES13Permission denied
EFAULT14Bad address (pointer into invalid memory)
EBUSY16Device or resource busy
EEXIST17File exists
EINVAL22Invalid argument
EMFILE24Too many open files (per process)
ENOSPC28No space left on device
EPIPE32Broken pipe
ENOTSUP95Operation not supported
ETIMEDOUT110Connection timed out
ssize_t n = read(fd, buf, 512);
if (n < 0) {
    perror("read");           // prints: "read: No such file or directory"
    fprintf(stderr, "errno=%d\n", errno);
    // errno is thread-local
}

Signal Numbers (Linux x86-64)

SignalNumberDefault actionCommon cause
SIGHUP1TerminateTerminal hangup
SIGINT2TerminateCtrl+C
SIGQUIT3Core dumpCtrl+\\
SIGILL4Core dumpIllegal instruction
SIGTRAP5Core dumpBreakpoint (debugger)
SIGABRT6Core dumpabort()
SIGFPE8Core dumpFloating point exception
SIGKILL9TerminateCannot be caught/ignored
SIGSEGV11Core dumpSegmentation fault
SIGPIPE13TerminateWrite to closed pipe
SIGALRM14Terminatealarm() timer expired
SIGTERM15TerminateGraceful termination request
SIGCHLD17IgnoreChild stopped/terminated
SIGCONT18ContinueResume stopped process
SIGSTOP19StopCannot be caught/ignored
SIGTSTP20StopCtrl+Z
SIGUSR1/210/12TerminateUser-defined

POSIX fixes signal names and default actions, not numbers. On macOS/BSD the numbers differ: SIGSTOP=17, SIGTSTP=18, SIGCONT=19, SIGCHLD=20, SIGUSR1/2=30/31. Write kill -TERM, not kill -15, in portable scripts.

Linux-Specific High-Performance Syscalls

SyscallPurpose
io_uring_setup, io_uring_enter, io_uring_registerAsync I/O via shared ring buffers: setup creates rings, enter submits/reaps, register pins buffers/fds; batch many ops per syscall
sendfile(out, in, off, count)Zero-copy file-to-socket transfer
splice(fd_in, …, fd_out, …)Move data between fds without user-space copy
tee(fd_in, fd_out, len, flags)Duplicate pipe data without consuming
vmspliceTransfer user memory into pipe
getrandom(buf, len, flags)Cryptographic random bytes
seccomp(op, flags, prog)Restrict syscall set (sandboxing)
ptrace(request, pid, addr, data)Process tracing (debuggers, strace)