Mercurial > hg > Members > menikon > CbC_xv6
view src/usr/init.c @ 75:624fe2ec975c cmake-of-the-shelf
reduce user command to achive fs space
author | kono |
---|---|
date | Fri, 02 Aug 2019 19:34:33 +0900 |
parents | 83c23a36980d |
children |
line wrap: on
line source
// init: The initial user-level program #include "types.h" #include "stat.h" #include "user.h" #include "fcntl.h" char *argv[] = { "sh", 0 }; int main(void) { int pid, wpid; if(open("console", O_RDWR) < 0){ mknod("console", 1, 1); open("console", O_RDWR); } dup(0); // stdout dup(0); // stderr for(;;){ printf(1, "init: starting sh\n"); pid = fork(); if(pid < 0){ printf(1, "init: fork failed\n"); exit(); } if(pid == 0){ exec("sh", argv); printf(1, "init: exec sh failed\n"); exit(); } while((wpid=wait()) >= 0 && wpid != pid) printf(1, "zombie!\n"); } }