/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 // init: The initial user-level program
2
3 #include "types.h"
4 #include "stat.h"
5 #include "user.h"
6 #include "fcntl.h"
7
8 char *argv[] = { "sh", 0 };
9
10 int
11 main(void)
12 {
13 int pid, wpid;
14
15 if(open("console", O_RDWR) < 0){
16 mknod("console", 1, 1);
17 open("console", O_RDWR);
18 }
19 dup(0); // stdout
20 dup(0); // stderr
21
22 for(;;){
23 printf(1, "init: starting sh\n");
24 pid = fork();
25 if(pid < 0){
26 printf(1, "init: fork failed\n");
27 exit();
28 }
29 if(pid == 0){
30 exec("sh", argv);
31 printf(1, "init: exec sh failed\n");
32 exit();
33 }
34 while((wpid=wait()) >= 0 && wpid != pid)
35 printf(1, "zombie!\n");
36 }
37 }