Skip to content

Commit 765ffd8

Browse files
committed
fix(pennos): simplify shell process control and documentation
1 parent 8bc4f06 commit 765ffd8

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

src/components/demos/TerminalDemo.astro

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,14 @@
117117

118118
switch (cmd) {
119119
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");
121121
break;
122122
case "man":
123123
if (args[1] === "ps") {
124124
await typeLine("ps - report a snapshot of the current processes.");
125125
await typeLine("Columns:");
126126
await typeLine(" PID - Process ID");
127127
await typeLine(" PPID - Parent Process ID");
128-
await typeLine(" PRI - Priority (-1, 0, 1)");
129128
await typeLine(" STAT - State (R: running, S: stopped, Z: zombie, B: blocked)");
130129
await typeLine(" CMD - Command line");
131130
} else if (args[1] === "ls") {
@@ -134,8 +133,6 @@
134133
await typeLine("cat - concatenate files and print on the standard output. Usage: cat [file]");
135134
} else if (args[1] === "echo") {
136135
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] [&]");
139136
} else if (args[1] === "sleep") {
140137
await typeLine("sleep - simulate a sleeping job for n seconds. Usage: sleep n [&]");
141138
} else if (args[1] === "jobs") {
@@ -177,10 +174,9 @@
177174
case "clear":
178175
output.innerHTML = "";
179176
break;
180-
case "sleep":
181-
case "busy": {
177+
case "sleep": {
182178
const isBg = args[args.length - 1] === "&";
183-
const dur = cmd === "sleep" ? (parseInt(args[1]) || 2) : 3;
179+
const dur = parseInt(args[1]) || 2;
184180
const pid = pidCounter++;
185181

186182
if (isBg) {
@@ -194,26 +190,21 @@
194190
if (j) j.state = "Done";
195191
}, dur * 1000);
196192
} 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));
203194
}
204195
break;
205196
}
206197
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");
210201
for (const j of jobs) {
211202
if (j.state !== "Done") {
212203
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}`);
214205
}
215206
}
216-
await typeLine(` ${pidCounter.toString().padStart(3)} 2 1 R ps`);
207+
await typeLine(` ${pidCounter.toString().padStart(3)} 2 R ps`);
217208
pidCounter++;
218209
break;
219210
case "jobs":

0 commit comments

Comments
 (0)