Linux Programming and Cloud Computing

Linux Evolution, GNU, GPL and System Architecture

PGCP-BDA

Linux evolution

Linux grew from a Unix-like kernel into a complete operating-system family by combining the kernel with GNU tools, libraries.

GNU project

The GNU project develops a free Unix-compatible software environment

GPL

The GNU General Public License permits use, study, modification and redistribution while requiring redistributed derivative source code to remain available.

distribution

A Linux distribution packages the kernel, installer, system libraries, utilities, package manager.

kernel and user space

Kernel space executes privileged code that manages memory, devices, processes and filesystems

system call

A system call is the protected entry point through which a user-space process asks the kernel to perform work such as opening a file.

process and service

A process is a running program instance; a service is a managed background capability often supervised by a service manager.

Linux server

A Linux system configured to provide network or local services under controlled identities, resources and operational policies.

UNIX System Architecture

Overview

UNIX is one of the most influential operating systems ever designed (Bell Labs, 1969).

Major Subsystems of UNIX:

  1. File Subsystem — manages files and directories
  2. Process Control Subsystem — manages processes

UNIX Architecture Diagram

+-------------------------------------------------------+
|                  USER SPACE                           |
|   User Programs / Applications                        |
|   (Shell, Compiler, text editor, database client)    |
+------------------+-------------------------------------|
|       System Call Interface (API boundary)            |
+------------------+------------------------------------+
|                  KERNEL SPACE                         |
|   File Subsystem    |   Process Control Subsystem     |
|   (file operations) |   (process scheduling, IPC)    |
|   +---------------+ |   +-------------------------+   |
|   | File tables   | |   | CPU Scheduler           |   |
|   | Inodes        | |   | Memory Management       |   |
|   | Buffer cache  | |   | IPC (pipes, signals)    |   |
|   +---------------+ |   +-------------------------+   |
+----------------------+----------------------------------+
|         Hardware Control (Device Drivers)              |
+-------------------------------------------------------+
|               HARDWARE                                |
|   CPU | Memory | Disk | Network | Terminal            |
+-------------------------------------------------------+

UNIX Key Concepts

ConceptDescription
Everything is a fileDevices, sockets, pipes are represented as files
ShellCommand-line interface to the kernel (bash, sh, zsh, ksh)
PIDEvery process has a unique Process ID
UID/GIDUser ID and Group ID for security
File permissionsrwx for owner, group, others
KernelCore of the OS managing all resources
DaemonBackground process (like a service in Windows)

System Calls

What are System Calls?

System calls provide the interface between user programs and the operating system kernel.

When a program needs OS services (file I/O, process creation, memory allocation), it makes a system call.

Categories of System Calls

CategoryExamples
Process Controlfork(), exec(), exit(), wait(), getpid()
File Managementopen(), read(), write(), close(), unlink(), stat()
Device Managementioctl(), read(), write() (for devices)
Information Maintenancegetpid(), alarm(), sleep(), time()
Communicationpipe(), socket(), send(), recv(), shmget()

System Call Flow

User Program
    |
    | calls  printf("hello") → internally calls write()
    |
    ↓
std C library (write() wrapper)
    |
    | System Call Instruction (int 0x80 / syscall)
    ↓
KERNEL (system call handler)
    |
    | sys_write() → device driver → I/O
    ↓
Returns to user program

Dual Mode Operation

What is Dual Mode?

The CPU operates in two modes to protect the OS from user programs:

ModeAlso CalledPrivilege
User ModeUnprivileged modeLimited instructions; cannot directly access hardware
Kernel ModeSupervisor/System modeAll instructions; full hardware access

Mode Switching

User Program executes → User Mode
     |
     | System Call or Interrupt
     ↓
Kernel Mode (OS handles request)
     |
     | Return from system call
     ↓
User Mode (program resumes)

Mode bit:

  • 0 = Kernel Mode
  • 1 = User Mode

Privileged vs Non-Privileged Instructions

Instruction TypeUser ModeKernel Mode
I/O operationsNot allowedAllowed
Memory managementNot allowedAllowed
Interrupt controlNot allowedAllowed
Normal arithmeticAllowedAllowed
Function callsAllowedAllowed

Process Management

What is a Process?

A process is a program in execution — an active entity.

Program vs Process:

FeatureProgramProcess
StatePassive (on disk)Active (in memory)
ResourcesNone (static file)CPU, memory, I/O
NumberOne copy on diskMultiple processes can run from same program
Examplenotepad.exe fileRunning instance of Notepad

Process in Memory

+------------------+   High address
|      Stack       |   ← Function calls, local variables (grows down)
|        ↓         |
|                  |
|        ↑         |
|       Heap       |   ← Dynamic memory (malloc, new)
+------------------+
|    BSS Segment   |   ← Uninitialized global/static variables
+------------------+
|    Data Segment  |   ← Initialized global/static variables
+------------------+
|    Text Segment  |   ← Program code (instructions)
+------------------+   Low address

Process Creation

In Unix/Linux:

pid_t child_pid = fork();  // Creates child process (copy of parent)
if (child_pid == 0) {
    // This is the child process
    exec("new_program");   // Replace with different program
} else {
    wait(NULL);            // Parent waits for child to finish
}

Process hierarchy — Process Tree:

init (PID 1)
├── systemd
│   ├── sshd
│   │   └── bash (user session)
│   │       └── vim
│   └── cron
│       └── backup_script.sh
└── kthreadd (kernel threads)

What is an Operating System?

Why is an OS Needed?

Basic functions of a computer:

  1. Data Storage — save data to storage devices

Data Processing — compute and transform data 3. Data Movement — transfer data between components 4. Control — coordinate all operations

Problem: Any user cannot communicate/interact directly with computer hardware to do different tasks. There is a need for some interface between user and hardware.

Solution: The Operating System

Definition of Operating System

An Operating System (OS) is system software that:

  • Manages computer hardware and software resources
  • Provides a common interface between users and hardware
  • Controls and coordinates use of hardware among various application programs for various users
  • Acts as a resource manager — allocates CPU, memory, I/O to processes

OS as an Intermediary

Applications (User Programs)
           ↕
    OPERATING SYSTEM
           ↕
      Hardware (CPU, Memory, I/O)

Popular Operating Systems

OSFamilyUse Case
Windows 11MicrosoftDesktop, Gaming
Ubuntu / DebianLinuxDevelopment, Server
macOSApple/UnixCreative, Development
AndroidLinux-basedMobile
iOSAppleMobile
UnixAT&T Bell LabsServer, Academic
LinuxOpen-source Unix-likeServer, Embedded

Functions of an Operating System

FunctionDescription
Process ManagementCreate, schedule, terminate processes; handle synchronization
Memory ManagementAllocate/deallocate memory; virtual memory management
File ManagementCreate/delete files and directories; access control
I/O ManagementControl I/O devices; provide device driver interface
Security & ProtectionProtect resources from unauthorized access
NetworkingTCP/IP stack; network communication
Error Detection & HandlingDetect hardware errors; take corrective action
User InterfaceCLI (command line) or GUI (graphical) interface

Continue learning

Related notes

Put this topic into timed practice

Open mock tests when you want full-exam pacing, or keep drilling in practice mode.