Learn computing fundamentals, programming, algorithms, systems, and software engineering.
An operating system is the software that manages a computer’s hardware and gives applications a clean, safe place to run. Without it, every program would have to talk to the disk, memory, and devices directly, and one buggy program could crash the whole machine. The OS juggles four big responsibilities: managing processes, managing memory, managing files, and managing devices. It also enforces security so programs cannot stomp on each other. This lesson explains what a process and a thread are, why concurrent programs produce race conditions, how locks and semaphores fix them, what deadlock is, and how virtual memory and paging let many programs share one machine safely.
The OS sits between applications and hardware, providing services through system calls.
A program is a file of instructions on disk. A process is a running instance of that program in memory. One program can run as many processes.
A process is created, waits until the scheduler gives it the CPU, runs, and eventually terminates. Waiting states are inserted when it blocks on I/O.
| Process | Thread | |
|---|---|---|
| Memory | Has its own address space | Shares the process’s address space |
| Cost | Heavier to create | Lighter to create |
| Communication | Inter-process (harder) | Shared memory (easier) |
| Analogy | An application | A worker inside an application |
When multiple threads update shared data without coordination, the interleaving of their operations can produce wrong results. This is a race condition.
A mutex (mutual exclusion lock) lets only one thread enter a critical section at a time. The other threads wait until the lock is released.
| Mutex | Semaphore | |
|---|---|---|
| Count | Binary (locked/unlocked) | Can count up to N |
| Use | Mutual exclusion | Limit N threads into a section / signal events |
| Who unlocks | Only the owner | Any thread |
Deadlock happens when threads wait on each other in a cycle and none can proceed. Four conditions must all hold: mutual exclusion, hold-and-wait, no preemption, and circular wait.
The OS gives each process a private virtual address space, then maps it to physical memory in fixed-size blocks called pages. The page table records which virtual page maps to which physical frame.
The file system organises files and directories on disk and stores metadata such as names, sizes, and permissions. Applications ask the OS to work on files through system calls such as open, read, write, and close. System calls run in kernel mode, which has full hardware access, while ordinary application code runs in user mode.
Without the lock, counter may be less than 400000 because of the race condition.
Run the counter with and without a lock to see the difference.
400000