mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-05-03 03:35:10 +08:00
my solution to lab5
This commit is contained in:
27
lab/user/initsh.c
Normal file
27
lab/user/initsh.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <inc/lib.h>
|
||||
|
||||
void
|
||||
umain(int argc, char **argv)
|
||||
{
|
||||
int i, r, x, want;
|
||||
|
||||
cprintf("initsh: running sh\n");
|
||||
|
||||
// being run directly from kernel, so no file descriptors open yet
|
||||
close(0);
|
||||
if ((r = opencons()) < 0)
|
||||
panic("opencons: %e", r);
|
||||
if (r != 0)
|
||||
panic("first opencons used fd %d", r);
|
||||
if ((r = dup(0, 1)) < 0)
|
||||
panic("dup: %e", r);
|
||||
while (1) {
|
||||
cprintf("init: starting sh\n");
|
||||
r = spawnl("/sh", "sh", (char*)0);
|
||||
if (r < 0) {
|
||||
cprintf("init: spawn sh: %e\n", r);
|
||||
continue;
|
||||
}
|
||||
wait(r);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user