OpSys Spring 2006 - HW3 FAQ

Click on a question to expand it (for the details).
Click on the question title again to hide the details.

+ Regular expression containing the '|' character

Question:

When I put '|' in my regular expression, it doesn't do what I want. It is being used to specify alternation in the regular expression. How to I create a regular expression in which '|' means '|' ?


Answer:

If you want to recognize the pipe symbol in a regular expression, you need to escape it - you need to use "\\|" in your string. You need "\\|", and not "\|" since we need the regular expression compiler to see "\|", which it won't see unless we put "\\" in our string.

+ Determining whether a file is executable

Question:

I'm not sure how to tell if a file is a command, and whether or not I have permission to execute it.


Answer:

In general this is not trivial, as you need to match the owner of the file to the uid of the process itself (who is running your program) and check the user-executable permission bit (S_IXUSR), if that doesn't indicate the file is executable by the process, you would need to try the groups (group owner of the file, group id of the running process and group permission bit), and finally the "other" execute permission bit.

For this assignment, you should simply make sure that the file is executable by "other" (use S_IXOTH), this will allow your shell to run programs like ls and sort. See the sample solution to question #6 on this old test: Test #1 for an example of how to do this.

+ input line parsing

Question:

What kind of input lines are we expected to be able to handle?


Answer:

For starters, we should not be able to crash your program no matter what we type in as input!

As for what kind of command lines you are expected to be able to process:

  • any of the internal commands

  • You should not treat "*", "?", ... as special characters, just pass them along to external programs.

  • You should be able to handle any command with any command line options, for example: "ls -a -l -g" or "ls -alg" (in both cases you just need to pass all the command line arguments on to ls).

  • Any command that calls for input redirection and/or output redirection. Valid examples: "sort -n < infile", "ls > outfile", and even "sort < infile > outfile"

  • Any pipeline (possibly including input redirection at the beginning of the pipeline and output redirection at the end of the pipeline). For example: "ls -al | sort", "ls -al | cut -c30- | sort -n > outfile" and "strings < /bin/ls | sort | uniq | wc -l > outfile"

  • Whitespace only separates things, the amount of whitespace doesn't matter. It is possible to have pipes or redirection without whitespace: "ls -al|sort>outfile".