title: adding exit code to processes in xv6
body: <p>I'm trying to add exit status code to processes in XV6. </p>
  
  <p>I've made the following changes:</p>
  
  <p>1) to <code>sysproc.c</code>:</p>
  
  <pre><code>int
  sys_exit(int status)
  {
    exit(status);
    return 0;  // not reached
  }
  </code></pre>
  
  <p>2) to <code>defs.h</code>:</p>
  
  <pre><code>...
  void            exit(int);
  ...
  </code></pre>
  
  <p>3) to <code>proc.h</code>:</p>
  
  <pre><code>struct proc {
    PCB struct elements...
    ...
    int status;                  // added
  };
  </code></pre>
  
  <p>4) to <code>proc.c</code>:</p>
  
  <pre><code>void
  exit(int status)
  {
    struct proc *curproc = myproc();
    struct proc *p;
    int fd;
  
    cprintf("exit received: %d\n",status); // for debugging purposes
  
    curproc-&gt;status = status; // added
  
    ...rest of exit system call...
    }
  </code></pre>
  
  <p>5) to <code>user.h</code>:</p>
  
  <pre><code>// system calls
  
  ...
  int exit(int) __attribute__((noreturn));
  ...
  </code></pre>
  
  <p>Then I wanted to test the added "functionality" by a simple user-space program:</p>
  
  <pre><code>int
  main (int argc, char *argv[]) {
      exit(3);
  }
  </code></pre>
  
  <p>But the following was printed (notice the cprintf call for debugging in <code>proc.c</code>):</p>
  
  <pre><code>$ exittest
  exit received: -2146420507
  </code></pre>
  
  <p>What have I done wrong?</p>
  
  <p>Thanks</p>