2006-08-11 15:55:18 +02:00
|
|
|
#include "types.h"
|
2006-08-15 17:53:46 +02:00
|
|
|
#include "stat.h"
|
|
|
|
#include "user.h"
|
2006-08-11 15:55:18 +02:00
|
|
|
#include "fs.h"
|
|
|
|
#include "fcntl.h"
|
|
|
|
|
2006-09-06 19:50:20 +02:00
|
|
|
// init: The initial user-level program
|
2006-08-28 20:31:33 +02:00
|
|
|
|
2006-08-11 15:55:18 +02:00
|
|
|
char *sh_args[] = { "sh", 0 };
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2007-08-08 10:39:23 +02:00
|
|
|
int pid, wpid;
|
2006-09-06 19:27:19 +02:00
|
|
|
|
2006-08-29 21:06:37 +02:00
|
|
|
if(open("console", O_RDWR) < 0){
|
2006-08-11 15:55:18 +02:00
|
|
|
mknod("console", T_DEV, 1, 1);
|
2006-08-29 21:06:37 +02:00
|
|
|
open("console", O_RDWR);
|
2006-08-11 15:55:18 +02:00
|
|
|
}
|
2006-09-08 16:36:44 +02:00
|
|
|
dup(0); // stdout
|
|
|
|
dup(0); // stderr
|
2006-08-11 15:55:18 +02:00
|
|
|
|
2006-09-06 20:47:51 +02:00
|
|
|
for(;;){
|
2007-08-24 22:03:40 +02:00
|
|
|
printf(1, "init: starting sh\n");
|
2006-08-11 15:55:18 +02:00
|
|
|
pid = fork();
|
2006-08-29 21:06:37 +02:00
|
|
|
if(pid < 0){
|
2007-08-24 22:03:40 +02:00
|
|
|
printf(1, "init: fork failed\n");
|
2006-08-29 21:06:37 +02:00
|
|
|
exit();
|
|
|
|
}
|
2006-08-11 15:55:18 +02:00
|
|
|
if(pid == 0){
|
|
|
|
exec("sh", sh_args);
|
2007-08-24 22:03:40 +02:00
|
|
|
printf(1, "init: exec sh failed\n");
|
2006-08-11 15:55:18 +02:00
|
|
|
exit();
|
2006-08-29 21:06:37 +02:00
|
|
|
}
|
2007-08-08 10:39:23 +02:00
|
|
|
while((wpid=wait()) >= 0 && wpid != pid)
|
2007-08-24 22:03:40 +02:00
|
|
|
printf(1, "zombie!\n");
|
2006-08-11 15:55:18 +02:00
|
|
|
}
|
|
|
|
}
|