xv6-65oo2/user/init.c

39 lines
684 B
C
Raw Normal View History

2007-08-28 19:04:36 +00:00
// 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)
{
2007-08-08 08:39:23 +00:00
int pid, wpid;
2006-09-06 17:27:19 +00:00
2006-08-29 19:06:37 +00:00
if(open("console", O_RDWR) < 0){
mknod("console", 1, 1);
2006-08-29 19:06:37 +00:00
open("console", O_RDWR);
}
2006-09-08 14:36:44 +00:00
dup(0); // stdout
dup(0); // stderr
2006-09-06 18:47:51 +00:00
for(;;){
printf(1, "init: starting sh\n");
pid = fork();
2006-08-29 19:06:37 +00:00
if(pid < 0){
printf(1, "init: fork failed\n");
2006-08-29 19:06:37 +00:00
exit();
}
if(pid == 0){
exec("sh", argv);
printf(1, "init: exec sh failed\n");
exit();
2006-08-29 19:06:37 +00:00
}
while((wpid=wait()) >= 0 && wpid != pid){
//printf(1, "zombie!\n");
}
}
}