]> Devi Nivas Git - cs3210-lab1.git/commitdiff
fix wait bug in init
authorrsc <rsc>
Wed, 8 Aug 2007 08:39:23 +0000 (08:39 +0000)
committerrsc <rsc>
Wed, 8 Aug 2007 08:39:23 +0000 (08:39 +0000)
BUGS
init.c

diff --git a/BUGS b/BUGS
index 79e956f6467e7198190334da3e044dc5480ebb9b..daa26ca95cdc60f6c5e4bc3c311d6c7cc8a63cdb 100644 (file)
--- a/BUGS
+++ b/BUGS
@@ -11,10 +11,6 @@ main.c:
 
        cpus[0] -> cpus[bcpu]
 
-init.c:
-       should while(wait() >= 0);
-       not just wait();
-
 proc.c:
        comment at top of scheduler() should say
                via longjmp back to the scheduler
diff --git a/init.c b/init.c
index 909ee8034b43ab3aa07097542a89d85d563c2e34..b9526891a92752b8d91a0ed0ff2b88178bf83248 100644 (file)
--- a/init.c
+++ b/init.c
@@ -11,7 +11,7 @@ char *sh_args[] = { "sh", 0 };
 int
 main(void)
 {
-  int pid;
+  int pid, wpid;
 
   if(open("console", O_RDWR) < 0){
     mknod("console", T_DEV, 1, 1);
@@ -21,6 +21,7 @@ main(void)
   dup(0);  // stderr
 
   for(;;){
+    puts("init: starting sh\n");
     pid = fork();
     if(pid < 0){
       puts("init: fork failed\n");
@@ -30,8 +31,8 @@ main(void)
       exec("sh", sh_args);
       puts("init: exec sh failed\n");
       exit();
-    } else {
-      wait();
     }
+    while((wpid=wait()) >= 0 && wpid != pid)
+      ;
   }
 }