You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: stage_descriptions/background-jobs-09-fy4.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,14 +2,14 @@ In this stage, you'll implement recycling job number indices.
2
2
3
3
### Recycling Job Numbers
4
4
5
-
Job numbers are assigned sequentially: `1`, `2`, `3`, and so on. When jobs are completed and removed from the table, the next new job reuses the smallest available number. So the next job number depends on how many jobs are still in the table:
5
+
Normally, job numbers are assigned sequentially: `1`, `2`, `3`, and so on. However, when jobs finish, they are removed from the job table, allowing job numbers to be reused.
6
6
7
-
- When all jobs have completed, and the table is empty, the next job gets `[1]`.
8
-
- If some jobs remain, the next job gets the smallest available number.
7
+
When assigning a new job number:
9
8
10
-
For example, if you have jobs `[1]` and `[3]` running, the next job gets `[2]`, not `[4]`.
9
+
- If the job table is empty, assign `[1]`.
10
+
- Otherwise, assign one more than the highest job number currently in the table.
11
11
12
-
Here are some more examples:
12
+
Here are some examples:
13
13
14
14
```bash
15
15
# Recycling to 1 when the table is empty
@@ -65,7 +65,7 @@ $ jobs
65
65
[1]+ Running sleep 100 &
66
66
```
67
67
68
-
The tester will also restart your program and verify number reuse when a gap exists:
68
+
The tester will also restart your program and verify number reuse when a job exits:
69
69
```bash
70
70
$ sleep 100 &
71
71
[1] <pid>
@@ -93,5 +93,4 @@ The tester will verify that:
93
93
### Notes
94
94
95
95
- Job numbers are recycled—they don't grow forever. After job 2 exits, the next job is `[2]`, not `[3]`.
96
-
- Always assign the smallest available number, not just the next sequential number.
0 commit comments