Introduction to Operating Systems
An operating system (OS) manages hardware and provides services to programs. It sits between applications and hardware, giving every program a consistent, protected view of the machine.
What an OS does
| Responsibility | Examples |
|---|---|
| Process management | Create, schedule and terminate programs |
| Memory management | Allocate RAM, provide virtual memory |
| File systems | Organise and protect data on disks |
| Device management | Drivers for disks, network cards, keyboards |
| Protection and security | Users, permissions, isolation between processes |
Kernel and user space
The kernel is the privileged core of the OS. Applications run in user mode and ask the kernel for services through system calls; the CPU switches to kernel mode for the duration of the call.
syscall.c
#include <unistd.h>
int main(void) {
// write() is a system call: the kernel performs the actual I/O
write(1, "hello\n", 6);
return 0;
}
Kernel designs
- Monolithic (Linux): most services run inside the kernel; fast, but a driver bug can crash everything.
- Microkernel (Minix, QNX): only the essentials in the kernel, the rest in user space; safer, with more message passing.
- Hybrid (Windows NT, macOS): a mix of both.
Common system calls
| Category | POSIX examples |
|---|---|
| Process control | fork, exec, wait, exit |
| File management | open, read, write, close |
| Device management | ioctl, read, write |
| Communication | pipe, socket, shmget |
Interrupts
An interrupt is a signal that makes the CPU pause the current work and run a handler: a keypress, a finished disk read, a timer tick. The timer interrupt is what lets the OS take the CPU back from a running program (pre-emption).
Loading Comments...