Exam Prep — OS · Linux · Shell · FCFS

Quiz 30 · Performance Test 15 (Linux 5, Shell 5, FCFS 5) · Viva 10

1. Operating System — the essentials

An OS is the core software that manages a computer's hardware and lets you run applications.

What it does

  • Manages hardware — CPU, RAM, storage
  • Runs apps — browsers, games, software
  • User interface — screen, icons, menus
  • Handles files — save/delete/organize
  • Controls devices — keyboard, mouse, printer

Examples

  • Windows — laptops/PCs
  • Android — phones/tablets
  • iOS — Apple iPhones only
  • macOS — Apple Mac/iMac
  • Linux — free, open-source, servers & dev

2. Linux Architecture

Linux is a Unix variant: open-source, multi-user. It's the link between the computer and the end user.

LayerWhat it is
KernelThe heart of Linux. Talks directly to hardware: memory management, task scheduling, file management.
ShellSoftware layer wrapped around the kernel — a command-line interpreter that turns your text commands into something the kernel understands.
CommandA specific text instruction typed into the shell.
Files & DirsAll data is organized into files, files into directories, directories into a tree-like filesystem.

Order to remember: Hardware → Kernel → Shell → Application Programs (bash, ksh, csh, sh, cpp, DBMS...).

Why Linux over Windows?

  • 100% free & open source — no license keys
  • Lightweight & fast on old hardware
  • High security, resistant to malware
  • No forced updates — you control reboot timing
  • Total customization of visuals/settings
  • Privacy — no tracking

The 3 types of Linux users

User TypePromptLogin allowed?Typical UID
Root User#Yes0
Regular User$Yes1000+
System UserNoneNo1–999

3. Linux Command Reference (full cheat sheet)

CommandMeaning
pwdPrint current directory path
pwd -PPhysical path, resolves symlinks
cd folderMove into folder (relative)
cd /a/bMove using absolute path
cd ..Up one level
cd ../..Up two levels
cd ~ / cdJump to home folder
cd -Toggle back to previous directory
lsBasic horizontal listing
ls -1One entry per line
ls -lLong format: size, owner, perms, timestamp
ls -laLong format + hidden files
ls -lhHuman-readable sizes (K/M/G)
ls -ltSort by modified time, newest first
ls -lSSort by size, largest first
ls -RRecursive, walks every sub-folder
man cmdFull manual page
man -k wordSearch manual descriptions by keyword
mkdir nameCreate one folder
mkdir d1 d2 d3Create multiple folders at once
mkdir -p a/b/cAuto-create missing parent folders
mkdir -v nameVerbose confirmation message
rmdir nameRemove folder only if empty
rmdir -p a/b/cRemove folder + empty parents
cat fileDump file contents to screen
cat -n fileShow with line numbers
cat -b fileNumber only non-empty lines
cat f1 f2 > outMerge f1+f2 into new file out
cat > new.txtType text, save with Ctrl+D
touch fileCreate empty file / update timestamp
touch -c fileUpdate timestamp only if file exists
cp src dstCopy a file
cp -r dir1 dir2Copy directory recursively
cp -iWarn before overwrite
cp -vVerbose, show what's copied
mv old newRename file/folder
mv file folder/Move file into folder
mv -iPrompt before overwrite
mv -nNever overwrite existing files
rm fileDelete a file permanently
rm -r folderDelete folder + contents
rm -iConfirm each deletion
rm -fForce, ignore missing files/prompts
rm -rf folderInstant forceful wipe — dangerous!

Go drill these for real in the Terminal Practice tab — typing builds muscle memory faster than reading.

4. Shell Scripting — quick reference

  • A shell script is a text file of commands the shell interprets, instead of typing directly in the terminal.
  • Create with touch hello.sh. First line must be the shebang: #!/bin/bash.
  • Print text with echo "Hello!"
  • Variables: name=mark (no spaces around =), read with $name. Names must start with a letter/underscore — 10val=10 is invalid.

Full drills with typing practice are in the Shell Scripting tab.

5. FCFS Scheduling — quick reference

  • FCFS = First Come First Serve, non-preemptive: whichever process arrives first runs first, and once started it runs to completion.
  • CT (Completion Time) = time process finishes
  • TAT (Turnaround Time) = CT − AT
  • WT (Waiting Time) = TAT − BT
  • Algorithm: read processes → sort by arrival time → run each to completion → compute CT/TAT/WT → repeat.
  • If CPU is idle when a process arrives (current_time < AT), jump current_time forward to AT.
  • Advantages: simple, fair order, no starvation, low overhead, good for batch systems.
  • Disadvantages: convoy effect (long process blocks short ones), high average wait, poor response time, non-preemptive, bad for time-sharing.
  • Time complexity: best case O(n) if already sorted by AT; worst case O(n log n) if sorting is needed first.

Full calculator + pseudocode + C++ code are in the FCFS Lab tab — practice writing the code by hand for the performance test.

Live Terminal Simulator

This is a real (simulated) Linux shell — type actual commands and see actual results. Work through the challenge list on the right in order; it checks what you typed and tells you if you got it right. Everything you type also actually changes the file tree, so mistakes behave like a real terminal.

[althofa@oslab ~]$

Try: help for the full supported command list.

Shell Scripting — study & typing drills

Variables

name=mark
echo $name              # mark
echo "The name is $name"

val10=10                # OK, starts with a letter
echo $val10

10val=10                # ERROR: cannot start with a digit

Reading Input

read name1 name2 name3
echo "Names: $name1, $name2, $name3"

read -p "Username: " user_var     # prompt + input, one line
read -sp "Password: " pass_var    # -s hides typed characters

echo "Enter names: "
read -a names                     # -a reads into an array
echo "${names[0]}, ${names[1]}"

echo "Enter something: "
read                               # no varname -> goes into $REPLY
echo "Your input was: $REPLY"

If / Elif / Else

#!/bin/bash
word="b"

if [ $word == "a" ]
then
    echo "Condition A is true"
elif [ $word == "b" ]
then
    echo "Condition B is true"
else
    echo "No condition matched"
fi

Loops

# while loop
n=1
while [ $n -le 10 ]
do
    echo "$n"
    n=$(( n + 1 ))
done

# C-style for loop
for (( i=0; i<5; i++ ))
do
    echo "$i"
done

# break: stop once i > 5
for (( i=1; i<=10; i++ ))
do
    if [ $i -gt 5 ]; then break; fi
    echo "$i"
done

# continue: skip 3 and 6
for (( i=1; i<=10; i++ ))
do
    if [ $i -eq 3 -o $i -eq 6 ]; then continue; fi
    echo "$i"
done

Functions

# Rule 1: parentheses
my_function() {
    echo "Hello"
}

# Rule 2: function keyword
function my_function {
    echo "Hello"
}

# Passing arguments: $1, $2, $3 ...
print_args() {
    echo $1 $2
}
print_args "Hello" "World"      # -> Hello World

Type it yourself — muscle memory drills

Each drill shows a task; type the exact line of shell code in the box and press Check. This builds the same recall you'll need on paper tomorrow.

0 / 10 mastered

FCFS Calculator — build the table yourself

Enter Arrival Time (AT) and Burst Time (BT) for each process (order doesn't matter — it'll sort by AT like the real algorithm), then compute. This mirrors exactly what you'll do on paper in the performance test.

Quick practice sets:

Pseudocode (memorize this structure)

ALGORITHM FCFS_Scheduling
BEGIN
    Input n (number of processes)
    Input Process details (id, AT, BT)

    Sort Process array P in ascending order of P[i].AT

    current_time = 0
    total_TAT = 0
    total_WT = 0

    FOR i = 0 TO n-1 DO
        IF current_time < P[i].AT THEN
            current_time = P[i].AT     // CPU was idle
        END IF

        P[i].CT = current_time + P[i].BT
        current_time = P[i].CT

        P[i].TAT = P[i].CT - P[i].AT
        P[i].WT  = P[i].TAT - P[i].BT

        total_TAT = total_TAT + P[i].TAT
        total_WT  = total_WT + P[i].WT
    END FOR

    Print Process details (id, AT, BT, CT, TAT, WT)
    Print "Average TAT" = total_TAT / n
    Print "Average WT"  = total_WT / n
END

C++ reference code (two versions you might be asked for)

Version A — struct + std::sort (from lecture note)

#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

struct Process { int id, at, bt, ct, tat, wt; };

bool compareArrival(Process p1, Process p2) { return p1.at < p2.at; }
bool compareID(Process p1, Process p2) { return p1.id < p2.id; }

int main() {
    int n;
    cout << "Enter number of processes: ";
    cin >> n;

    Process p[n];
    float total_tat = 0, total_wt = 0;

    for (int i = 0; i < n; i++) {
        p[i].id = i + 1;
        cout << "Enter AT and BT for P" << p[i].id << ": ";
        cin >> p[i].at >> p[i].bt;
    }

    sort(p, p + n, compareArrival);

    int current_time = 0;
    for (int i = 0; i < n; i++) {
        if (current_time < p[i].at) current_time = p[i].at;
        p[i].ct = current_time + p[i].bt;
        current_time = p[i].ct;

        p[i].tat = p[i].ct - p[i].at;
        p[i].wt  = p[i].tat - p[i].bt;

        total_tat += p[i].tat;
        total_wt  += p[i].wt;
    }

    sort(p, p + n, compareID);

    cout << "\nProcess\tAT\tBT\tCT\tTAT\tWT\n";
    for (int i = 0; i < n; i++) {
        cout << "P" << p[i].id << "\t" << p[i].at << "\t" << p[i].bt << "\t"
             << p[i].ct << "\t" << p[i].tat << "\t" << p[i].wt << "\n";
    }

    cout << fixed << setprecision(2);
    cout << "\nAverage TAT: " << total_tat / n << "\n";
    cout << "Average WT: "  << total_wt / n  << "\n";
    return 0;
}

Version B — parallel arrays + bubble sort (from your own notes)

#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    string s[100];
    int at[100], bt[100];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i] >> at[i] >> bt[i];

    // bubble sort by arrival time
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - i - 1; j++) {
            if (at[j] > at[j + 1]) {
                swap(at[j], at[j + 1]);
                swap(bt[j], bt[j + 1]);
                swap(s[j], s[j + 1]);
            }
        }
    }

    int ct = 0, tat = 0, wt = 0;
    cout << "process\tAt\tBt\tCt\tTAT\tWT\n";
    for (int i = 0; i < n; i++) {
        ct += bt[i];
        tat = ct - at[i];
        wt  = tat - bt[i];
        cout << s[i] << "\t\t" << at[i] << "\t" << bt[i] << "\t" << ct << "\t" << tat << "\t" << wt << endl;
    }
    return 0;
}

Note: Version B assumes zero idle CPU time (it just accumulates ct += bt[i]) — it works only when processes queue back-to-back with no gaps. Version A correctly handles idle-CPU gaps. Know both, but understand why A is more general — that's a likely viva question.

MCQ Quiz Bank

Practice by topic, or sit a timed 30-question mock that mirrors tomorrow's Quiz section exactly.

Score: 0 / 0

Pick a mode above to drill again — order and options reshuffle every time.

Viva Prep — flashcards

The viva draws questions from all 4 PDFs. Read the question, say your answer out loud, then reveal to check. Do a "Random 10" pass first, then "Show all" once you're confident.