xv6-65oo2/init.c

38 lines
554 B
C
Raw Normal View History

#include "types.h"
2006-08-15 15:53:46 +00:00
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "fcntl.h"
/* The initial user-level program */
char *sh_args[] = { "sh", 0 };
int
main(void)
{
int pid;
2006-08-29 19:06:37 +00:00
if(open("console", O_RDWR) < 0){
mknod("console", T_DEV, 1, 1);
2006-08-29 19:06:37 +00:00
open("console", O_RDWR);
}
2006-08-29 19:06:37 +00:00
dup(0);
dup(0);
while(1){
pid = fork();
2006-08-29 19:06:37 +00:00
if(pid < 0){
puts("init: fork failed\n");
exit();
}
if(pid == 0){
exec("sh", sh_args);
2006-08-29 19:06:37 +00:00
puts("init: exec sh failed\n");
exit();
2006-08-29 19:06:37 +00:00
} else {
wait();
2006-08-29 19:06:37 +00:00
}
}
}