Ese 333 project 1
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

ESE 333 - Project 1 PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on
  • Presentation posted in: General

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) {

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Ese 333 project 1

ESE 333 - Project 1


Functionalities

Functionalities

  • A shell command interpreter

    • Printing prompts

    • Parsing command lines

    • Executing commands

    • Input/output redirect

    • Pipe

    • Background jobs


Ese 333 project 1

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

Parsing Command Lines

  • Break a command line into tokens.

  • Separate the sequence of tokens by the special characters: <, >, |, &

  • Available functions: strtok


Executing commands

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

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


Ese 333 project 1

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

Background process

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


Grading criteria

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 criteria1

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

Unix Lab

  • gcc has been fixed now.

  • Course accounts can access jessica.ece.sunysb.edu, which has telnet, ftp, ssh services.


  • Login