Operating SystemsUnit 14 min read
Operating System Overview: Definitions, Functions, Structures, and System Calls
Unit 1 of Operating Systems: This note provides a foundational overview of OS concepts, covering the definition of an OS, its role as a resource allocator and control program, the architecture of system calls, and the distinction between various computing environments.
Key points
- An Operating System acts as an intermediary between the computer hardware and the user, managing resources and providing a platform for application execution.
- System calls provide the essential interface between a running program and the OS kernel, allowing access to privileged hardware operations.
- The shell serves as the command-line interface that interprets user commands and invokes the necessary system calls to execute them.
- Modern OS architectures are designed to support multitasking, multiprogramming, and time-sharing to maximize CPU utilization.
- Understanding the transition between user mode and kernel mode is critical for grasping how an OS maintains system security and stability.
Introduction to Operating Systems
An Operating System (OS) is a program that manages the computer hardware. It acts as an intermediary between the user of a computer and the computer hardware. The primary goals of an OS are to provide an environment in which a user can execute programs in a convenient and efficient manner and to allocate resources (CPU time, memory, I/O devices) fairly among competing processes.
Functions of an OS
- Resource Management: Acts as a resource allocator, deciding between conflicting requests for efficient resource use.
- Control Program: Manages the execution of user programs to prevent errors and improper use of the computer.
- Abstraction: Provides a virtual machine interface that hides the complexities of hardware from the user.
System Calls
A system call is a programmatic way in which a computer program requests a service from the kernel of the operating system. It is the interface between a process and the OS.
How System Calls Work
- User Mode: The application runs in user mode. When a system call is needed, the process executes a "trap" or "software interrupt."
- Mode Switch: The CPU switches from user mode to kernel mode.
- Execution: The kernel examines the system call number, executes the corresponding kernel function, and returns the result.
- Return: The CPU switches back to user mode, and the application resumes execution.
Common System Call Categories:
- Process Control:
fork(),exit(),wait() - File Management:
open(),read(),write(),close() - Device Management:
ioctl(),read(),write() - Information Maintenance:
getpid(),alarm(),sleep()
The Shell
The shell is a command-line interpreter that provides a user interface to the OS. It reads commands from the user and executes them. When a user types a command (e.g., ls or dir), the shell:
- Parses the command string.
- Searches for the executable file.
- Uses a system call (like
exec()in Unix) to start the process. - Waits for the process to complete or runs it in the background.
Comparison: User Mode vs. Kernel Mode
| Feature | User Mode | Kernel Mode |
|---|---|---|
| Access | Restricted access to hardware | Full access to hardware |
| Privilege | Low privilege level | High privilege level |
| Execution | User applications run here | OS kernel runs here |
| Switching | Switches to kernel via system call | Switches to user via interrupt return |
Computing Environments
- Batch Systems: Jobs are grouped together and processed sequentially without user interaction.
- Multiprogramming: Keeps multiple jobs in memory so the CPU always has one to execute, increasing CPU utilization.
- Time-Sharing (Multitasking): The CPU switches between jobs so frequently that users can interact with each program while it is running.
- Distributed Systems: A collection of physically separate, heterogeneous computer systems networked to provide users with access to various resources.
Worked Example: System Call Flow
Consider a process attempting to read a file:
- Application: Calls
read(fd, buffer, size). - Library: The standard C library places the system call number in a specific CPU register.
- Trap: The library executes a
syscallinstruction. - Kernel: The OS kernel receives the trap, validates the file descriptor (
fd), performs the disk I/O, and copies data to thebuffer. - Return: The kernel clears the trap and returns control to the user process with the number of bytes read.
Exam Tip
In TU exams, questions on this unit often focus on the conceptual flow of system calls and the distinction between OS types.
- When asked to "Define shell and system call," always mention that the shell is the interface and the system call is the mechanism for requesting services.
- If asked about "System Call Handling," draw a simple block diagram showing:
User Program->System Call Interface->Kernel->Hardware. - Be prepared to explain how multiprogramming increases CPU utilization by overlapping I/O operations with CPU processing.
Based on the TU BSc CSIT syllabus for Operating Systems (CSC264), unit 1.
Discussion
Loading…