Name: ___Solutions__________________ SID: ____Solutions____________
Answer the following questions in the space provided, or as instructed by editing and adding files to your student account. Please be write clearly and make clear your final solution to a question if you make changes or corrections (pencils are recommended). Partial credit will be given if and where possible, so show your work where appropriate. This test is open book / open source material, you may use any source materials you like and find helpful for this class. However, this is an individual test, no cell phones, IM or other collaboration will be allowed during the test.
|
For official grading use only. Total: ______/ 100 |
||||||||||||||||||||||||
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
|
/6 |
/2 |
/4 |
/2 |
/3 |
/6 |
/3 |
/3 |
/6 |
/3 |
/2 |
/3 |
/3 |
/3 |
/1 |
/1 |
/1 |
/1 |
/6 |
/8 |
/5 |
/10 |
/2 |
/4 |
/12 |
(6 pts) Match the following tools/commands with the description of their purpose (you can draw lines and/or match the number with the letter).
|
1) rm |
L |
a) symbolic debugger
|
3 |
|
2) ls |
H |
b) create or extract archives of directory structures
|
6 |
|
3) gdb |
A |
c) concatenate files and print on standard output
|
7 |
|
4) grep |
E |
d) task automation and system build tool
|
12 |
|
5) chmod |
I |
e) print line matching a regular expression pattern
|
4 |
|
6) tar |
B |
f) c source code compiler
|
8 |
|
7) cat |
C |
g) revision control system
|
11 |
|
8) gcc |
F |
h) list directory contents
|
2 |
|
9) man |
K |
i) change file access permissions
|
5 |
|
10) cd |
J |
j) change working directory
|
10 |
|
11) svn |
G |
k) read online reference manuals
|
9 |
|
12) make |
D |
l) remove files or directories
|
1 |
(2 pts) Which of the following problems or tasks does a version control system like subversion solve for you?
Allows you to automate repetitive tasks
Allows multiple collaborators to share and sync changes with one another
Allows you to undo changes in time, e.g. see the past history of changes done to a file
Allows you to symbolically debug a program in a more systematic way than using print statements.
Answer(s) (choose all that apply): ______B, C______________
(4 pts) If you run the following subversion command and see this output:
[harry@nisl lab04]$ svn status
! wc.py
M palindrome.py
A goodbye.py
C reverse.py
What does the ! indicate about the wc.py file? ________File is missing in local working copy of repository
What does the M indicate about the palindrome.py file? File has been modified
What does the A indicate about the goodbye.py file? ___File has been added to repository
What does the C indicate about the reverse.py file? ____File is in conflict
(2 pts) The pipe command ( | ) is used to:
Redirect the output of a command into a new file
Renumber the output of a command
Run two commands concurrently
Redirect the output of a command into the input of another command
Answer(s) (choose all that apply): ___D_____
(3 pts) Given the following directory listing:
[root@nisl sbin]# ls -al rrestore service
lrwxrwxrwx 1 root root 7 Jun 26 2007 rrestore -> restore
-rwxr-xr-- 1 root aturing 1744 Nov 28 2006 service
What type of file is rrestore? ____symbolic link__________________________
Who has permission to delete the service command file? _root (the owner of the file)
Who has permission to execute the service command? ___root (the owner) and members of the aturing group
(6 pts) Mark the following as examples of either Relative path names (R) or Absolute path names (A)
test.py _Relative_
../../bin/script.py _Relative_
/usr/local/lib/libabs.a _Absolute_
~/work/project/file.txt _Relative_
/ _Absolute_
./dat2csv.py _Relative_
(3 pts) What three things must be done in order to make an interpretable script, such as a file of Python or Perl code, be executable?
1. Set execute permission for the file (e.g. chmod +x)
2. Specify appropriate interpreter for file (e.g. using #! method for example on Linux)
3. Locate the script (e.g. by adding to your PATH, or specifying an absolute or relative full path name of the script)
(3 pts) Given the following contents of the file animals.txt, how would you use both input and output redirection and the sort command to create a new file called animals-sorted.txt that contains the same contents as in animals.txt by sorted by alphabetical order?
[harry@nisl ~]$ cat animals.txt
elephant
kangaroo
dog
bird
mongoose
[harry@nisl ~]$ cat animals.txt | sort > animals-sorted.txt
(6 pts) Given the following Makefile:
------------------------------------------ Makefile ------------------------------------
CC = gcc
CFLAGS = -g -O2 -D_REENTRANT -Wall
LIBS = ../libunp.a -lpthread
LIBUNP_NAME = ../libunp.a
LIBGAI_OBJS = getaddrinfo.o getnameinfo.o freeaddrinfo.o gai_strerror.o ga_aistruct.o \
ga_clone.o ga_echeck.o ga_nsearch.o ga_port.o ga_serv.o ga_unix.o gn_ipv46.o
PROGS = testga test1
CLEANFILES = core core.* *.core *.o temp.* *.out typescript* \
*.lc *.lh *.bsdi *.sparc *.uw
all: ${LIBGAI_OBJS}
ar rv ${LIBUNP_NAME} $?
testga: testga.o
${CC} ${CFLAGS} -o $@ testga.o ${LIBS}
test1: test1.o
${CC} ${CFLAGS} -o $@ test1.o ${LIBS}
%.o: %.c
${CC} -c -o $@ $<
clean:
rm -f ${PROGS} ${CLEANFILES}
------------------------------------------ Makefile ------------------------------------
What is the default target of this makefile? __all______________________________________________________
What does the default target do? _Creates the static archive libunp.a, and compiles any out of date object files that are part of the library.
What are the prerequisites of the testga target? __testga.o______________________________________________
CC and CFLAGS are examples of
(a) automatic varibles (b) make macro variables (c) targets (d) actions (e) prerequisites? ______B______________________
$@ and $< are examples of
(a) automatic varibles (b) make macro variables (c) targets (d) actions (e) prerequisites? ______A______________________
If test1.c is in the current directory and has been modified, what actions would you expect to take place if
[user@nisl ~]$ make test1 is invoked? __
gcc -c -o test1.o test1.c
gcc -g -O2 -D_REENTRANT -wall -o test1 test1.o ../libunp.a -lpthread
(3 pts) What is displayed when the following python script is run as shown:
----- argscript.py contents -----
#!/usr/bin/env python
import sys
for arg in sys.argv:
print arg
---------------------------------
[harry@nisl ~]$ ./argscript.py arg1 -flag1 arg2
./argscript.py
arg1
-flag1
arg2
(2 pts) We discussed and frequently used two special directory to specify relative path names from the command line and in Makefiles and scripts. Briefly, what do these two special directory names refer to?
. __the current working directory ____________________________
.. __the parent directory (relative to the current working directory)__
(3 pts) Briefly describe what each wildcard character does when used with the bash shell to match file names:
* ____match 0 or more of any character_______________________________
? ____match any single character_____________________________________
[] ____match any single character among choices (e.g. if [aeiou] match either an a, an e, an i, an o or a u)
(3 pts) Given the following directory listing, what will be displayed by executing the given directory listing command:
[dharter@chaos shultznn] $ ls -al
total 120
drwxr-xr-x 2 dharter dharter 4096 2007-02-26 16:51 .
drwxr-xr-x 9 dharter dharter 4096 2007-02-21 09:35 ..
-rwxr-xr-x 1 dharter dharter 26541 2007-02-26 16:51 backpropsim
-rw-r--r-- 1 dharter dharter 2020 2007-02-23 15:42 backpropsim.c
-rw-r--r-- 1 dharter dharter 4440 2007-02-26 16:51 backpropsim.o
-rw-r--r-- 1 dharter dharter 149 2007-02-23 15:35 Debug.h
-rw-r--r-- 1 dharter dharter 13605 2007-02-23 15:38 Layer.c
-rw-r--r-- 1 dharter dharter 617 2007-02-23 11:05 Layer.h
-rw-r--r-- 1 dharter dharter 14044 2007-02-26 16:51 Layer.o
-rw-r--r-- 1 dharter dharter 584 2007-02-26 16:50 Makefile
-rw-r--r-- 1 dharter dharter 1834 2007-02-23 15:39 Pattern.c
-rw-r--r-- 1 dharter dharter 392 2007-02-22 11:10 Pattern.h
-rw-r--r-- 1 dharter dharter 5724 2007-02-26 16:51 Pattern.o
-rw-r--r-- 1 dharter dharter 499 2007-02-21 11:14 Random.c
-rw-r--r-- 1 dharter dharter 193 2007-02-21 11:55 Random.h
-rw-r--r-- 1 dharter dharter 3140 2007-02-26 16:51 Random.o
[dharter@chaos shultznn]$ ls [LP]*.[hc]
Layer.c Layer.c Pattern.c Pattern .h
(3 pts) What are the 3 I/O connections that every process in Unix has to the outside world when it is created, and what are these connected to by default (don't forget this second part, does the I/O go to a printer for example by default, or where)?
_standard input connected to the keyboard__
_standard output connected to the terminal_
_standard error also connected to the terminal
(1 pts) The following use of pipes is illegal because you can only pipe 2 commands together at most:
$ grep 'Title' spells.txt | sort | uniq -c | sort -n -r | head -10 > popular_spells.txt
a) True b) False
(1 pts) Any program that reads from standard input and writes to standard output can use I/O redirection and pipes
a) True b) False
(1 pts) A program that reads from standard input, does some manipulation, then writes results to standard output is called a:
____Filter_______________ __________________________
(1 pts) If you are using the bash shell, which file should you edit in order to have variables or aliases set automatically for you every time you log in?
__~/.bashrc________________________________________
(6 pts) Assume that there is a subversion repository that you have modify access to at the url location http://magicco.org/repo
What subversion command would you use to check out a working copy of the magicco repo to a directory calld magiccorepo in your home directory?
[user@nisl ~]$ svn co http://magicco.org/repo magiccorepo
If you are now in the magiccorepo working copy directory, what command would you use to synchronize your working copy of the repository with the most recent revision that has been checked in?
[user@nisl ~]$ svn update
What command would you run to add a new file named spells.txt in current directory to be under revision control?
[user@nisl ~]$ svn add spells.txt
What command would you run to see all of the logged history of updates and changes to the repository?
[user@nisl ~]$ svn log
What command would you use to remove a file named spellusers.txt that is currently under repository control from the repository?
[user@nisl ~]$ svm rm spellusers.txt
What command would you use to send your changes to the repository and create a new revision?
[user@nisl ~]$ svi ci
(8 pts) Given the following Makefile:
------------------------------- Makefile ---------------------------------
element_summary.csv: gold.csv lead.csv silver.csv
summarizecsv gold.csv lead.csv silver.csv > element_summary.csv
gold.csv: gold.dat
dat2csv gold.dat > gold.csv
lead.csv: lead.dat
dat2csv lead.dat > lead.csv
silver.csv: silver.dat
dat2csv silver.dat > silver.csv
clean:
rm -v *.dat
------------------------------- Makefile ---------------------------------
And also with the following dates/times and files in the current directory:
[dharter@chaos tests]$ ls -al
total 76
drwxr-xr-x 2 dharter dharter 4096 2007-03-13 13:41 .
drwxr-xr-x 5 dharter dharter 4096 2007-03-13 10:50 ..
-rw-r--r-- 1 dharter dharter 54 2007-03-13 13:25 element_summary.csv
-rw-r--r-- 1 dharter dharter 27 2007-03-13 13:38 gold.dat
-rw-r--r-- 1 dharter dharter 65 2007-03-13 13:40 lead.csv
-rw-r--r-- 1 dharter dharter 101 2007-03-13 13:41 lead.dat
-rw-r--r-- 1 dharter dharter 288 2007-03-13 13:40 Makefile
-rw-r--r-- 1 dharter dharter 40 2007-03-13 13:40 silver.csv
-rw-r--r-- 1 dharter dharter 67 2007-03-13 13:38 silver.dat
Draw a file dependency tree of the targets/prerequisites defined by this Makefile:













20. (continued from question on previous page)
What commands will be be run by make when we do the following. Be careful, you need to examine the dates/time stamps as well as the file dependencies to determine which commands will be run. Remember, that make will only run the actions for targets that are out of date based on their dependencies.
[dharter@chaos tests]$ make
dat2csv gold.dat > gold.csv
dat2csv lead.dat > lead.csv
# silver.csv is already up to date (newer) than its dependency, so will not be rebuilt)
summarizecsv gold.dat lead.dat silver.dat > element_summary.csv
Whoops, what is wrong with the make file that causes the following problem? How would you fix the problem?
[dharter@chaos tests]$ make clean
rm -v *.dat
removed `gold.dat'
removed `lead.dat'
removed `silver.dat'
[dharter@chaos tests]$ make
make: *** No rule to make target `gold.dat', needed by `gold.csv'. Stop.
The clean target should remove product files, not source files:
clean:
rm -v *.csv
(5 pts) In Python, what data type or data structure is held in each of the following variables. Possible answers include Boolean, String, List, Dictionary, Tuple, Integer, ImaginaryNumber, Function
items = [1, 2, 3] __List_________________
user = “Derek” __String_______________
dates = {“newton”: 1942, “einstein”: 1882} __Dictionary___________
point = (8,2) __Tuple________________
flag = True __Boolean______________
(10 pts) Given this variable assignment in python:
vals = [5, 20, 8, “red”, “green”, “blue”]
Write two versions of a Python loop that will print out each item in the variable on a separate line to standard output, one using indexes and one that doesn't use indexes. You should write this as a simple Python script, name the script loop.py, add it to your test directory in your repository working copy, and check the file in.
Example solutions are available checked in to example student harry repository. Do a
$ svn co http://nisl.tamu-commerce.edu/repo/csci553/harry/test harrytest
to see the solution
(2 pts) Given the following variable declaration in Python:
element = “hydrogen”
What is displayed on standard output if we do the following (remember that it helps here to think of the indices as being between elements):
print element[1:3], element[:2], element[4:-1]
yd hg oge
(4 pts) What is displayed after we execute the following Python statements:
birthday = {
'Newton' : 1642,
'Darwin' : 1809,
'Turing' : 1912
}
del birthday['Turing']
birthday['Einstein'] = 1888
names = birthday.keys()
names.sort()
for name in names:
print name, birthday[name]
Darwin 1809
Einstein 1888
Turing 1912
(12 pts) The following should be done in your student account. Copy the test script called TestLastUpper.py from /home/csci553/classfiles/TestLastUpper.py, add it to your test directory of your repository working copy, and check it in when you have completed the question.
You are to implement and test a function that accepts a single string as input, and returns a boolean result. The purpose of the function is to return true if the last (and only the last) character of the string is an upper case character. Currently the function does nothing, you need to provide the correct logic to implement the function as described.
Once you have implemented your function you should test it. A single test is already available for you in the script which tests a typical example where the function should return True:
isLastOnlyUpper('hellO') => True # test a true example
Once your function is working, you should add tests for all of the following as well, and make sure your function works for all of these cases:
isLastOnlyUpper('') => False # test the boundary condition of an empty string
isLastOnlyUpper('a') => False # test false boundary condition single character string
isLastOnlyUpper('A') => True # test true boundary condition single character string
isLastOnlyUpper('HellO') => False # test a false example
isLastOnlyUpper('hello') => False # a different failure case
Example solutions are available checked in to example student harry repository. Do a
$ svn co http://nisl.tamu-commerce.edu/repo/csci553/harry/test harrytest
to see the solution
CSci 553, Test
1