diff options
author | Robert Morris <[email protected]> | 2020-08-15 05:46:32 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2020-08-15 05:46:32 -0400 |
commit | b154cf091c57db1b412a022490c0cec009b4cf6b (patch) | |
tree | 6a54ca874f00de6f66751ee4c7299cfb322b18c7 /user/init.c | |
parent | 4a87a0ae8bc4a186842fb5f57454412de56f52bc (diff) | |
download | xv6-labs-b154cf091c57db1b412a022490c0cec009b4cf6b.tar.gz xv6-labs-b154cf091c57db1b412a022490c0cec009b4cf6b.tar.bz2 xv6-labs-b154cf091c57db1b412a022490c0cec009b4cf6b.zip |
x
Diffstat (limited to 'user/init.c')
-rw-r--r-- | user/init.c | 16 |
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. + } } } } |