Download presentation
Presentation is loading. Please wait.
1
Andy Wang Operating Systems COP 4610 / CGS 5765
Project 1 Hints Andy Wang Operating Systems COP 4610 / CGS 5765
2
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
3
Foreground Execution fork() Shell Shell waitpid(pid, &status, 0)
4
Foreground Execution fork() Shell Shell execvp(bin_path, argv)
waitpid(pid, &status, 0)
5
Foreground Execution fork() Shell Shell waitpid(pid, &status, 0)
6
Background Execution fork() Shell Shell waitpid(-1, &status, WNOHANG)
7
Background Execution fork() Shell Shell execvp(bin_path, argv)
waitpid(-1, &status, WNOHANG)
8
Background Execution fork() Shell Shell waitpid(-1, &status, WNOHANG)
9
Input Redirection shell file descriptors 0 stdin 1 stdout 2 stderr
fork() file descriptors 0 stdin 1 stdout 2 stderr shell
10
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
11
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
12
Input Redirection close(0) file descriptors 0 stdin 1 stdout 2 stderr
3 input_file shell shell
13
Input Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr
1 stdout 2 stderr 3 input_file shell shell
14
Input Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr
0 input_file 1 stdout 2 stderr 3 input_file shell shell
15
Input Redirection close(3) file descriptors 0 stdin 1 stdout 2 stderr
0 input_file 1 stdout 2 stderr 3 input_file shell shell
16
Output Redirection shell file descriptors 0 stdin 1 stdout 2 stderr
fork() file descriptors 0 stdin 1 stdout 2 stderr shell
17
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
18
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
19
Output Redirection file descriptors 0 stdin 1 stdout 2 stderr
3 output_file shell close(1) shell
20
Output Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr
3 output_file shell shell
21
Output Redirection dup(3) file descriptors 0 stdin 1 stdout 2 stderr
1 output_file 2 stderr 3 output_file shell shell
22
Output Redirection close(3) file descriptors 0 stdin 1 stdout 2 stderr
1 output_file 2 stderr 3 output_file shell shell
23
Pipe int p1_to_p2[2]; pipe(p1_to_p2); file descriptors 0 stdin
1 stdout 2 stderr shell
24
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
25
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
26
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
27
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
28
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
29
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
30
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
31
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
32
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
33
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
34
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
35
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
36
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
37
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
38
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
39
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
40
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
41
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.