OSOperating Systems · Lesson 6 of 7

System Calls & Talking Between Processes

Every interesting thing a program does — print, read a file, open a connection — is a polite request to the kernel. Watch the requests and any program's behavior becomes transparent.

A system call is a controlled jump into the kernel: the program puts a syscall number and arguments in registers and executes a special instruction; the CPU switches to kernel mode at a fixed entry point; the kernel does the work, and returns a result (or an error). There are ~350 syscalls on Linux; a dozen — open, read, write, close, mmap, fork, execve, wait, socket, connect, accept, exit — cover most of what programs do.

Bash
# strace shows every syscall a program makes:
strace -c ls        # summary: counts and time per syscall
strace echo hi      # full trace; note write(1, "hi\n", 3)

# Even print() is a syscall at the bottom:
# python3 -c 'print("hi")'  ends in  write(1, "hi\n", 3)

# Syscalls are ~100-300ns each — cheap, not free.
# That's why buffered IO exists: 1 write() of 8KB
# beats 8000 write()s of 1 byte, ~1000x.

Processes are isolated by design, so the OS provides official channels between them — inter-process communication (IPC). Pipes stream bytes from one process to another (every shell | is one). Sockets do the same across machines. Shared memory maps the same physical pages into two processes — fastest, and reintroduces every threading hazard. Signals poke; files rendezvous.

Bash
# A shell pipeline is three processes and two pipes:
cat access.log | grep "500" | wc -l
#   cat's stdout -> pipe -> grep's stdin
#   grep's stdout -> pipe -> wc's stdin
# The kernel moves the bytes; the processes never meet.

# The pipe blocks when full — that's backpressure:
# 'cat' automatically slows to the speed of 'wc'.
# Unix got streaming right in 1973.
◆ Note
Containers (Docker) are not virtual machines — they're OS features: namespaces give a process group its own view of PIDs, filesystems, and network; cgroups cap its CPU and memory. Same kernel, walled gardens. A VM boots a whole second OS; a container is just processes wearing blinders — which is why containers start in milliseconds.