cswork / OAOpen practice workspace

OA ARITHMETIC · STEP BY STEP

Work it by hand, then step through it.

OA multiple choice often needs arithmetic by hand: average waiting time, page faults, a safe sequence, cwnd, the seq and ack of a handshake. These six simulators work it out step by step, and each takes the numbers from your question so you can check your own working.

CPU scheduling: draw the Gantt chart, average the waits

OA questions give three to five processes with arrival and burst times and ask for the average waiting or turnaround time under one policy. Change the policy (fcfs, sjf, srtf, rr plus a quantum, prio, prio-p) or the processes, and see stretch by stretch why each process gets the CPU.

Interactive demo · step by step

CPU scheduling · Gantt chart

Round robin (RR) q=2: what is the average waiting time?

Try your own input
CurrentDiscovered / computedAnswer
Ready queue (process:time left)
Empty
A
arrives 0 · burst 5
B
arrives 1 · burst 3
C
arrives 2 · burst 1
D
arrives 3 · burst 2

Round robin (RR) q=2: 4 processes. Each cell is one stretch on the CPU, with its start and end time below.

InvariantTurnaround = finish − arrival, waiting = turnaround − burst, response = first run − arrival. Ties go by input order; a smaller priority number runs first; in RR a process arriving as a quantum ends queues ahead of the preempted one.

Page replacement: count the faults

With the default reference string, FIFO faults 9 times with 3 frames and 10 times with 4: Belady’s anomaly. Switch to lru, opt or clock to compare; the last step lists all four algorithms’ faults and the fault curve for 1 to 7 frames.

Interactive demo · step by step

Page replacement · count the faults

With 3 frames and FIFO, how many page faults does 1 2 3 4 1 2 5 1 2 3 4 5 cause?

Try your own input
1#1
2#2
3#3
4#4
1#5
2#6
5#7
1#8
2#9
3#10
4#11
5#12
F1
F1
F1
F1
F1
F1
F1
F1
F1
F1
F1
F1
F2
F2
F2
F2
F2
F2
F2
F2
F2
F2
F2
F2
F3
F3
F3
F3
F3
F3
F3
F3
F3
F3
F3
F3
CurrentDiscovered / computedAnswer
Faults
0
Hits
0

3 frames, all empty to start. The top row is the reference string; each row below is a frame, and each column shows memory after that access.

InvariantFIFO evicts the page loaded first; LRU the one used least recently; OPT the one used furthest ahead; Clock keeps a bit per page (set on load and on a hit) and on a fault sweeps the hand, clearing set bits, to evict the first clear one. LRU and OPT are stack algorithms, so more frames never mean more faults; FIFO and Clock are not and can show Belady’s anomaly.

Banker’s algorithm: find a safe sequence

Work out Need = Max − Allocation, then use Work to find, round by round, a process that can finish. With a request such as P1 1 0 2, it is first checked against Need and Available, then granted on trial and checked for safety.

Interactive demo · step by step

Banker's algorithm · safe sequence

P1 asks for (1, 0, 2). Can it be granted?

Try your own input
P0Need
7A
4B
3C
P1Need
1A
2B
2C
P2Need
6A
0B
0C
P3Need
0A
1B
1C
P4Need
4A
3B
1C
CurrentDiscovered / computedAnswer
Safe sequence so far
Empty
Available
(3, 3, 2)
Work
—
Request
P1 (1, 0, 2)

Each row is a process's Need = Max − Allocation: how much of resources A, B, C it still needs to finish. Available = (3, 3, 2).

InvariantEach round scans from P0 and picks the first process whose Need ≤ Work; it finishes and returns its Allocation: Work += Allocation. The state is safe only if every process can finish. A request must satisfy Request ≤ Need and Request ≤ Available, then is granted on trial and checked for safety. There can be several safe sequences; this one follows the scan-from-P0 rule.

TCP three-way handshake and four-way close

Every step’s seq, ack and both states sit on the sequence diagram. Try syn-loss (the first SYN is lost and resent) or simul-close (both sides close at once and pass through CLOSING).

Interactive demo · step by step

TCP connection · handshake and close

How do seq, ack and both states change through the handshake and the close?

Try your own input
CCLOSEDSLISTEN
CurrentDiscovered / computedAnswer
Client
CLOSED
Server
LISTEN
Segments
—

The server opens passively and enters LISTEN; the client is CLOSED. Initial sequence numbers: client x = 100, server y = 300.

InvariantC is the client, S the server, and time runs downward. SYN and FIN each use one sequence number, so the ack for one is the peer’s seq + 1; an ack always names the next sequence number expected. The side that closes first ends in TIME_WAIT and waits 2MSL before it closes.

Congestion control: the cwnd curve

Give the initial ssthresh, the number of rounds and the rounds with a timeout or three duplicate ACKs (dup), and get cwnd round by round. On three duplicate ACKs, Reno here sets cwnd to the new ssthresh, the common textbook shortcut; RFC 5681’s fast recovery starts at ssthresh + 3.

Interactive demo · step by step

Congestion control · Reno's cwnd

Starting from ssthresh = 8, what is cwnd in each round?

Try your own input
ssthresh1
1#1
CurrentDiscovered / computedAnswer
cwnd
1
ssthresh
8
Phase
slow start
Round
1 / 20

Round 1: cwnd = 1 < ssthresh = 8, slow start doubles it each round: next round 2.

Invariantcwnd starts at 1. Below ssthresh, slow start doubles it each round without passing ssthresh; from there congestion avoidance adds 1 a round. Timeout: ssthresh = max(⌊cwnd/2⌋, 2), cwnd = 1. Three duplicate ACKs: Tahoe acts as on a timeout; Reno takes cwnd = the new ssthresh, the textbook shortcut (RFC 5681 enters fast recovery at ssthresh + 3). The green line is ssthresh; red dots mark the rounds with an event.

Sliding window: Go-Back-N and Selective Repeat

Lose the same packet: Go-Back-N resends everything from it, Selective Repeat resends only that one. Change the first part to sr and compare the number of sends. In TCP this window is the smaller of the receiver’s advertised window (flow control) and the congestion window (congestion control).

Interactive demo · step by step

Sliding window · Go-Back-N and Selective Repeat

Go-Back-N with window 4: how many transmissions does it take to deliver 10 packets?

Try your own input
0usable
1usable
2usable
3usable
4not yet
5not yet
6not yet
7not yet
8not yet
9not yet
CurrentDiscovered / computedAnswer
This step’s packets (× lost) or ACKs
Empty
base
0
next
0
Receiver expects
0
Sends / resends
0 / 0

Go-Back-N: 10 packets, window 4; packet 3 is lost the first time it is sent. Blue is the send window [base, base + 4): packets in it go out without waiting for ACKs.

InvariantThe sender may only send packets in [base, base + window). A GBN receiver accepts only in-order packets and acknowledges the last of them cumulatively; on a timeout the sender resends everything from base. An SR receiver buffers out-of-order packets and acknowledges each one; only the timed-out packet is resent. One round is one round trip, and an unacknowledged packet times out at the end of the next round; sequence numbers never wrap (real SR needs a window of at most half the sequence space). In TCP the send window is also capped by the receive window (rwnd) the receiver advertises in its ACKs, so it is min(cwnd, rwnd): rwnd keeps the sender from overflowing the receiver’s buffer (flow control), cwnd keeps it from congesting the network (congestion control).