|
117 | 117 |
|
118 | 118 | switch (cmd) { |
119 | 119 | case "help": |
120 | | - await typeLine("Available mock commands: help, man, ls, cat, echo, busy, sleep, ps, jobs, fg, clear"); |
| 120 | + await typeLine("Available mock commands: help, man, ls, cat, echo, sleep, ps, jobs, fg, clear"); |
121 | 121 | break; |
122 | 122 | case "man": |
123 | 123 | if (args[1] === "ps") { |
124 | 124 | await typeLine("ps - report a snapshot of the current processes."); |
125 | 125 | await typeLine("Columns:"); |
126 | 126 | await typeLine(" PID - Process ID"); |
127 | 127 | await typeLine(" PPID - Parent Process ID"); |
128 | | - await typeLine(" PRI - Priority (-1, 0, 1)"); |
129 | 128 | await typeLine(" STAT - State (R: running, S: stopped, Z: zombie, B: blocked)"); |
130 | 129 | await typeLine(" CMD - Command line"); |
131 | 130 | } else if (args[1] === "ls") { |
|
134 | 133 | await typeLine("cat - concatenate files and print on the standard output. Usage: cat [file]"); |
135 | 134 | } else if (args[1] === "echo") { |
136 | 135 | await typeLine("echo - print text back to the terminal."); |
137 | | - } else if (args[1] === "busy") { |
138 | | - await typeLine("busy - simulate a CPU-bound job. Usage: busy [priority] [&]"); |
139 | 136 | } else if (args[1] === "sleep") { |
140 | 137 | await typeLine("sleep - simulate a sleeping job for n seconds. Usage: sleep n [&]"); |
141 | 138 | } else if (args[1] === "jobs") { |
|
177 | 174 | case "clear": |
178 | 175 | output.innerHTML = ""; |
179 | 176 | break; |
180 | | - case "sleep": |
181 | | - case "busy": { |
| 177 | + case "sleep": { |
182 | 178 | const isBg = args[args.length - 1] === "&"; |
183 | | - const dur = cmd === "sleep" ? (parseInt(args[1]) || 2) : 3; |
| 179 | + const dur = parseInt(args[1]) || 2; |
184 | 180 | const pid = pidCounter++; |
185 | 181 |
|
186 | 182 | if (isBg) { |
|
194 | 190 | if (j) j.state = "Done"; |
195 | 191 | }, dur * 1000); |
196 | 192 | } else { |
197 | | - if (cmd === "sleep") { |
198 | | - await new Promise(r => setTimeout(r, dur * 1000)); |
199 | | - } else { |
200 | | - await typeLine(`busy: running in foreground (mocked to run ${dur}s)...`); |
201 | | - await new Promise(r => setTimeout(r, dur * 1000)); |
202 | | - } |
| 193 | + await new Promise(r => setTimeout(r, dur * 1000)); |
203 | 194 | } |
204 | 195 | break; |
205 | 196 | } |
206 | 197 | case "ps": |
207 | | - await typeLine(" PID PPID PRI STAT CMD"); |
208 | | - await typeLine(" 1 0 0 B init"); |
209 | | - await typeLine(" 2 1 0 S shell"); |
| 198 | + await typeLine(" PID PPID STAT CMD"); |
| 199 | + await typeLine(" 1 0 B init"); |
| 200 | + await typeLine(" 2 1 S shell"); |
210 | 201 | for (const j of jobs) { |
211 | 202 | if (j.state !== "Done") { |
212 | 203 | const stat = j.type === 'sleep' ? 'S' : 'R'; |
213 | | - await typeLine(` ${j.pid.toString().padStart(3)} 2 1 ${stat} ${j.cmd}`); |
| 204 | + await typeLine(` ${j.pid.toString().padStart(3)} 2 ${stat} ${j.cmd}`); |
214 | 205 | } |
215 | 206 | } |
216 | | - await typeLine(` ${pidCounter.toString().padStart(3)} 2 1 R ps`); |
| 207 | + await typeLine(` ${pidCounter.toString().padStart(3)} 2 R ps`); |
217 | 208 | pidCounter++; |
218 | 209 | break; |
219 | 210 | case "jobs": |
|
0 commit comments