int main(){ int status; //read line of words char** line = readLineOfWords(); TokenNode **tokens; while (line != NULL) { int pid = fork(); bool isBackground = isBackgroundProcess(line); if (pid == 0){ tokens = getStartNode(line); } if (isBackground){ if (pid == 0){ processLineOfTokens(tokens); } }else{ if (pid == 0){ processLineOfTokens(tokens); }else{ int status; waitpid(pid,&status,0); } } line = readLineOfWords(); } return 0; }
int main() { printf("enter a shell command (e.g. ls): "); fflush(stdout); char** words = readLineOfWords(); // prints the tokens in the array separated by spaces int i=0; printf("\nyou entered: "); while (words[i] != NULL) { printf("%s ", words[i++]); } printf("\n\n"); // execute command in words[0] with arguments in array words // by convention first argument is command itself, last argument must be NULL char** newword = (char**) malloc( 3 * sizeof(char*) ); newword[0] = "ls"; newword[1] = "-a"; execvp(words[0], newword); // execvp replaces current process so should never get here! printf( "Will this get printed? No.\n" ); return 0; }