# Unit 3: Operating System

## 3.1 General Features of OS

### 3.1.1 Introduction
An Operating System (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. It acts as an intermediary between the user of a computer and the computer hardware. Without an operating system, a computer and its software programs would be useless. 

### 3.1.2 Need for an Operating System
- **Resource Management**: It allocates and manages resources such as memory, processors, devices, and information.
- **Convenience**: It provides a user-friendly interface to interact with the hardware.
- **Efficiency**: It ensures that computer system resources are used in an efficient manner.
- **Hardware Abstraction**: It hides the complexity of the hardware from the user and the application software.

### 3.1.3 Functions of an Operating System
- **Process Management**: Creating, scheduling, and terminating processes, as well as handling synchronization and communication among them.
- **Memory Management**: Keeping track of primary memory, i.e., what part of it is in use by whom, and what part is not in use. It allocates memory when a process requests it and deallocates it when the process terminates.
- **File Management**: Managing files, directories, and free space. It handles the creation, deletion, reading, and writing of files.
- **Device Management**: Keeping track of all devices. It is responsible for the I/O controller, deciding which process gets the device when, and for how long.
- **Security and Privacy**: Protecting data and resources from unauthorized access through passwords and other similar techniques.
- **Job Accounting**: Keeping track of time and resources used by various jobs and users.

### 3.1.4 Services Provided by an Operating System
- **User Interface**: Most OSs provide a User Interface (UI), which can be a Command-Line Interface (CLI), Graphical User Interface (GUI), or a touch interface.
- **Program Execution**: The OS loads programs into memory and runs them, handling execution and termination.
- **I/O Operations**: A running program may require I/O, which may involve a file or an I/O device. The OS provides a means to perform I/O operations efficiently.
- **File-System Manipulation**: Programs need to read, write, create, and delete files and directories. The OS provides services to perform these tasks.
- **Communication**: Processes need to exchange information with other processes executing on the same computer or on different computer systems tied together by a network.
- **Error Detection**: The OS needs to be constantly aware of possible errors (in CPU, memory hardware, I/O devices, or in user programs) and take appropriate action to ensure correct and consistent computing.

## 3.2 Types of OS (Introduction and Classification)

Operating systems can be classified based on their capabilities, functionalities, and intended use cases. 

### 3.2.1 Batch Operating System
In a batch operating system, users do not interact directly with the computer system. Each user prepares their job on an off-line device like punch cards and submits it to the computer operator. Jobs with similar needs are batched together and run as a group to speed up processing.
- **Advantage**: Good for large, repetitive tasks without user interaction.
- **Disadvantage**: Lack of interaction between the user and the job. CPU is often idle because the mechanical I/O devices are slower than the CPU.

### 3.2.2 Multitasking / Time-Sharing Operating System
Time-sharing (or multitasking) is a logical extension of multiprogramming. The CPU executes multiple jobs by switching among them, but the switches occur so frequently that the users can interact with each program while it is running.
- **Advantage**: Provides the illusion that multiple users are using the system simultaneously. Reduces CPU idle time.
- **Disadvantage**: Requires complex memory management and CPU scheduling.

### 3.2.3 Multiprocessing Operating System
A multiprocessing operating system supports the execution of multiple processes using two or more CPUs (processors) within a single computer system. The processors share the computer bus, the clock, memory, and peripheral devices.
- **Advantage**: Increased throughput, economy of scale, and increased reliability.
- **Disadvantage**: Complex OS design and coordination required among processors.

### 3.2.4 Real-Time Operating System (RTOS)
A real-time operating system is designed to handle real-time applications where data needs to be processed within a strict time constraint. A delayed response is considered a system failure.
- **Hard Real-Time**: Guarantees that critical tasks complete on time.
- **Soft Real-Time**: Gives critical tasks higher priority over other tasks but does not guarantee absolute strict timing.
- **Applications**: Industrial control systems, medical imaging systems, weapon systems, robotics.

### 3.2.5 Distributed Operating System
A distributed operating system manages a group of independent, networked, communicating, and physically separate computational nodes. They appear to users as a single centralized OS.
- **Advantage**: High fault tolerance; if one node fails, others can still function. Resource sharing across the network.
- **Disadvantage**: Complex implementation, heavy reliance on network availability.

### 3.2.6 Network Operating System
A network operating system runs on a server and provides the server the capability to manage data, users, groups, security, applications, and other networking functions. The primary purpose of the NOS is to allow shared file and printer access among multiple computers in a network.
- **Advantage**: Centralized control and security.
- **Disadvantage**: Costly server setup and maintenance.

### 3.2.7 Mobile Operating System
A mobile operating system is an OS specifically designed to run on mobile devices such as smartphones, tablets, and smartwatches. They combine features of a personal computer OS with other features useful for mobile or handheld use (e.g., touchscreens, cellular connectivity, GPS). Examples include Android and iOS.

## 3.3 Proprietary & Open-Source Software

### 3.3.1 Proprietary vs Open-Source
- **Proprietary Software**: Software owned by an individual or a company. The source code is kept secret, and users must purchase a license to use it. They cannot modify or distribute the software. Example: Microsoft Windows.
- **Open-Source Software**: Software whose source code is released under a license in which the copyright holder grants users the rights to study, change, and distribute the software to anyone and for any purpose. Example: Linux.

### 3.3.2 Windows OS - Introduction Only
Microsoft Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. It was introduced in 1985 as a graphical operating system shell for MS-DOS. Windows is the most popular desktop operating system globally, known for its user-friendly GUI, extensive software compatibility, and hardware support.

### 3.3.3 Linux OS
Linux is a family of open-source Unix-like operating systems based on the Linux kernel. It was initially released by Linus Torvalds in 1991. Linux is widely used in servers, supercomputers, embedded systems, and mobile devices (Android is based on the Linux kernel).

#### 3.3.3.1 Architecture and Components of Linux System
The Linux system architecture can be broadly divided into several layers:
1.  **Hardware**: The lowest level, consisting of the physical components (CPU, memory, disks, etc.).
2.  **Kernel**: The core of the operating system. It directly interacts with the hardware, managing memory, processes, and devices.
3.  **System Libraries**: Special functions or programs using which application programs or system utilities access Kernel's features. They implement most of the functionalities of the operating system without requiring kernel module code rights.
4.  **System Utilities (Shell/Applications)**: Utility programs that do specialized, individual level tasks. The **Shell** is a special program that provides an interface for the user to interact with the OS by executing commands.

#### 3.3.3.2 Kernel Mode vs User Mode
To ensure system stability and security, modern processors provide at least two modes of execution:
- **User Mode**: The mode in which normal application programs (like a web browser or a word processor) execute. Programs in user mode have restricted access to system resources and hardware. If a program crashes in user mode, it usually doesn't crash the entire system.
- **Kernel Mode**: The mode in which the core OS functions (kernel) execute. Code running in kernel mode has unrestricted, full access to all hardware and system memory. A crash in kernel mode can bring down the entire system. When a user application needs to perform a privileged operation (like reading a file or accessing a network), it makes a **system call**, temporarily switching the processor from User Mode to Kernel Mode.

#### 3.3.3.3 Basic Features of Linux
- **Open Source**: Free to use, modify, and distribute.
- **Multi-User**: Multiple users can access system resources concurrently.
- **Multiprogramming/Multitasking**: Multiple applications can run at the same time.
- **Hierarchical File System**: Organizes files in a tree structure, starting from the root directory (`/`).
- **Security**: Provides robust security features, including file permissions, user authentication, and data encryption.
- **Portability**: Linux can be installed on various types of hardware platforms (from smartphones to supercomputers).
- **Command-Line Interface (CLI)**: Offers a powerful CLI for system administration and automation, alongside GUIs (like GNOME or KDE) for everyday use.
