Loading…
Operating Systems
echo "Enter a number:"
read n
echo "You typed $n"
read a b # two values on one line
read -p "Name: " namesum=$((a + b))
rem=$((n % 10))
let c=a*b
x=$(expr $a + $b)
# decimals need bc:
area=$(echo "scale=2; 3.14 * $r * $r" | bc)if [ $n -gt 0 ]
then
echo "positive"
elif [ $n -eq 0 ]
then
echo "zero"
else
echo "negative"
fifor ((i = 1; i <= 10; i++))
do
echo $i
done
while [ $n -gt 0 ]
do
n=$((n - 1))
done
for f in a b c; do echo $f; donecase $choice in
1) echo "one" ;;
2) echo "two" ;;
*) echo "invalid" ;;
esacsquare() {
local x=$1
echo $((x * x))
}
res=$(square 5)
arr=(10 20 30)
echo ${arr[0]} ${arr[@]} ${#arr[@]}Spaces matter: [ $a -gt $b ] works, [$a -gt $b] does not.
| Operator | Meaning |
|---|---|
| -eq / -ne | equal / not equal |
| -gt / -ge | greater than / greater or equal |
| -lt / -le | less than / less or equal |
| = / != (strings) | string equal / not equal |
| -z $s / -n $s | string is empty / not empty |
| -f file / -d dir | file exists / directory exists |
| && / || | and / or between tests |
| Command | What it does |
|---|---|
| pwd, ls -l, cd dir, cd .. | where am I, list, move around |
| mkdir d, rmdir d, rm -r d | make / remove folders |
| touch f, cp a b, mv a b, rm f | create, copy, move or rename, delete |
| cat f, head -n 5 f, tail f, wc -l f | show, first / last lines, count lines |
| echo hi > f, echo hi >> f | overwrite, append |
| grep -i 'x' f, grep -v, grep -c | search (ignore case), invert, count |
| sed 's/old/new/g' f | find and replace on every line |
| sort f | uniq, cut -d, -f1 | sort, de-duplicate, pick columns |
| chmod +x s.sh, chmod 755 f | permissions (r=4 w=2 x=1) |
| ps, top, kill PID, & | processes, stop one, run in background |
| cal 7 2026, date, whoami, uname -a | calendar, date, user, system info |
| xclock, oclock | graphical clocks (need X11) |
Programs 15, 16 and 31 assume every process arrives at time 0. Program 32 is the Banker's algorithm; 33 is First / Best / Worst Fit.
| Formula | Meaning |
|---|---|
| TAT = CT − AT | turnaround = completion − arrival |
| WT = TAT − BT | waiting = turnaround − burst |
| RT = first run − AT | response time |
| FCFS (AT = 0) | wt[i] = wt[i−1] + bt[i−1] |
| Average | sum of WT (or TAT) ÷ n |
| Round Robin | run min(q, remaining); unfinished → back of queue |
| Banker's: Need | Need = Max − Allocation |
| Banker's: safe | Need ≤ Work → Work = Work + Allocation |
| First / Best / Worst Fit | first big-enough / smallest that fits / largest block |
chmod +x 01_add.sh # once
./01_add.sh # or: bash 01_add.sh
gcc 15_fcfs.c -o fcfs
./fcfs