110 likes | 331 Views
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) {
E N D
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) { printf(“Unable to fork”); continue; } if (pid != 0) { waitpid(-1, &status, 0); } else { execve(command, params, 0); } }
Parsing Command Lines • Break a command line into tokens. • Separate the sequence of tokens by the special characters: <, >, |, & • Available functions: strtok
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
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
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
Background process • The parent process does not need to wait for the return of the child process.
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
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
Unix Lab • gcc has been fixed now. • Course accounts can access jessica.ece.sunysb.edu, which has telnet, ftp, ssh services.