Introduction
An operating system (OS) is system software that manages computer hardware and software resources and provides common services for application programs. It sits between the user/applications and the raw hardware, acting as an intermediary that hides the complexity of hardware devices while enforcing controlled, fair access to shared resources such as the CPU, memory, storage, and I/O devices.
Cricket analogy: Like an umpire standing between bowlers and batsmen enforcing the laws of the game, the OS sits between applications and hardware, translating raw physical action (the ball, the pitch) into fair, rule-governed play that both sides can trust.
Explanation
Without an OS, every application would need to talk directly to disk controllers, network cards, and the CPU scheduler itself — an unmanageable and dangerous proposition, since multiple programs would fight over the same resources. The OS provides two broad abstractions: (1) it acts as a resource manager, allocating CPU time, memory, and devices among competing processes; and (2) it acts as an extended/virtual machine, offering programmers a clean set of abstractions (files, processes, sockets) instead of raw registers and interrupts. Modern operating systems such as Linux, Windows, and macOS run in a privileged CPU mode (kernel mode) that ordinary applications (user mode) cannot access directly, forcing all hardware interaction to go through well-defined, safe entry points.
Cricket analogy: Without a central ground authority, every team would independently negotiate pitch access and umpiring decisions, causing chaos; the OS is like that central authority, acting as resource manager (allocating overs) and providing clean rules (LBW, no-ball) instead of raw physics.
Example
#include <stdio.h>
#include <unistd.h>
int main(void) {
/* getpid() is a thin wrapper around a system call.
The OS kernel, not the C library, actually knows
the process ID -- the library just asks it. */
pid_t pid = getpid();
printf("This process is managed by the OS.\n");
printf("My process ID (assigned by the kernel): %d\n", pid);
return 0;
}Output
Running this program prints a process ID such as 'My process ID (assigned by the kernel): 4821'. The exact number varies each run because the OS's process manager assigns IDs dynamically as processes are created and destroyed. This tiny example already demonstrates the OS acting as a resource manager: it is the sole authority that tracks which processes exist and hands out unique identifiers for them.
Cricket analogy: Each new player who walks out to bat is assigned a batting-order number by the team management on the spot, not pre-decided at birth, just as the OS's process manager dynamically hands out a unique process ID whenever a process is created.
Key Takeaways
- An OS is the software layer between hardware and applications.
- It acts both as a resource manager (CPU, memory, I/O) and a virtual/extended machine.
- Hardware is only accessed safely through the OS via privileged kernel-mode code.
- Examples of OS abstractions include processes, files, and sockets instead of raw hardware registers.
- Even a trivial call like getpid() shows the OS quietly managing state on your program's behalf.
Practice what you learned
1. What is the primary role of an operating system?
2. Why can't applications talk directly to hardware devices in most modern systems?
3. Which of the following best describes the OS as a 'virtual machine' or 'extended machine'?
4. In the example program, why does getpid() return different values on different runs?
Was this page helpful?
You May Also Like
OS Functions and Types
Explore the core functions every OS performs and the major categories of operating systems.
System Calls
Understand how applications request kernel services through system calls and the user-to-kernel mode transition.
OS Structure and Kernel Types
Compare monolithic, microkernel, and hybrid kernel architectures with real-world examples.