Unit 1 : Overview of Operating Systems
UNIT 1:
Overview of Operating System, basic concepts, UNIX/LINUX Architecture, Kernel, services and systems calls, system programs.
Basic Concepts
Operating System (OS):
Definition: An operating system (OS) is a complex software system that serves as a bridge between computer hardware and user applications. It provides a comprehensive set of services and functionalities to manage hardware resources, facilitate user interaction, and enable the execution of software programs.
Functions:
- Resource Management: The OS manages various hardware resources such as CPU, memory, disk drives, and peripherals. It allocates these resources to different processes and ensures efficient utilization.
- Process Management: Process management involves creating, scheduling, and terminating processes. The OS manages the execution of multiple processes concurrently, allocating CPU time and memory resources as needed.
- Memory Management: Memory management is responsible for allocating and deallocating memory space to processes, ensuring that each process has sufficient memory to execute. It also handles memory protection, virtual memory, and memory swapping to optimize memory usage.
- File System Management: The OS provides a file system that organizes and controls access to data stored on disk drives. It manages files, directories, and file permissions, allowing users to create, read, write, and delete files.
- User Interface: The OS provides a user interface through which users interact with the system. This can be a command-line interface (CLI), a graphical user interface (GUI), or a combination of both. The user interface allows users to run applications, manage files, and configure system settings.
Types of Operating Systems:
- Batch Operating Systems: Batch operating systems process batches of tasks without user intervention. They are commonly used in scenarios where similar tasks need to be executed repetitively, such as payroll processing or batch data processing.
- Time-Sharing Operating Systems: Time-sharing operating systems allow multiple users to interact with the system concurrently. They achieve this by rapidly switching between user processes, giving each user the illusion of having dedicated access to the system.
- Distributed Operating Systems: Distributed operating systems manage a group of interconnected computers and present them as a single coherent system to users. They enable resource sharing and communication between networked computers.
- Network Operating Systems: Network operating systems provide services and functionalities for computers connected in a network. They manage network resources, facilitate communication between networked devices, and support network protocols.
- Real-Time Operating Systems: Real-time operating systems are designed to provide timely and predictable responses to events. They are used in applications where strict timing constraints must be met, such as industrial automation, robotics, and embedded systems.
An operating system plays a critical role in modern computing environments, serving as the foundation for running software applications and managing hardware resources. Its design and implementation significantly impact the performance, reliability, and security of computer systems.
UNIX/Linux Architecture
Overview:
UNIX and Linux are multiuser, multitasking operating systems. They provide a powerful and flexible environment for users.
Kernel
The kernel is the core component of an operating system (OS). It acts as a bridge between the hardware of a computer system and the software applications running on it. Essentially, the kernel provides a layer of abstraction, shielding applications from the complexities of interacting directly with hardware components.
Functions:
- Process Management: The kernel is responsible for creating, scheduling, and terminating processes. It manages the lifecycle of processes, including process creation, switching between processes, and reclaiming resources when processes terminate.
- Memory Management: Memory management involves allocating and deallocating memory space as needed by processes. The kernel tracks available memory, allocates memory to processes upon request, and ensures memory protection and isolation between processes.
- File System Management: The kernel manages files and directories on storage devices such as hard drives and SSDs. It provides file system drivers to interface with different file system formats, handles file operations (e.g., read, write, delete), and maintains file metadata (e.g., permissions, timestamps).
- Device Management: Device management encompasses controlling and interfacing with hardware devices such as disk drives, network interfaces, and input/output devices. The kernel manages device drivers, handles device interrupts, and provides a unified interface for accessing devices through device files in the file system.
Types:
Monolithic Kernel:
- In a monolithic kernel, all operating system services run in kernel space, meaning they execute within the privileged mode of the CPU.
- Example: Traditional UNIX kernel.
- Advantages:
- Efficiency: Direct access to hardware resources allows for faster system calls and better overall performance.
- Tight Integration: All OS components operate within a single address space, enabling seamless interaction and efficient communication.
- Disadvantages:
- Complexity: Monolithic kernels tend to be larger and more complex, making them harder to maintain and debug.
- Lack of Modularity: Changes to one part of the kernel can impact the stability and functionality of other parts.
Microkernel:
- In a microkernel architecture, only essential services, such as interprocess communication (IPC) and basic scheduling, run in kernel space. Other services, including device drivers and file systems, operate in user space as separate processes.
- Example: Minix, QNX.
- Advantages:
- Modularity: Microkernels are highly modular, with each service running in its own address space. This design enhances system reliability, flexibility, and extensibility.
- Isolation: User-space components are isolated from the kernel, reducing the risk of kernel crashes and improving system security.
- Disadvantages:
- Performance Overhead: Interprocess communication between user-space components and the kernel may incur additional overhead compared to direct kernel access in monolithic kernels.
- Complexity: Coordinating communication between kernel-space and user-space components requires careful design and may introduce complexity.
Hybrid Kernel:
- A hybrid kernel combines elements of both monolithic and microkernel designs, aiming to leverage the advantages of both approaches.
- Example: Windows NT, macOS.
- Advantages:
- Flexibility: Hybrid kernels offer flexibility in design, allowing developers to tailor the kernel architecture to suit specific requirements.
- Performance: By retaining critical services in kernel space while delegating non-essential services to user space, hybrid kernels can achieve a balance between performance and modularity.
- Disadvantages:
- Complexity: Hybrid kernels may inherit the complexity of monolithic kernels, particularly in managing the interactions between kernel-space and user-space components.
- Development Overhead: Designing and maintaining a hybrid kernel requires careful consideration of trade-offs between performance, modularity, and complexity.
Services and System Calls
System Calls:
Definition: System calls are functions provided by the operating system kernel that can be called directly by user programs or applications. These functions provide a way for user-space processes to interact with the kernel and request various operating system services.
Purpose: Purpose:
The primary purpose of system calls is to enable user-level processes to perform privileged operations that require kernel-level permissions. These operations include:
1. Process Management: Creating, terminating, and managing processes.
2.File Management: Opening, reading from, writing to, and closing files.
3.Device Management: Accessing hardware devices such as disk drives, printers, and network interfaces.
4.Memory Management: Allocating and deallocating memory, mapping memory regions, and managing virtual memory.
5.Communication: Establishing communication channels between processes, such as pipes, sockets, and message queues.
6.Time Management: Setting timers, scheduling alarms, and querying the system time.
7.Security: Performing operations related to access control, authentication, and permissions.
8.Network Operations: Initiating network connections, sending and receiving data over networks.
Types of System Calls:
Process Control:
fork()
: Create a new process.
exec()
: Replace the current process image with a new process image.
exit()
: Terminate a process.
File Management:
open()
: Open a file.
read()
: Read data from a file.
write()
: Write data to a file.
close()
: Close a file.
Device Management:
ioctl()
: Control device operations.
read()
: Read from a device.
write()
: Write to a device.
Information Maintenance:
getpid()
: Get the process ID.
alarm()
: Set an alarm clock for the delivery of a signal.
sleep()
: Suspend execution for a specified time.
Communication:
pipe()
: Create a pipe for interprocess communication.
shmget()
: Allocate shared memory.
mmap()
: Map files or devices into memory.
Examples of Common System Calls in UNIX/Linux:
fork()
, exec()
, wait()
, exit()
open()
, close()
, read()
, write()
ioctl()
, fcntl()
getpid()
, getuid()
, getgid()
pipe()
, shmget()
, semget()
System Programs
Purpose:
System programs provide a convenient environment for program development and execution. They offer services to the user and system utilities for managing system resources.
Types of System Programs:
File Management:
cp
: Copy files.
mv
: Move or rename files.
rm
: Remove files.
ls
: List directory contents.
Status Information:
ps
: Display process status.
top
: Display and update sorted information about processes.
df
: Report disk space usage.
free
: Display amount of free and used memory.
File Modification:
- vi: Text editor.
- nano: Simple text editor.
- emacs: Powerful text editor.
- sed: Stream editor for filtering and transforming text.
Programming Language Support:
- Compilers (e.g.,
gcc
for C, g++
for C++).
- Interpreters (e.g., python, perl).
Program Loading and Execution:
- exec: Execute a program.
- sh, bash: Shell programs for command execution.
Communications:
- ssh: Secure shell for remote login.
- scp: Secure copy for transferring files.
- ftp: File transfer protocol.
- mail: Simple email client.
Background Services (Daemons):
- cron: Job scheduling daemon.
- sshd: Secure Shell daemon.
- httpd: Web server daemon.