Operating Systems Basics
Cheatsheet Content
### Definition of OS An Operating System (OS) is a software program that manages computer hardware and software resources and provides common services for computer programs. It acts as an intermediary between the user and the computer hardware, making the computer system convenient to use and managing its resources efficiently. ### Types of OS Operating systems can be categorized based on their functionality and design: - **Batch OS:** Processes jobs in batches without direct user interaction. - **Time-Sharing OS:** Allows multiple users to share computer resources simultaneously via CPU scheduling. - **Distributed OS:** Manages a group of independent computers and makes them appear as a single coherent system. - **Network OS:** Runs on a server and provides capabilities to manage data, users, groups, security, applications, and other networking functions. - **Real-Time OS (RTOS):** Designed to process data with strict time constraints, often used in embedded systems. - **Mobile OS:** Designed specifically for mobile devices like smartphones and tablets (e.g., Android, iOS). ### Generation of OS The evolution of operating systems can be broadly classified into generations: 1. **First Generation (1940s-1950s):** No OS. Programmers interacted directly with hardware using machine language or plug boards. 2. **Second Generation (1950s-1960s):** Batch processing systems. Introduction of assemblers, compilers, and libraries. OS handled job sequencing. 3. **Third Generation (1960s-1970s):** Multiprogramming, time-sharing, and spooling. Emergence of minicomputers and interactive computing. UNIX was developed. 4. **Fourth Generation (1970s-1980s):** Personal computers (PCs). Development of networked OS, graphical user interfaces (GUIs), and client-server models (e.g., MS-DOS, Apple Macintosh). 5. **Fifth Generation (1980s-Present):** Distributed systems, mobile OS, parallel processing, and pervasive computing. Focus on ease of use, connectivity, and performance. ### Kernel The kernel is the core component of an operating system. It is the first program loaded when a computer starts and has complete control over everything in the system. Its primary responsibilities include: - **Process Management:** Managing the execution of multiple processes. - **Memory Management:** Allocating and deallocating memory space for processes. - **Device Management:** Managing I/O devices (disk, printer, etc.) and their communication. - **System Calls:** Providing an interface for user applications to interact with hardware. - **Interrupt Handling:** Responding to hardware and software interrupts. ### Kernel Architecture Different kernel architectures are designed to manage system resources: - **Monolithic Kernel:** All OS services (process management, memory management, file system, device drivers) run in a single address space within the kernel. This offers high performance but can be difficult to maintain and debug. - **Microkernel:** Only essential services (inter-process communication, basic memory management, scheduling) run in the kernel space. Other services (file systems, device drivers) run as user-level processes. This provides modularity and security but can have performance overhead due to message passing. - **Hybrid Kernel:** Combines aspects of both monolithic and microkernel architectures. It allows some non-essential services to run in kernel space for performance, while keeping others in user space for modularity (e.g., Windows NT, macOS). - **Exokernel:** Provides minimal hardware abstractions, allowing user-level applications to directly manage hardware resources. This offers high flexibility but is complex to program. ### Basic Architecture of OS The fundamental architecture of an OS typically involves several layers: 1. **Hardware:** The physical components of the computer (CPU, memory, I/O devices). 2. **Kernel:** The core of the OS, directly interacts with hardware and provides fundamental services. 3. **System Calls Interface:** Provides a programmatic interface for applications to request services from the kernel. 4. **Shell/User Interface:** The layer through which users interact with the OS (command-line interface or graphical user interface). 5. **Applications:** User-level programs and utilities that run on top of the OS. This layered approach helps in organizing and managing the complexity of the system. ### System Calls System calls are the programmatic interface between a process and the operating system. They are the only way a user program can request services from the kernel. When an application needs to perform an operation that requires kernel-level privileges (e.g., accessing files, creating processes, managing memory), it issues a system call. **Examples of System Calls:** - `fork()`: Create a new process. - `exec()`: Load a new program into a process. - `read()`, `write()`: Perform I/O operations on files or devices. - `open()`, `close()`: Open or close files. - `exit()`: Terminate a process. System calls provide a layer of abstraction between the user program and the hardware, ensuring system stability and security. ### PowerShell PowerShell is a command-line shell and scripting language developed by Microsoft. It is built on the .NET framework and is designed for automating tasks and managing configurations on Windows systems, and increasingly on Linux and macOS as well. **Key Features:** - **Object-Oriented:** Commands (cmdlets) output objects, not just text, which allows for powerful pipelining and manipulation. - **Extensible:** Users can write custom cmdlets and scripts. - **Integration:** Deeply integrates with Windows services, Active Directory, Exchange, SQL Server, etc. - **Remote Management:** Enables management of remote computers. PowerShell is a powerful tool for system administrators and developers for automating complex administrative tasks. ### Shell Commands Shell commands are instructions given to a command-line interpreter (shell) to perform specific tasks. A shell provides a text-based interface for interacting with the operating system. **Common Categories of Commands:** - **File Management:** `ls` (list files), `cd` (change directory), `mkdir` (make directory), `rm` (remove file), `cp` (copy file), `mv` (move file). - **Process Management:** `ps` (list processes), `kill` (terminate process). - **System Information:** `uname` (system information), `df` (disk free space). - **Networking:** `ping` (check network connectivity), `ipconfig`/`ifconfig` (network configuration). Shells like Bash (Linux/macOS) and Command Prompt (Windows) interpret these commands, allowing users to control the OS without a graphical interface. ### Services & Functions of OS Operating systems provide a wide range of services and functions to both users and system programs: 1. **Program Execution:** Loads and runs programs, handling their execution from start to finish. 2. **I/O Operations:** Manages input/output devices (keyboard, mouse, printer, disk) and facilitates data transfer. 3. **File System Management:** Organizes and manages files and directories, including creation, deletion, access control, and storage. 4. **Resource Allocation:** Distributes system resources (CPU time, memory, I/O devices) among various users and programs. 5. **Error Detection and Handling:** Monitors for errors (hardware or software) and takes appropriate action to ensure system stability. 6. **Security and Protection:** Protects system resources from unauthorized access and ensures data integrity. 7. **Process Management:** Creates, deletes, suspends, and resumes processes, and handles process synchronization and communication. 8. **Memory Management:** Keeps track of memory usage, allocates and deallocates memory to processes, and manages virtual memory. 9. **Networking:** Facilitates communication between different computers over a network. These services collectively enable efficient and secure operation of a computer system.