mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-04-28 21:01:11 +08:00
my solution to lab5
This commit is contained in:
29
lab/user/icode.c
Normal file
29
lab/user/icode.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <inc/lib.h>
|
||||
|
||||
void
|
||||
umain(int argc, char **argv)
|
||||
{
|
||||
int fd, n, r;
|
||||
char buf[512+1];
|
||||
|
||||
binaryname = "icode";
|
||||
|
||||
cprintf("icode startup\n");
|
||||
|
||||
cprintf("icode: open /motd\n");
|
||||
if ((fd = open("/motd", O_RDONLY)) < 0)
|
||||
panic("icode: open /motd: %e", fd);
|
||||
|
||||
cprintf("icode: read /motd\n");
|
||||
while ((n = read(fd, buf, sizeof buf-1)) > 0)
|
||||
sys_cputs(buf, n);
|
||||
|
||||
cprintf("icode: close /motd\n");
|
||||
close(fd);
|
||||
|
||||
cprintf("icode: spawn /init\n");
|
||||
if ((r = spawnl("/init", "init", "initarg1", "initarg2", (char*)0)) < 0)
|
||||
panic("icode: spawn /init: %e", r);
|
||||
|
||||
cprintf("icode: exiting\n");
|
||||
}
|
||||
Reference in New Issue
Block a user