Operating System Fundamentals: Commands, Architecture, and Services
Operating System Concepts
1. Internal vs. External Commands
Internal commands are built into the command interpreter (like Command Prompt in Windows or Shell in UNIX) and are always loaded into memory when the operating system starts. They execute directly without requiring an external file and are faster. Examples in Windows include DIR, CLS, COPY, and DEL. In UNIX/Linux, examples are CD, PWD, ECHO, and EXIT.
External commands are separate executable files stored in the operating system. They are not built into the command interpreter and require the operating system to locate and load their corresponding files into memory before execution. This can make them slower than internal commands. Examples in Windows include FORMAT.EXE, CHKDSK.EXE, and DISKCOPY.EXE. In UNIX/Linux, examples are LS, FIND, GREP, and AWK.
2. The Directory Command (DIR)
The DIR command displays a list of files and subdirectories in a specific directory. It’s used in operating systems like Windows and DOS to explore file structures. It shows details like file size, creation date, and time.
Syntax: DIR [drive:][path][filename] [parameters]
- [drive:][path]: Specifies the drive and path to list.
- [filename]: Displays specific files.
- [parameters]: Modifiers to customize output (e.g., /P for paginated output, /A to show hidden files).
Example: To view the contents of the Documents directory on the C drive:
DIR C:\Documents
Useful Parameters:
/P
: Displays output one page at a time./S
: Lists all files in the specified directory and subdirectories./A
: Shows files with specified attributes (e.g., hidden files)./W
: Displays output in a wide format.
3. The Ls Command
The Ls command is widely used in Unix/Linux systems to list the contents of a directory, including files, subdirectories, and their attributes. It helps users navigate the file system efficiently.
Purpose: Displays files and directories in a specified path or the current directory.
Syntax: Ls [options] [directory]
Common Options:
-l
: Provides a detailed listing with file permissions, owner, size, and modification date.-a
: Lists all files, including hidden files (starting with a dot).-h
: Displays file sizes in a human-readable format (e.g., KB, MB).-R
: Recursively lists files and directories.-t
: Sorts files by modification time (newest first).-S
: Sorts files by size (largest first).
4. Linux System Architecture
The Linux operating system architecture is modular and layered, designed for performance, scalability, and flexibility. Key components include:
- Kernel: The core component, managing hardware, system resources (process, memory, device, file system management). Linux uses a monolithic kernel.
- System Libraries: Act as an interface between applications and the kernel, providing functions like system calls (e.g., GNU C Library – glibc).
- System Utilities: Programs for managing files, monitoring processes, and configuring the system (e.g., ls, cp, mkdir, top, df).
- Shell: A command-line interface (CLI) for user interaction with the system (e.g., Bash, Zsh).
- Applications: User-space programs providing specific functionalities (e.g., Firefox, Vim).
The layered structure is typically visualized as:
| Applications | | Shell | | System Utilities | | System Libraries | | Kernel | | Hardware Layer |
5. Operating System Definition and Examples
An Operating System (OS) is system software that acts as an interface between the user, applications, and computer hardware. It manages hardware resources and provides essential services for software execution, ensuring smooth communication and system functionality.
Key Functions: Process Management, Memory Management, File System Management, Device Management, Security.
Common Operating Systems:
- Windows OS: Developed by Microsoft, popular for personal computers (e.g., Windows 11).
- Linux OS: Open-source, versatile, and reliable (e.g., Ubuntu).
- macOS: Developed by Apple Inc. for Apple computers (e.g., macOS Ventura).
- Android OS: Mobile OS by Google for smartphones and tablets (e.g., Android 13).
6. Operating System Services
Operating systems provide essential services for program execution, resource management, and user interaction:
- Program Execution: Loading, executing, and terminating programs.
- File System Management: Managing files and directories (creation, deletion, access).
- Memory Management: Allocating and managing memory for processes.
- Process Management: Scheduling, creating, and terminating processes, ensuring multitasking.
- Device Management: Facilitating communication with hardware devices via drivers.
- Security and Access Control: Protecting the system with authentication and permissions.
- Error Detection and Handling: Monitoring for and recovering from system errors.
- User Interface: Providing CLI and GUI for user interaction.
7. System Calls: Definition and Workflow
A System Call is a mechanism allowing user applications to request services from the operating system’s kernel. It bridges user space and kernel space for privileged operations.
How System Calls Work:
- User Space to Kernel Space Transition: An application makes a system call request (e.g., opening a file).
- Interrupt or Trap: An interrupt or trap signals the kernel, switching control to kernel space.
- System Call Handling: The kernel identifies the call by its number and executes the requested function.
- Return to User Space: The kernel returns the result (success, error, or data) to the application, and control returns to user space.
8. Common System Calls
- fork(): Creates a new child process, a duplicate of the parent. Returns the child’s PID to the parent and 0 to the child. Used for multi-tasking.
- open(): Opens a file, returning a file descriptor for subsequent operations. Checks file existence and permissions. Used for file access.
- exec(): Replaces the current process image with a new program. The calling process executes a different program. Used for running new programs.
- read(): Reads data from a file or device into a memory buffer. Returns the number of bytes read or an error code. Used for file input.
9. The Booting Process
The booting process starts a computer and loads the OS into memory:
- Power-On Self-Test (POST): BIOS/UEFI performs hardware diagnostics. Errors are indicated by codes or beeps.
- Loading the BIOS/UEFI: Firmware initializes hardware and identifies bootable devices.
- Bootloader Execution: BIOS/UEFI loads the bootloader from the boot sector of the primary boot device.
- Loading the Kernel: The bootloader loads the OS kernel into memory, which then takes control of hardware.
- Initializing the Operating System: The kernel starts system processes, initializes services (file systems, networking), and displays the user login prompt.
10. Program vs. Process
A program is a static set of instructions stored on disk, a passive entity. It consists only of code and data.
A process is a dynamic instance of a program in execution. It’s an active entity with a program counter, stack, heap, and associated resources. Multiple processes can be created from a single program.
Key Differences:
- Definition: Program = static instructions; Process = program in execution.
- Nature: Program = passive; Process = active.
- Lifespan: Program = on disk; Process = during execution.
- Components: Program = code/data; Process = code, PC, stack, heap, data.
- Multiplicity: Program = one file; Process = multiple instances possible.
- Dependency: Program = none; Process = depends on program and resources.
Example: A file named example.c
is a program. When compiled and run, it becomes a process executing the sum calculation.