Part 4 of 6 · 3 min read
Three clocks
In plain words: Three customers in a queue measure their experience differently: the time until they leave the shop, the time spent standing in the line, and the time until the first word from a clerk. The analogy stops in one place: a process in line may be moved ahead or behind by the scheduler, and a customer cannot.
Three times are measured for each process, all from the process's arrival time, the moment it enters the ready queue for the first time:
- Turnaround time = finish time − arrival time. The whole stay in the system.
- Waiting time = turnaround time − total CPU time. The time spent ready but not running. (This assumes no I/O waits; in the examples here, the process only computes.)
- Response time = first start time − arrival time. The time before the process first gets the processor.
Here is a workload that is used on pages 2 to 4. Four processes arrive at different times, each needing the CPU for a fixed number of time units. The processes are made up to show the idea.
| Process | Arrival | CPU time |
|---|---|---|
| A | 0 | 5 |
| B | 1 | 3 |
| C | 2 | 8 |
| D | 3 | 2 |
Run them in the order of arrival, one after another without interruption. The processor timeline is A from 0 to 5, B from 5 to 8, C from 8 to 16, and D from 16 to 18. The three times follow:
| Process | Finish | Turnaround | Waiting | Response |
|---|---|---|---|---|
| A | 5 | 5 − 0 = 5 | 5 − 5 = 0 | 0 − 0 = 0 |
| B | 8 | 8 − 1 = 7 | 7 − 3 = 4 | 5 − 1 = 4 |
| C | 16 | 16 − 2 = 14 | 14 − 8 = 6 | 8 − 2 = 6 |
| D | 18 | 18 − 3 = 15 | 15 − 2 = 13 | 16 − 3 = 13 |
The averages are 41 ÷ 4 = 10.25 for turnaround, 23 ÷ 4 = 5.75 for waiting and 23 ÷ 4 = 5.75 for response. Here the waiting and response times are equal, since each process runs once without interruption. They differ as soon as a process is interrupted.
D is the shortest job but waited the longest, 13 units, because it came after the long process C. This behaviour has a name on page 2.
Turnaround time, waiting time and response time
Turnaround time is the time from a process's arrival to its completion. Waiting time is the part of that time spent in the ready queue, not running. Response time is the time from arrival to the first moment the process runs.
Example: process B above arrives at 1, first runs at 5 and ends at 8, so its turnaround time is 7, its waiting time is 4 and its response time is 4.
Check yourself: 1. Compute the waiting time of C from the table, starting from its arrival and finish. 2. Why are waiting and response time equal when a process is never interrupted? 3. Which of the three does a person at a keyboard notice most?