summaryrefslogtreecommitdiff
path: root/user/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'user/init.c')
-rw-r--r--user/init.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/user/init.c b/user/init.c
index 5df6deb..13764ca 100644
--- a/user/init.c
+++ b/user/init.c
@@ -31,8 +31,20 @@ main(void)
printf("init: exec sh failed\n");
exit(1);
}
- while((wpid=wait(0)) >= 0 && wpid != pid){
- //printf("zombie!\n");
+
+ for(;;){
+ // this call to wait() returns if the shell exits,
+ // or if a parentless process exits.
+ wpid = wait((int *) 0);
+ if(wpid == pid){
+ // the shell exited; restart it.
+ break;
+ } else if(wpid < 0){
+ printf("init: wait returned an error\n");
+ exit(1);
+ } else {
+ // it was a parentless process; do nothing.
+ }
}
}
}