An operating system is made of several parts, each responsible for one resource, and it offers a set of services to users and programs.
Components of an OS
Process management creates and deletes processes, schedules them on the CPU, and provides synchronisation and communication between them. Main memory management keeps track of which parts of memory are in use and by whom, and allocates and frees memory. File management creates and deletes files and directories and maps them onto storage. Secondary storage management manages free space and disk scheduling. I/O system management hides the details of devices through device drivers, buffering and caching. Protection and security control access to resources and defend against attacks. Networking manages communication between computers. The command interpreter (shell) reads and carries out user commands.
Definition: System service. A function provided by the operating system to programs and users, such as program execution, I/O operations or file manipulation, usually requested through system calls.
Services Provided by an OS
For the user, the OS provides: user interface, as a command line (CLI), a graphical interface (GUI) or a touch interface; program execution, loading a program into memory and running it; I/O operations, since user programs cannot control devices directly; file-system manipulation, to read, write, create, delete and search files; communication between processes, through shared memory or message passing; and error detection, in the CPU, memory, devices and programs. For the efficient operation of the system itself, it provides resource allocation, accounting of resource use, and protection and security.
User and Kernel Mode
To protect itself, the OS uses dual-mode operation. Ordinary programs run in user mode, in which certain privileged instructions, such as I/O and changing memory limits, are not allowed. The OS runs in kernel mode, with full access. A program that needs a privileged action asks the OS through a system call, which switches the CPU to kernel mode, performs the action, and returns to user mode. A mode bit in the hardware records the current mode.
Table 1.2: OS services
| Service | Purpose | Example |
|---|---|---|
| User interface | Interact with the system | Shell, desktop |
| Program execution | Load and run programs | Running a browser |
| I/O operations | Use devices safely | Reading the keyboard |
| File manipulation | Manage files | Copy, delete, search |
| Communication | Exchange data between processes | Pipes, sockets |
| Error detection | Handle faults | Disk read error |
Example 1.2: Service behind an action
Problem: Which OS service is used when (a) a user double-clicks an icon, (b) a program reads a file, (c) two programs exchange a message, (d) a disk read fails?
Solution:
- Double-clicking starts a program: program execution (through the user interface).
- Reading a file: file-system manipulation.
- Exchanging messages: communication.
- A failed read is handled by error detection.
Result: (a) program execution, (b) file manipulation, (c) communication, (d) error detection.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int main(void) {
const char *msg = "written using the write() system call\n";
write(1, msg, strlen(msg));
int fd = open("/no/such/file", O_RDONLY);
if (fd < 0) printf("open() failed: the OS reported an error\n");
return 0;
}
Output
written using the write() system call
open() failed: the OS reported an error
Common mistakes
- Thinking that a program can drive a device directly. It must ask the OS.
- Confusing components (parts of the OS) with services (what it offers).
- Forgetting that the mode switches back to user mode after a system call.
Key takeaways
- The main components manage processes, memory, files, storage, I/O and security.
- Services include UI, program execution, I/O, files, communication and error detection.
- Dual-mode operation protects the OS: user mode and kernel mode.
- Privileged actions are requested through system calls.
Practice questions
- Name four services of an OS.
- What is dual-mode operation?
- What is a privileged instruction?
Answers to the practice questions
- User interface, program execution, I/O operations and file manipulation (also communication, error detection).
- Running user programs in user mode and the OS in kernel mode, so that privileged instructions are protected.
- An instruction that can be run only in kernel mode, such as direct I/O.
Sources
- Official BCA syllabus Operating Systems, course code 25BCA402DS03, Unit I
