Andy Wang Operating Systems COP 4610 / CGS 5765 Project 1 Hints Andy Wang Operating Systems COP 4610 / CGS 5765
Overall Parsing chdir() is a system call Use calloc() instead of malloc() Use multiple passes to simply parsing One pass to create an array of string tokens One pass for input redirection One pass for output redirection chdir() is a system call
Foreground Execution fork() Shell Shell waitpid(pid, &status, 0)
Foreground Execution fork() Shell Shell execvp(bin_path, argv) waitpid(pid, &status, 0)
Foreground Execution fork() Shell Shell waitpid(pid, &status, 0)
Background Execution fork() Shell Shell waitpid(-1, &status, WNOHANG)
Background Execution fork() Shell Shell execvp(bin_path, argv) waitpid(-1, &status, WNOHANG)
Background Execution fork() Shell Shell waitpid(-1, &status, WNOHANG)
Input Redirection shell file descriptors 0 stdin 1 stdout 2 stderr fork() file descriptors 0 stdin 1 stdout 2 stderr shell
Input Redirection open(input_file, O_RDONLY) file descriptors 0 stdin 1 stdout 2 stderr file descriptors 0 stdin 1 stdout 2 stderr shell shell
Input Redirection open(input_file, O_RDONLY) file descriptors 0 stdin 1 stdout 2 stderr file descriptors 0 stdin 1 stdout 2 stderr 3 input_file shell shell
Input Redirection close(0) file descriptors 0 stdin 1 stdout 2 stderr 3 input_file shell shell
Input Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr 1 stdout 2 stderr 3 input_file shell shell
Input Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr 0 input_file 1 stdout 2 stderr 3 input_file shell shell
Input Redirection close(3) file descriptors 0 stdin 1 stdout 2 stderr 0 input_file 1 stdout 2 stderr 3 input_file shell shell
Output Redirection shell file descriptors 0 stdin 1 stdout 2 stderr fork() file descriptors 0 stdin 1 stdout 2 stderr shell
Output Redirection open(output_file, O_RDWR | O_CREAT | O_TRUC) file descriptors 0 stdin 1 stdout 2 stderr file descriptors 0 stdin 1 stdout 2 stderr shell shell
Output Redirection open(output_file, O_RDWR | O_CREAT | O_TRUC) file descriptors 0 stdin 1 stdout 2 stderr file descriptors 0 stdin 1 stdout 2 stderr 3 output_file shell shell
Output Redirection file descriptors 0 stdin 1 stdout 2 stderr 3 output_file shell close(1) shell
Output Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr 3 output_file shell shell
Output Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr 1 output_file 2 stderr 3 output_file shell shell
Output Redirection close(3) file descriptors 0 stdin 1 stdout 2 stderr 1 output_file 2 stderr 3 output_file shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell
Pipe shell file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] int p1_to_p2[2]; pipe(p1_to_p2); fork() int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell
Pipe shell file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] int p1_to_p2[2]; pipe(p1_to_p2); fork() int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] dup(4) shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] dup(4) shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] dup(3) shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 p1_to_p2[0] 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] dup(3) shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 p1_to_p2[0] 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 p1_to_p2[0] 1 stdout 2 stderr shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr 3 p1_to_p2[0] 4 p1_to_p2[1] file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) shell shell shell
Pipe int p1_to_p2[2]; pipe(p1_to_p2); int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin 1 stdout 2 stderr waitpid(…) file descriptors 0 stdin 1 p1_to_p2[1] 2 stderr execvp(bin_path, argv) file descriptors 0 p1_to_p2[0] 1 stdout 2 stderr execvp(bin_path, argv) shell shell shell