Operating Systems
Discover how operating systems manage hardware, memory, processes, files, and devices while providing an environment for applications to run.
1. What Is an Operating System?
An operating system (OS) is system software that manages computer hardware and provides services for applications and users.
When you open a browser, save a document, or play music, the operating system helps coordinate the resources needed for those tasks.
Examples of operating systems
- Microsoft Windows
- macOS
- GNU/Linux distributions
- Android
- iOS
2. Main Functions of an Operating System
3. Kernel and System Calls
The kernel is the core component of an operating system. It manages fundamental operations such as scheduling, memory, and access to hardware.
Applications generally request protected operating-system services through defined interfaces called system calls.
Application
|
v
Operating-system interface
|
v
Kernel
|
v
Hardware resources
For example, an application may request that the OS open a file. The operating system checks the request and permissions, then performs the appropriate operations.
4. Programs, Processes, and Threads
Program
A program is a set of instructions stored for execution. By itself, a program file is not necessarily running.
Process
A process is a running instance of a program, together with the resources and execution state managed for it.
Thread
A thread is a sequence of execution within a process. A process can have one or multiple threads.
Process: Web Browser
|
|-- Thread 1: Interface work
|-- Thread 2: Background task
|-- Thread 3: Page processing
This is a conceptual illustration. Actual browser architecture varies and may use multiple processes as well as multiple threads.
5. Process States
A process can move through different states during its lifetime. A simplified model includes the following:
| State | Meaning |
|---|---|
| New | The process is being created. |
| Ready | The process can run but is waiting for CPU time. |
| Running | The process is currently executing on a CPU core. |
| Waiting / Blocked | The process is waiting for an event, such as an I/O operation. |
| Terminated | The process has finished or has been stopped. |
New → Ready → Running → Terminated
^ |
| v
└── Waiting
State transitions depend on events such as scheduling decisions, I/O completion, and process termination.
6. CPU Scheduling
A CPU scheduler chooses which eligible process or thread should run next. Scheduling helps share processor time among competing tasks.
Common scheduling algorithms
- First Come, First Served (FCFS): Tasks are handled in arrival order.
- Shortest Job First (SJF): Selects the task with the shortest expected CPU burst.
- Priority Scheduling: Selects tasks according to priority rules.
- Round Robin: Gives each ready task a time slice before moving to another task.
Example: Round Robin
Time slice = 2 units Process A runs for up to 2 units Process B runs for up to 2 units Process C runs for up to 2 units Then the scheduler cycles through remaining ready tasks.
Round Robin is useful for sharing CPU time responsively. The appropriate scheduling method depends on the system's goals.
7. Memory Management
Memory management controls how programs use main memory (RAM). The operating system tracks memory usage and provides processes with suitable address spaces.
Key concepts
- RAM: Fast, temporary working memory used by running programs.
- Virtual memory: An abstraction that gives processes their own address spaces and can use storage to support memory management.
- Paging: Divides virtual memory into fixed-size pages and physical memory into corresponding frames.
- Page fault: An event that occurs when an access requires a page that is not currently mapped as needed; the OS handles it according to the circumstances.
- Memory protection: Helps prevent one process from accessing another process's protected memory without authorization.
8. File Systems
A file system defines how files and directories are organized and how information about stored data is maintained.
Common file-system concepts
- File: A named collection of data.
- Directory: A structure used to organize files and other directories.
- Path: Identifies a file or directory's location in a file-system hierarchy.
- Metadata: Information about a file, such as size, timestamps, or permissions.
- Permissions: Rules controlling who may read, write, or execute data.
Examples of file systems
- NTFS, commonly used by Windows.
- APFS, used by modern Apple operating systems.
- ext4, used by many Linux systems.
- FAT32 and exFAT, often encountered on removable storage.
9. Device and I/O Management
The operating system coordinates input and output (I/O) between applications and devices.
- Device drivers: Software components that allow the OS to communicate with particular hardware.
- Interrupts: Signals that can alert the CPU to events requiring attention.
- Buffering: Temporarily stores data while it is transferred between components.
- Spooling: Queues work for a device, such as print jobs waiting for a printer.
Application requests printing
|
v
Operating system prepares print job
|
v
Print queue stores pending work
|
v
Printer processes the job
10. Deadlocks
A deadlock occurs when a set of processes are permanently waiting for resources or events that cannot become available because of the waiting relationships between them.
Four classic conditions
- Mutual exclusion: At least one resource can be used by only one process at a time.
- Hold and wait: A process holds one resource while waiting for another.
- No preemption: Resources cannot simply be taken away under the assumed model.
- Circular wait: Processes form a cycle, each waiting for a resource held by another.
Under the classic resource-allocation model, all four conditions must hold for deadlock to be possible.
Ways systems handle deadlocks
- Prevention: Design resource rules so at least one necessary condition cannot hold.
- Avoidance: Grant requests only when the resulting state meets a safety criterion.
- Detection and recovery: Detect deadlocks and take steps to recover.
- Ignore: Some systems do not attempt general-purpose handling for certain kinds of deadlock.
11. Types of Operating Systems
12. User Interfaces: GUI and CLI
Graphical User Interface (GUI)
A GUI lets users interact through visual elements such as windows, icons, buttons, menus, and touch controls.
Command-Line Interface (CLI)
A CLI accepts text commands. It is useful for automation, system administration, development, and tasks that benefit from precise commands.
| GUI | CLI |
|---|---|
| Visual and often easier to discover. | Text-based and often efficient for repetitive tasks. |
| Commonly uses windows, icons, and menus. | Uses commands and their arguments. |
| Good for many everyday interactive tasks. | Useful for scripting and remote administration. |
Many operating systems provide both interfaces, and advanced users often use them together.
13. Knowledge Check
Try answering each question before revealing the answer.
1. What is the main purpose of an operating system?
2. What is the difference between a program and a process?
3. Which scheduling algorithm uses time slices?
4. What is virtual memory?
5. Name the four classic deadlock conditions.
6. What does a device driver do?
7. What is the difference between a GUI and a CLI?
Key Takeaways
- An OS manages hardware and provides services for applications.
- The kernel handles core system operations.
- Processes and threads represent units of program execution.
- Scheduling, memory management, and file systems are major OS responsibilities.
- Drivers, interrupts, and buffering support device communication.
- Deadlocks can be prevented, avoided, detected, or handled in other ways.
- Operating systems can offer graphical interfaces, command lines, or both.