Skip to content
Snippets Groups Projects
init.c 655 B
Newer Older
#include "types.h"
kaashoek's avatar
kaashoek committed
#include "stat.h"
#include "user.h"
#include "fcntl.h"

rsc's avatar
rsc committed
// init: The initial user-level program
kaashoek's avatar
kaashoek committed

char *sh_args[] = { "sh", 0 };

int
main(void)
{
rsc's avatar
rsc committed
  int pid, wpid;
  if(open("console", O_RDWR) < 0){
rsc's avatar
 
rsc committed
    mknod("console", 1, 1);
    open("console", O_RDWR);
kaashoek's avatar
kaashoek committed
  dup(0);  // stdout
  dup(0);  // stderr
rsc's avatar
rsc committed
  for(;;){
rsc's avatar
 
rsc committed
    printf(1, "init: starting sh\n");
    pid = fork();
    if(pid < 0){
rsc's avatar
 
rsc committed
      printf(1, "init: fork failed\n");
      exit();
    }
    if(pid == 0){
      exec("sh", sh_args);
rsc's avatar
 
rsc committed
      printf(1, "init: exec sh failed\n");
      exit();
rsc's avatar
rsc committed
    while((wpid=wait()) >= 0 && wpid != pid)
rsc's avatar
 
rsc committed
      printf(1, "zombie!\n");