diff --git a/sysproc.c b/sysproc.c
index 990a4261ef6c319b129ef044df2e6a9c78855ffb..da01b5b363114ed27914a4b40304e8a12aeb3101 100644
--- a/sysproc.c
+++ b/sysproc.c
@@ -1,4 +1,5 @@
 #include "types.h"
+#include "x86.h"
 #include "defs.h"
 #include "param.h"
 #include "mmu.h"
@@ -13,6 +14,9 @@ sys_fork(void)
   if((np = copyproc(cp)) == 0)
     return -1;
   pid = np->pid;
+
+  // Clear %eax so that fork returns 0 in the child.
+  np->tf->eax = 0;
   np->state = RUNNABLE;
   return pid;
 }
@@ -54,7 +58,8 @@ sys_sbrk(void)
 
   if(argint(0, &n) < 0)
     return -1;
-  if((addr = growproc(n)) < 0)
+  addr = cp->sz;
+  if(growproc(n) < 0)
     return -1;
   return addr;
 }