1
System Calls and User/Kernel Mode
Operating System
A program runs in user mode. To use hardware (files, network, new process) it makes a system call, which switches the CPU to kernel mode.
| Category | Examples (Linux) |
|---|---|
| Process control | fork(), exec(), exit(), wait() |
| File management | open(), read(), write(), close() |
| Device management | ioctl() |
| Information | getpid(), time() |
| Communication | pipe(), socket(), shmget() |
#include <unistd.h>
#include <stdio.h>
int main() {
pid_t pid = fork(); // creates a child process
if (pid == 0) printf("Child, pid = %d\n", getpid());
else printf("Parent, child pid = %d\n", pid);
return 0;
}
// fork() returns 0 in the child and the child's pid in the parent