xv6-riscv-kernel/user/init.c

39 lines
675 B
C
Raw Normal View History

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