OpSys Spring 2005 - HW3 FAQ

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

+ 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 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".