Add these #include s:
#include <sys/types.h> #include <sys/wait.h>
then wait(2) correctly:
int status; wait(&status);
Your wait() code does not call the wait(2) system call. Rather, it declares a temporary object of type union wait . If you are #include stdlib.h but not sys/wait.h , then you will only get a type declaration, not a function declaration.
By the way, if you checked the return value of the wait : int result = wait() call, you received an informative error message:
xsh.cc:26: error: cannot convert 'wait to' int to initialization
source share