Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chien-Chung Shen CIS/UD

Similar presentations


Presentation on theme: "Chien-Chung Shen CIS/UD"— Presentation transcript:

1 Chien-Chung Shen CIS/UD cshen@udel.edu
Notes on Shell Chien-Chung Shen CIS/UD

2 Command Line Argument argv
$ mine -c argc == 4

3 Wildcard * $ grep hello a*
Shell “expands” string a* to a list of every file name matching pattern a* via blog() or wordexp() These then become part of the command line parameters to a single instance of grep For the implementer of shell (i.e., you the student), all the expanded words go as separate strings into the argv argument of main() of grep That single grep command then parses the arguments in whatever way it chooses, and it is up to grep to interpret those arguments as file names, options, option arguments, regular expressions, etc., and take the appropriate actions

4 Environment Variable PATH
tcsh % echo $path % set path = (/User/cshen $path) bash % export PATH=/User/cshen:${PATH}

5 exec() Functions int execl(const char *pathname, const char *arg0, ... /* (char *)0 */ ); int execv(const char *pathname, char *const argv []); int execle(const char *pathname, const char *arg0, ...             /* (char *)0, char *const envp[] */ ); int execve(const char *pathname, char *const argv[], char *const envp[]); int execlp(const char *filename, const char *arg0, ... /* (char *)0 */ ); int execvp(const char *filename, char *const argv[]); int fexecve(int fd, char *const argv[], char *const envp[]); l: list of arguments; v: argv[] vector; p: filename with PATH; e: envp[] array

6 Unix Pipe int pfds[2]; // file descriptors pipe(pfds); R W
Stevens and Rago’s Section 15.2

7 Half-Duplex Pipe after fork

8 Pipe from Parent to Child
parent closes the read end of pipe (fd[0]) child closes the write end of the pipe (fd[1])

9 Shell Execution of Programs
Stevens and Rago’s Section 9.9 % ps | cat1 | cat2


Download ppt "Chien-Chung Shen CIS/UD"

Similar presentations


Ads by Google