* review fork / wait / exec fork -- create a copy of the current process (with some difference) exec -- execute a program; replace the currently running code with the code for a different program wait -- parent waits for child and gets the exit status ** pid_t pid = fork(); if ( pid == 0 ) { // child process here } else if ( pid > 0 ) { // parent process here } else { // error case } ** exec variants l -- list ... just list out the arguments with the last one always NULL v -- vector ... same as the list, just loaded into an array e -- environment ... specify the environment as a vector for the new process to use p -- path ... search the path for a program by that name execve is the one system call, all the others wrap it *** shell exec builtin takes all of the args _after_ exec and uses them as the vector for execvp ** int status = 0; if ( wait(&status) < 0 ) { // error condition } if ( WIFEXITED(status) ) { // WEXITSTATUS(status) is what was passed to exit in the child } else if ( WIFSIGNALED(status) ) { // WTERMSIG(status) is the signal number } * review starting code * diagram flow described in lecture 8 read VAR -l /tmp echo $VAR -l /tmp ls $VAR argv[0] == "ls" argv[1] == "-l" argv[2] == "/tmp" argv[3] == NULL * assignment clarifications ** cd command requirements calls chdir handle the case of one arg and no args *** with no arg, cd goes to $HOME *** what if HOME doesn't have a value or is unset? ** read command requires a single argument that must be a valid variable name reads a single line of text from stdin (always) stores that as the var value ** unset command removes variable completely from the table in varlib.c ** source command (dot) open a separate file stream read commands from the new file stream then return to whatever file stream you were reading from before