Skip to content
Snippets Groups Projects
init.c 649 B
Newer Older
rsc's avatar
rsc committed
// init: The initial user-level program

#include "types.h"
kaashoek's avatar
kaashoek committed
#include "stat.h"
#include "user.h"
#include "fcntl.h"

rsc's avatar
 
rsc committed
char *argv[] = { "sh", 0 };
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){
rsc's avatar
 
rsc committed
      exec("sh", argv);
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");