On this page

Operating Systems, Linux Architecture & CLI

Fundamentals of Computer Science · Unit 3

Unit 3 — Operating Systems, Linux Architecture & Command-Line Environments

1. Operating System Foundations & Evolution

An Operating System (OS) is system software that acts as an intermediary interface between computer hardware and user applications. It fulfills two primary objectives:

  1. Extended Machine (Abstractor): Hides complex, heterogeneous physical hardware registers behind uniform, programmer-friendly interfaces (system calls).
  2. Resource Manager: Allocates CPU execution time, primary memory addresses, disk storage, and I/O devices fairly, securely, and efficiently among competing processes.
+-------------------------------------------------------------+
|                     USER APPLICATIONS                       |
|           Browsers · Text Editors · Compilers · Games       |
+-------------------------------------------------------------+
|                  SYSTEM CALL INTERFACE                      |
|                  open() · read() · fork() · write()         |
+-------------------------------------------------------------+
|                   OPERATING SYSTEM KERNEL                   |
|   Process Manager · Memory Manager · File System · Drivers  |
+-------------------------------------------------------------+
|                      COMPUTER HARDWARE                      |
|                     CPU · RAM · Storage · I/O               |
+-------------------------------------------------------------+

1.1 Five Core Functions of an Operating System

  1. Processor / Process Management: Scheduling CPU time slices among active threads, tracking process execution states, handling context switching, and resolving deadlocks.
  2. Memory Management: Allocating memory chunks to processes, deallocating memory on termination, and managing virtual memory paging/swapping between RAM and disk.
  3. File System Management: Organizing files and folders into hierarchical directory structures, managing file access permissions, and reading/writing disk sectors.
  4. Device / I/O Management: Buffering, caching, and communicating with hardware peripherals via specialized device drivers.
  5. Security & Protection: Preventing unauthorized access through user authentication, protecting memory spaces from cross-process corruption, and enforcing file access control lists.

1.2 Classification of Operating Systems

OS Classification Operational Mechanism Key Characteristics Real-World Examples
Batch OS Similar jobs with identical requirements are grouped into batches by an operator and executed sequentially without interactive user intervention. High turnaround time; no direct user-computer interaction; CPU idle during I/O. Early IBM mainframes (IBM OS/360).
Multiprogrammed OS Keeps multiple jobs loaded in main memory simultaneously. When current job yields CPU for I/O, OS switches CPU to another job. Increases overall CPU utilization; reduces idle time. Corporate database servers.
Time-Sharing / Multitasking Allocates short, fixed CPU time slices (quantum, e.g., $10\text{ to }50\text{ ms}$) to multiple active users rapidly in round-robin fashion. Provides the illusion that all users own the CPU concurrently; low response time. Linux, macOS, modern Windows.
Distributed OS Manages a collection of independent networked computers, presenting them to the user as a single unified system. Shared computational power, high fault tolerance, seamless resource distribution. Apache Hadoop cluster OS, LOCUS.
Real-Time OS (RTOS) Guaranteed strict execution within rigid, deterministic time boundaries. Hard RTOS: Missing a deadline results in total catastrophic failure (airbags, pacemakers, avionics).<br>Soft RTOS: Missing a deadline degrades performance but is tolerable (audio streaming). VxWorks, QNX, FreeRTOS.
Mobile OS Engineered for battery-powered, touch-screen mobile devices with power, wireless, and memory constraints. Power management, gesture sensors, sandboxed app permissions, touch UI. Android (Linux kernel based), iOS (Apple Darwin/XNU kernel based).

1.3 Generations & Evolution of Operating Systems

Operating systems evolved through distinct architectural generations in lockstep with advancing semiconductor and computing hardware:

Generation Historical Period Underlying Hardware Operating System Innovations & Architecture Milestone Systems
1st Generation 1945–1955 Vacuum Tubes, Plugboards No Operating System. Programmers interacted directly with bare metal using mechanical plugboards and paper tape. Execution was strictly single-user, single-program at a time. ENIAC, EDVAC, IBM 701.
2nd Generation 1955–1965 Transistors, Magnetic Core Memory Early Batch Processing Systems. Programmers punched cards onto tape offline; an early monitor program batched jobs together, reducing setup time. IBM 7094, Fortran Monitor System (FMS), IBSYS.
3rd Generation 1965–1980 Integrated Circuits (ICs), Hard Disk Drives Multiprogramming & Time-Sharing. CPU switched between concurrent in-memory jobs to avoid I/O idle time. Spooling (Simultaneous Peripheral Operations On-Line) and user terminals emerged. IBM OS/360, MULTICS, UNIX (created 1969 at AT&T Bell Labs).
4th Generation 1980–2000s Microprocessors (LSI / VLSI) Personal Computer OS & Graphical Interfaces. Desktop computing with GUI, local networking (TCP/IP), and virtual memory. The POSIX standard emerged. MS-DOS, Windows 95/NT, Apple System 7, Linux (released 1991 by Linus Torvalds).
5th Generation 2000s–Present Multi-Core, 64-bit, SoC, Cloud Clusters Mobile, Cloud, Distributed & Containerized OS. Sandboxed app lifecycles, power management, cloud virtualization hypervisors, and container runtimes. Android, iOS, Red Hat Enterprise Linux, Kubernetes/Docker runtimes.

2. Linux Architecture & Shell Environments

Linux is a free, open-source, POSIX-compliant, multi-user, multitasking operating system based on Unix design principles.

2.1 The Four Architecture Layers

  1. Hardware: Physical silicon (CPU, RAM, Disks, Network cards).
  2. Kernel: The core heart of the operating system that resides continuously in protected memory space. Controls hardware directly, executes process scheduling, and enforces memory isolation.
  3. Shell: The command language interpreter that reads text commands from the user or script file and translates them into underlying kernel system calls.
    • Common Shells: bash (Bourne Again Shell - Linux default), zsh (Z Shell - macOS default), sh (Bourne Shell).
  4. User Applications & Utilities: Command-line utilities (ls, grep, cat) and high-level software suites running in user space.

2.2 Shell Environment Variables

The shell maintains configuration state through key-value environment variables:

  • echo $SHELL: Displays active shell binary path (e.g., /bin/bash).
  • echo $HOME: Current user's home directory (e.g., /home/student).
  • echo $USER: Active logged-in username.
  • echo $PATH: Colon-separated list of directories searched by the shell when executing commands.

3. Core Linux Command-Line Navigation & File Manipulation

The Linux directory structure is a single inverted tree starting from the root directory (/):

                                      / (Root)
                                      |
         +---------+---------+--------+--------+---------+
         |         |         |        |        |         |
       /bin      /etc      /home     /var     /tmp     /usr
       (Core     (Config    |        (Logs)   (Temp)   (User
      Commands)  Files)  /student                      Programs)

3.1 Essential Navigation Commands

Command Syntax & Flags Description & Output
pwd pwd Print Working Directory: Outputs absolute path of current directory.
cd cd [path] Change Directory: Moves terminal to targeted directory path.
cd .. cd .. Moves up one parent directory level.
cd ~ cd ~ or cd Jumps directly to current user's home directory (/home/username).
cd - cd - Toggles back to the previous working directory.
ls ls Lists files and folders in current directory.
ls -l ls -l Long listing format: Displays permissions, link count, owner, group, file size, and timestamp.
ls -a ls -a All files: Displays hidden files (files beginning with a dot .bashrc).
ls -la ls -la or ls -lah Combines long listing, hidden files, and human-readable file sizes (KB, MB).

3.2 Directory and File Manipulation Commands

Command Example Usage Description
mkdir mkdir Projects Creates a new directory.
mkdir -p mkdir -p Sem1/FCS/Unit3 Recursively creates nested parent directories without error.
rmdir rmdir EmptyFolder Removes an empty directory.
touch touch notes.txt Creates an empty file or updates the access timestamp of an existing file.
cp cp source.txt backup.txt Copies a file.
cp -r cp -r /dir1 /dir2 Recursive copy: Copies an entire directory and all contained files.
mv mv old.txt new.txt Moves or renames files and directories.
rm rm file.txt Deletes a file.
rm -rf rm -rf directory_name Recursive Force Remove: Deletes a directory and all its contents without prompt (use with extreme caution).

3.3 File Viewing & Text Processing Commands

  • cat filename: Concatenates and prints entire file content to terminal standard output.
  • less filename: Interactive pager allowing forward/backward scrolling through large files (q to quit).
  • head -n 10 file.txt: Displays the first 10 lines of a file.
  • tail -n 10 file.txt: Displays the last 10 lines of a file.
  • grep "keyword" file.txt: Global Regular Expression Print: searches and prints lines matching pattern.
  • wc -l file.txt: Word Count utility: -l counts total lines, -w counts words, -c counts bytes.
  • find /path -name "*.c": Recursively searches filesystem for files matching name pattern.

4. Linux Security & File Permissions Architecture

Every file and directory in Linux has an explicit security ownership model divided into three user classes and three permission modes:

        -   r w x   r - x   r - -
        |   \___/   \___/   \___/
     File   User    Group   Others
     Type  (Owner)

4.1 Permission Classes & Value Weights

User Class Symbol Meaning
Owner / User u The individual account that created or owns the file.
Group g Users belonging to the file's assigned group.
Others / World o All other users on the operating system.
All a Combination of user, group, and others (u + g + o).
Permission Symbol Octal Numeric Value Meaning on a File Meaning on a Directory
Read r 4 Can open and read file contents. Can list directory contents (ls).
Write w 2 Can edit, save, or truncate file. Can create, delete, or rename files in folder.
Execute x 1 Can execute file as a binary/script. Can enter directory (cd) and access files.
None - 0 No permissions granted. No access granted.

4.2 Octal Calculation & chmod Command

The octal permission is calculated by summing the values of granted permissions for each class:

$$ \text{Permission} = \text{Read (4)} + \text{Write (2)} + \text{Execute (1)} $$

  • rwx = $4 + 2 + 1 = \mathbf{7}$ (Full control)
  • rw- = $4 + 2 + 0 = \mathbf{6}$ (Read and Write)
  • r-x = $4 + 0 + 1 = \mathbf{5}$ (Read and Execute)
  • r-- = $4 + 0 + 0 = \mathbf{4}$ (Read-only)
  • --- = $0 + 0 + 0 = \mathbf{0}$ (No access)

Standard Octal Configurations:

  • chmod 755 script.sh: Owner gets rwx (7), Group gets r-x (5), Others get r-x (5). (Standard for executable scripts and directories).
  • chmod 644 document.txt: Owner gets rw- (6), Group gets r-- (4), Others get r-- (4). (Standard for web and document files).
  • chmod 600 private.key: Owner gets rw- (6), Group gets none (0), Others get none (0). (Strict security for SSH keys).

Symbolic Notation Examples:

  • chmod u+x program.bin: Grants execute permission to the owner.
  • chmod g-w shared.txt: Revokes write permission from the group.
  • chmod o=r public.txt: Sets others permission strictly to read-only.

4.3 Ownership Commands

  • chown student:cse file.txt: Changes owner to user student and group to cse.
  • chgrp cse file.txt: Changes assigned group to cse.

5. Linux Process Management & System Calls

A process is an active program currently in execution loaded into memory.

5.1 Process Lifecycle States

[ New ] ---> [ Ready ] <====== Context Switch ======> [ Running ] ---> [ Terminated ]
                 ^                                         |
                 |                                         v
                 +-------------- [ Waiting / Blocked ] <---+
                                    (I/O Request)
  • New: Process is being initialized and created.
  • Ready: Process is in memory waiting to be assigned CPU time by the scheduler.
  • Running: Instructions are currently being executed by the CPU core.
  • Waiting / Blocked: Process yielded CPU waiting for an external event (I/O, keyboard, disk read).
  • Terminated: Process finished execution; system resources are reclaimed.

5.2 Process Control Block (PCB) & Identification

The Linux kernel maintains a Task Struct / PCB for every active process:

  • PID (Process ID): Unique integer identifying the process (e.g., PID 1042).
  • PPID (Parent Process ID): The PID of the process that spawned this child process.
  • Process State: Current status (Running R, Sleeping S, Stopped T, Zombie Z).

5.3 Core Linux System Calls (fork, exec, wait)

In C and Linux systems programming, process hierarchies are constructed using low-level kernel system calls:

  1. fork() System Call:
    • Creates an exact duplicate child process by cloning the parent process memory space, file descriptors, and registers.
    • Return Values:
      • Returns 0 to the newly created child process.
      • Returns the child's PID ($> 0$) to the parent process.
      • Returns a negative value ($-1$) if process creation fails.
  2. exec() Family (execl, execvp):
    • Replaces the current process memory image with a completely new binary program from disk. The PID remains unchanged, but execution starts fresh from the new program's main().
  3. wait() / waitpid():
    • Causes the parent process to suspend execution and wait until a child process terminates, reading the child's termination exit status code.

Classic fork() Code Pattern:

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
    pid_t pid = fork();

    if (pid < 0) {
        printf("Fork failed!\n");
        return 1;
    } else if (pid == 0) {
        // Child process execution branch
        printf("Child Process: PID = %d, Parent PID = %d\n", getpid(), getppid());
    } else {
        // Parent process execution branch
        wait(NULL); // Wait for child to finish
        printf("Parent Process: Child with PID = %d completed\n", pid);
    }
    return 0;
}
  • Zombie Process: A child process that completed execution, but its exit status has not yet been read by its parent via wait(). Retains a minimal PCB entry in the process table.
  • Orphan Process: A child process whose parent terminated prematurely. In Linux, orphan processes are automatically adopted by init / systemd (PID 1).

5.4 Process Monitoring Commands

  • ps: Displays snapshot of active processes in current terminal session.
  • ps aux: Displays all active processes running across the entire system.
  • top: Interactive real-time display of running processes, CPU usage, and memory consumption.
  • htop: Enhanced, colorful, ncurses-based interactive process monitor with mouse navigation.
  • kill [PID]: Sends the termination signal SIGTERM (15) requesting graceful shutdown.
  • kill -9 [PID]: Sends SIGKILL (9), immediately terminating the process without cleanup.
  • Background execution: Appending & runs command in background (./long_job.sh &).

6. Remote Cloud Execution via SSH

Cloud computing and modern server administration rely on headless Command Line Interfaces over secure network connections.

6.1 Secure Shell (SSH)

SSH (Secure Shell) operates over default port 22, providing cryptographically encrypted command execution and administrative access across public networks.

# Connect to a remote Linux cloud server using password or key
ssh username@remote_server_ip

# Example: Connecting to an AWS Ubuntu instance with a private key
ssh -i "my-keypair.pem" ubuntu@ec2-54-210-12-89.compute-1.amazonaws.com

6.2 Secure Copy Protocol (SCP)

Transfers files securely between local and remote computers over SSH:

# Upload local file to remote server
scp local_report.txt username@remote_server_ip:/home/username/

# Download remote file to local computer
scp username@remote_server_ip:/var/log/syslog ./syslog_backup.txt

7. Unit 3 Review & CAT 3 Exam Checklist

  • 5 Core OS Functions: Process, Memory, File System, Device, and Security management.
  • OS Types: Compare Batch, Time-Sharing, and Real-Time (Hard vs Soft RTOS) systems.
  • Linux Architecture: Describe Hardware $\rightarrow$ Kernel $\rightarrow$ Shell $\rightarrow$ User Programs.
  • Octal Permission Calculation: Convert symbolic strings (e.g., -rwxr-xr--) into exact octal numbers (754) and vice versa.
  • System Calls: Explain the return value behavior of fork() and describe the relationship between fork(), exec(), and wait().
  • Zombies vs. Orphans: Differentiate between a zombie process and an orphan process.
  • Remote Cloud Operations: Explain the role of port 22 and SSH keypair authentication.

Saved Bookmarks

0

Request or Upload Content

Send missing topics, notes, question banks, or corrections directly to Sehjal

Click to upload or drag and drop
PDF, PNG, JPG, DOCX, ZIP (Up to 10MB)

Submitting opens FormSubmit's confirmation or error page. You can return to StudyDump with your browser Back button.