Quiz 2 (Due in or before class, 3nd week)

Question 1: Text manipulation
Use this passwd file for this question. Give a command that will alphabetize the login names in the file. Give a command that will sort the file by UID. Give a command that will tell you how many users use "bash" as their shell.
Answer 1
Part 1: sort passwdfile
Part 2: sort -n -t: +2 -3 passwdfile
Part 3: grep '/bash$' passwdfile | wc -l

Question 2: File types
When you are making a hard link to a file, the link has the same owner and permissions as the original file. But with a symbolic link, the link is owned by you, and has bizarre permissions. Why is this not considered a difference in functionality (i.e. does this actually change the way you can use the links)? Give an explanation for why only root can hard link directories.
Answer 2
Part 1: Access control on symbolic links is relegated to the access control on the file it points to. So the link's permissions do not affect the authentication of the access operation.
Part 2: Root has to be aware of the directory hierarchy. For example, if you hardlinked the root directory into your home directory, when root would do a 'find' that descended through your home directory, it would loop infinitely (it would go back to / and then [eventually] descend into your home directory again) without ever knowing that it had been redirected out of your home directory. With symlinks, it would know that it had been redirected (and, in fact, find will not follow symlinks unless you explicitly tell it to).

Question 3: Processes
Login to "orcus.cs.uchicago.edu" and run the following: "/usr/ucb/ps auxww | grep flynn". Discuss what you see that is irregular. Explain why/when this happens. Look at ~flynn/foo.c for the source code.
Answer 3
The output shows a defunct process. The parent of this process is not allowing the process to exit (by not issuing a wait(2) system call). The wait(2) notation means that the feature is documented in section two of the manual page.

Question 4: Manual pages
Read the manual page for "man" (i.e. run "man -M/usr/man man"). Explain what the difference is between the pages output with: "man -M/usr/man -s 1 chmod" and "man -M/usr/man -s 2 chmod".
Answer 4
The -s selects a section of the manual page. Section 1 is user commands. Section 2 is system calls.