1 / 11

ESE 333 - Project 1

ESE 333 - Project 1. Functionalities. A shell command interpreter Printing prompts Parsing command lines Executing commands Input/output redirect Pipe Background jobs. while (TRUE) { type_prompt(); read_command(command, params); pid = fork(); if (pid < 0) {

holly
Download Presentation

ESE 333 - Project 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ESE 333 - Project 1

  2. Functionalities • A shell command interpreter • Printing prompts • Parsing command lines • Executing commands • Input/output redirect • Pipe • Background jobs

  3. while (TRUE) { type_prompt(); read_command(command, params); pid = fork(); if (pid < 0) { printf(“Unable to fork”); continue; } if (pid != 0) { waitpid(-1, &status, 0); } else { execve(command, params, 0); } }

  4. Parsing Command Lines • Break a command line into tokens. • Separate the sequence of tokens by the special characters: <, >, |, & • Available functions: strtok

  5. Executing Commands • Use fork to create a new process. • The child process is dispatched to execute the command. • The parent process waits for the return of the child. • Available functions: fork, waitpid, execvp

  6. Input/Output Redirect • Any device in Unix is viewed as a file, and is associated with a file descriptor (fd). • Standard input = 0, standard output = 1. • Open a file for read/write. • Close the original fd of standard input/output, and use dup/dup2 to create a copy of the fd of the opened file. • Available functions: open, close, dup/dup2

  7. Pipe • Similar to input/output redirect. • Claim a fd array with two items, and create a pipe to connect the two fds: a read from fd[0] accesses the data written to fd[1], and vice versa. • Close the standard input/output and dup fds. • Available functions: pipe

  8. Background process • The parent process does not need to wait for the return of the child process.

  9. Grading Criteria • 1) program can be compiled, 10 points • 2) ls, 10 points, basic command • 3) ls -al, 10 points, command with arguments • 4) man date > out1, 10 points, input redirection • 5) more < out1, 10 points, output redirection • 6) xterm &, 10 points, background job • 7) cat out1 | more, 10 points, pipe

  10. Grading Criteria • 8) cat -n < out1 | more, 6 points, combination of input redirection and pipe • 9) grep -i os < out1 > out2 &, 6 points, combination of input redirection, ouput redirection, and background job • 10) man date | grep -i os > out3, 6 points, combination of piple and output redirection • 11) cat -n < out1 | grep -i os > out4 &, 6 points, combination of input redirection, pipe, ouput redirection, and background job • 12) extra credit, 6 points, extra functionality such as: cd, or combination of two pipes

  11. Unix Lab • gcc has been fixed now. • Course accounts can access jessica.ece.sunysb.edu, which has telnet, ftp, ssh services.

More Related