xv6-65oo2/user/init.c
2019-08-27 13:13:03 -04:00

39 lines
672 B
C

// init: The initial user-level program
#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"
#include "kernel/fcntl.h"
char *argv[] = { "sh", 0 };
int
main(void)
{
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("init: starting sh\n");
pid = fork();
if(pid < 0){
printf("init: fork failed\n");
exit();
}
if(pid == 0){
exec("sh", argv);
printf("init: exec sh failed\n");
exit();
}
while((wpid=wait()) >= 0 && wpid != pid){
//printf("zombie!\n");
}
}
}