Common System Calls in Practice
You'll learn: How real programs use specific system calls like fork, exec, open, read, write, and close to interact with the operating system.
Understanding Real System Calls
Now that you know what system calls are and how they work, let's examine the workhorses that programs use every day. These are the specific requests your code makes to the kernel to do meaningful work.
Process Management System Calls
fork() creates a new process by duplicating the calling process. Think of it like photocopying a running program—the copy (child) continues from the same point as the original (parent).
exec() (actually a family: execv, execl, etc.) replaces the current process with a new program. It's like switching the DVD in a player—same player (process), different movie (program code).
File Operations System Calls
open() requests the kernel to open a file and returns a file descriptor (a number that identifies this open file). It's like asking a librarian for a book and getting a checkout card.
read() reads data from a file descriptor into a buffer in your program's memory.
write() sends data from your program's memory to a file descriptor (could be a file, screen, or network connection).
close() tells the kernel you're done with that file descriptor, releasing resources.
Real-World Flow
A typical program might: call open() to access a file → call read() repeatedly to get its contents → call write() to output results → call close() when finished. Meanwhile, a shell creates new programs by calling fork() to duplicate itself, then exec() to transform the copy into the desired program.
Key Takeaway: The most common system calls—fork, exec, open, read, write, and close—form the foundation of process creation and file I/O in practically every program running on your computer.