summaryrefslogtreecommitdiff
path: root/user/init.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2020-08-15 05:46:32 -0400
committerFrans Kaashoek <[email protected]>2020-08-17 08:18:23 -0400
commit95dad4c061d6e1f036d75cc041367a8f12b92982 (patch)
tree6a54ca874f00de6f66751ee4c7299cfb322b18c7 /user/init.c
parentf2ec6777bd530f949c235d7f0386286314a2f601 (diff)
downloadxv6-labs-95dad4c061d6e1f036d75cc041367a8f12b92982.tar.gz
xv6-labs-95dad4c061d6e1f036d75cc041367a8f12b92982.tar.bz2
xv6-labs-95dad4c061d6e1f036d75cc041367a8f12b92982.zip
x
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.
+ }
}
}
}