xv6/init.c

36 lines
752 B
C
Raw Permalink Normal View History

2023-01-04 17:04:31 +01:00
// init: The initial user-level program
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
char *shell_argv[] = { "sh", 0 };
int main(int argc, char* argv[]) {
int pid, wpid;
if (open("console", O_RDWR) < 0) {
mknod("console", 1, 1);
open("console", O_RDWR);
}
dup(0); // stdout
dup(0); // stderr
for (;;) {
printf(1, "init: starting sh\n");
pid = fork();
if (pid < 0) {
printf(1, "init: fork failed\n");
exit();
}
if (pid == 0) {
exec("sh", shell_argv);
printf(1, "init: exec sh failed\n");
exit();
}
while ((wpid = wait()) >= 0 && wpid != pid) {
}
}
}