2007-08-28 19:04:36 +00:00
|
|
|
// init: The initial user-level program
|
|
|
|
|
2019-06-11 13:57:14 +00:00
|
|
|
#include "kernel/types.h"
|
|
|
|
#include "kernel/stat.h"
|
|
|
|
#include "user/user.h"
|
|
|
|
#include "kernel/fcntl.h"
|
2006-08-11 13:55:18 +00:00
|
|
|
|
2009-05-31 05:12:21 +00:00
|
|
|
char *argv[] = { "sh", 0 };
|
2006-08-11 13:55:18 +00:00
|
|
|
|
|
|
|
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){
|
2007-08-24 20:54:23 +00:00
|
|
|
mknod("console", 1, 1);
|
2006-08-29 19:06:37 +00:00
|
|
|
open("console", O_RDWR);
|
2006-08-11 13:55:18 +00:00
|
|
|
}
|
2006-09-08 14:36:44 +00:00
|
|
|
dup(0); // stdout
|
|
|
|
dup(0); // stderr
|
2006-08-11 13:55:18 +00:00
|
|
|
|
2006-09-06 18:47:51 +00:00
|
|
|
for(;;){
|
2007-08-24 20:03:40 +00:00
|
|
|
printf(1, "init: starting sh\n");
|
2006-08-11 13:55:18 +00:00
|
|
|
pid = fork();
|
2006-08-29 19:06:37 +00:00
|
|
|
if(pid < 0){
|
2007-08-24 20:03:40 +00:00
|
|
|
printf(1, "init: fork failed\n");
|
2006-08-29 19:06:37 +00:00
|
|
|
exit();
|
|
|
|
}
|
2006-08-11 13:55:18 +00:00
|
|
|
if(pid == 0){
|
2009-05-31 05:12:21 +00:00
|
|
|
exec("sh", argv);
|
2007-08-24 20:03:40 +00:00
|
|
|
printf(1, "init: exec sh failed\n");
|
2006-08-11 13:55:18 +00:00
|
|
|
exit();
|
2006-08-29 19:06:37 +00:00
|
|
|
}
|
2019-07-05 16:33:26 +00:00
|
|
|
while((wpid=wait()) >= 0 && wpid != pid){
|
|
|
|
//printf(1, "zombie!\n");
|
|
|
|
}
|
2006-08-11 13:55:18 +00:00
|
|
|
}
|
|
|
|
}
|