1 #include "types.h" 2 #include "stat.h" 3 #include "user.h" 4 #include "fs.h" 5 #include "fcntl.h" 6 7 // init: The initial user-level program 8 9 char *sh_args[] = { "sh", 0 }; 10 11 int 12 main(void) 13 { 14 int pid; 15 16 if(open("console", O_RDWR) < 0){ 17 mknod("console", T_DEV, 1, 1); 18 open("console", O_RDWR); 19 } 20 dup(0); 21 dup(0); 22 23 for(;;){ 24 pid = fork(); 25 if(pid < 0){ 26 puts("init: fork failed\n"); 27 exit(); 28 } 29 if(pid == 0){ 30 exec("sh", sh_args); 31 puts("init: exec sh failed\n"); 32 exit(); 33 } else { 34 wait(); 35 } 36 } 37 } 38