Operating Systems & Linux
DSSSB TGT CS — Section B P2 (Rank ~8). Focus: definitions, scheduling tables, deadlock, memory, Linux commands.
1. OS Functions
- Process management — create, schedule, terminate processes/threads
- Memory management — allocate/deallocate RAM
- File management — create, read, write, permissions
- Device / I/O management — drivers, buffering
- Security & protection — users, access control
- User interface — CLI / GUI / shell
- Resource sharing, error detection, accounting
OS = interface between user/applications and hardware.
2. Types of OS
| Type | Idea |
|---|---|
| Batch | Jobs collected, run without interaction |
| Multiprogramming | Multiple programs in memory; CPU switches on I/O wait → higher utilization |
| Time-sharing / multitasking | Time slices; interactive users |
| Real-time (RTOS) | Deadlines matter (hard/soft) |
| Distributed | Multiple machines appear as one |
| Network OS | Share resources over network |
| Mobile OS | Android, iOS |
- Trap: Multiprogramming ≠ multiprocessing. Multiprocessing = multiple CPUs/cores.
3. Process States
Typical states:
New → Ready → Running → Terminated
Also: Waiting/Blocked (I/O), sometimes Suspended.
| Transition | Cause |
|---|---|
| Ready → Running | Scheduler dispatch |
| Running → Ready | Time slice / preemption |
| Running → Waiting | I/O or event wait |
| Waiting → Ready | I/O complete |
4. PCB (Process Control Block)
Kernel data structure storing process info:
- Process ID (PID), state, priority
- Program counter, CPU registers
- Memory limits / page tables
- Open files, I/O status
- Accounting info
Context switch = save/restore PCB-related CPU state.
5. CPU Scheduling
| Algorithm | Rule | Preemptive? | Notes |
|---|---|---|---|
| FCFS | Arrival order | No | Convoy effect |
| SJF | Shortest burst next | Non-preemptive | Optimal avg waiting (known bursts) |
| SRTF | Shortest remaining | Yes | Preemptive SJF |
| Round Robin (RR) | Time quantum q | Yes | Fair; q too small → overhead |
| Priority | Highest priority first | Can be either | Starvation → aging |
Comparison (exam)
| Metric focus | Prefer |
|---|---|
| Fairness / interactive | RR |
| Min avg waiting (theory) | SJF |
| Simple | FCFS |
| Importance-based | Priority |
- Trap: SJF needs burst time estimates; RR response depends on quantum.
6. Deadlock
Necessary conditions (Coffman) — all four:
- Mutual exclusion
- Hold and wait
- No preemption
- Circular wait
Break any one → deadlock impossible.
| Approach | Idea |
|---|---|
| Prevention | Negate a condition |
| Avoidance | Safe state (e.g. Banker's algorithm) |
| Detection + recovery | Find cycle; kill/rollback |
| Ignore | Ostrich approach |
Banker's idea: Allocate only if system stays in a safe sequence (can finish all with remaining resources).
7. Memory Management
| Concept | Idea |
|---|---|
| Contiguous | Single block (fixed/variable partitions) |
| Paging | Fixed-size pages ↔ frames; no external fragmentation |
| Segmentation | Logical segments (code, data, stack); variable size |
| Virtual memory | Process address space > physical RAM via disk |
| Thrashing | Too much paging; little useful work |
- Page table maps logical page → physical frame.
- Trap: Paging → internal fragmentation; segmentation → external fragmentation.
8. Page Replacement
| Algorithm | Rule |
|---|---|
| FIFO | Replace oldest page |
| LRU | Replace least recently used |
| OPT / Belady’s optimal | Replace page used farthest in future (theoretical) |
- Belady’s anomaly: more frames can increase faults for FIFO.
- LRU approximates OPT; OPT is benchmark only.
9. File Systems
- File = named collection of related data
- Directory structure: single-level, two-level, tree, DAG
- Operations: create, delete, open, close, read, write
- Allocation: contiguous, linked, indexed
- Access: sequential vs random
- Linux common FS: ext4, also XFS, Btrfs; Windows: NTFS, FAT
10. Linux Basics
| Layer | Role |
|---|---|
| Kernel | Core: hardware, processes, memory, drivers |
| Shell | Command interpreter (bash, sh, zsh) |
| Utilities / apps | User programs |
- Linux is multiuser, multitasking, Unix-like.
- Root (
UID 0) = superuser; full privileges — use carefully.
11. Essential Commands
| Command | Use |
|---|---|
ls | List directory |
cd | Change directory |
pwd | Print working directory |
mkdir | Make directory |
rm | Remove file/dir (-r recursive) |
cp | Copy |
mv | Move / rename |
cat | Display file contents |
grep | Search pattern in text |
chmod | Change permissions |
chown | Change owner |
ps | Process status |
kill | Send signal to process (e.g. terminate) |
Paths
| Type | Example |
|---|---|
| Absolute | Starts at / → /home/user/a.txt |
| Relative | From current dir → docs/a.txt, ../b |
/= root of filesystem tree (not the same concept as root user, but related naming).- Home often
/home/username; root user’s home/root.
Permissions (chmod idea)
rwxfor user/group/others; numeric e.g.755,644.chmod 755 file— common exam pattern.
Quick Revision Traps
- Multiprogramming (many jobs in memory) vs multiprocessing (many CPUs).
- Deadlock needs all four Coffman conditions.
- Banker's → safe state avoidance, not prevention of all conditions.
- Thrashing = excessive paging.
- FIFO can show Belady’s anomaly; LRU/OPT do not (classic claim).
- Absolute path starts with
/. rootuser ≠ filesystem root/(related but distinct).- RR quantum too small → context-switch overhead.