A 4 marks Say whether each of the following statements is tr

A. (4 marks)

Say whether each of the following statements is true (“T”) or false (“F”).

__ An environment variable is a shell variable whose name begins with a ‘$’ character, as in “$PATH”.

__ The programming guidelines given in class for C/C++ programs and TDD stipulate that function tem-

plates should follow a \"preamble, definition, stub\" pattern.

__ One of the guidelines to proper testing is to know what to expect as output from each test case.

__ In LINUX/UNIX a data type of “long int *” (i.e. pointer to long int) is always 8 bytes in size.

B. (1 mark each, 5 marks total)

In each of the statements below, fill in the blank with the word or phrase which best fits the overall state- ment.

A(n) ___________________ is a named sequence of addressable, nonvolatile bytes.

A(n) _________________ is that portion of the operating system that provides only the minimum of serv- ices necessary for implementing additional O/S services. It is typically responsible for interfacing to hardware, implementing the process abstraction, and coordinating processes of multiple users.

The file ________________ is a “configuration file” for bash. It contains commands which are executed upon startup by the shell program.

A key feature of the iterative software development method is the extensive use of ________________ .

In a file name pattern (specified to the shell), a \'____\' character matches any single character.

C. (10 marks)

For each of the following multiple-choice1 questions, indicate the answer that is the best response to the question. Circle the label (e.g. “(a)”) of your intended response in each case.

1. Suppose that your working directory is currently /usr/tmp, and that you would like to specify the file stuff.txt in your home directory as an argument on the shell command line. You could specify that file via which of the following?
(a) /stuff.txt

(b) ./stuff.txt
(c) ~/stuff.txt
(d) ../stuff.txt (e) ~home/stuff.txt (f) None of the above.

2. You require some detailed, authoritative information on the operational details of a particular UNIX/ LINUX command. The best source for this information is

(a) the \"man page\" for the command as provided by info(1).

(b) a site you found on the WWW using a Google search with the command name as the keyword.

(c) the person who happens to be sitting next to you in the lab.

(d) a response you received to a “tweet” you gave on Twitter asking for assistance and information.

(e) Any of the above

What is the function of the “>>” operator in the bash command cat foo >> bar

? Assume that the noclobber shell variable is set to its default value.

(a) Passes output of cat(1) to the program (command) bar.

(b) Indicates that data from the file bar should be considered (input) after the data from file foo.

(c) Overwrites file bar with the contents of file foo.

(d) Redirects error messages from the execution of cat into file foo.

(e) None of the above.

In UNIX/LINUX the files to implement most standard user commands are found in

(a) /usr/local/bin

(b) /bin

(c) /usr/X11R6/bin

(d) /usr/bin

(e) None of the above.

Suppose that a program or command, started from the shell, is reading from stdin, and that stdin is cur- rently the keyboard. Typing which of the following characters will be interpreted by the operating sys- tem as indicating an EOF (end-of-file) on stdin? (Note that \"^\" below indicates a control character).

(a) ^C

(b) ^D

(c) ^H

(d) ^S

(e) ^Z

(f) None of the above.

A user wishes to use a portion of LINUX/UNIX software named swab. The man page for swab is de- notedas\"swab(3)\". Thismeansthatswabisa

(a) user command.

(b) kernel call.

(c) library function.

(d) device.

(e) file format.

(f) system administration command.

(g) None of the above.

Which of the following LINUX/UNIX commands will indicate the amount of free space (available stor- age) on all the individual file systems mounted on the current, overall file system?

(a) whatis (b) uptime (c) diff (d) stty (e) grep

(f) None of the above.

page 3

Cmpt 214 Midterm Examination

October 22, 2015

In the context of C/C++ programming practice, an idiom is

(a) a person of low IQ.

(b) the conventional way that experienced programmers write common pieces of code.

(c) the template that must be followed for typedef statements in TDD.

(d) a type of for-loop.

(e) None of the above.

Which of the following shell commands is a request to the shell to reissue the previous command?

(a) !!

(b) repeat

(c) back

(d) #!

(e) None of the above.

10. A test scaffold

(a) is a type of testing that exercises all boundary conditions for a piece of (program) code.

(b) is necessary for performing level 6 testing.

(c) does not need to be tested, even if it is complex.

(d) is a portion of code that provides a framework or context for a test to run.

(e) None of the above.

D.

(5+2+1+1+1+1 = 11 marks)

Answer each of the following questions with a very short, precise answer. 1. Consider the following C++ program:

}

The program is compiled without errors, producing the executable program a.out in the current working directory. When invoked by

./a.out

the program produces

on the user’s virtual terminal window.

page 4

Cmpt 214 Midterm Examination October 22, 2015

The program is then invoked with a number of different bash commands. Each command redirects standard output and standard error. However, the commands perform the redirection in different ways. To understand the “net effect” of each command, we will consider what is produced on the user’s virtual terminal, in file log_stdout, in file log_stderr, and in file log.
For each of the following pairs of commands, say whether or not the commands in the pair have the same net effect. Say “same” if the commands in the pair have the same net effect. Say “different” if there is a difference in net effect.

(a) ./a.out 1> log_stdout 2> log_stderr ./a.out 2> log_stderr 1> log_stdout

(b) ./a.out 1> log_stdout 2> log_stderr ./a.out 1> log_stderr 2> log_stdout

(c) ./a.out 1> log_stdout 2> log_stderr ./a.out 2> log_stdout 1> log_stderr

(d) ./a.out 1>log 2>&1 ./a.out 2>&1 1>log

(e) ./a.out 1>log 2>&1 ./a.out 2>log 1>&2

Suppose that a file stuff.txt contains the following lines of text: foo,har

Now suppose that we issue the following command

What is the first letter of the result (the first character output)?

Consider the following shell command

kill -TERM %1
What does the “%1” refer to? What is “1”?

Consider the following declaration in C/C++:

int32_t x[1024][860][3]
What is the type (datatype) of x[34][56] ?

page 5

Cmpt 214 Midterm Examination October 22, 2015

5.

6.

E.

Suppose your current working directory contains the following files (and only these files):

Suppose you give the following command:

How many file names will be output?
What is the name of a standard UNIX/LINUX command that will output the (system) “load average”?

(5+4+5 = 14 marks)

The following questions involve diagrams and figures. Complete them as directed.

2. Suppose the output from a ps -l command on tuxworld is the following: bash-4.3$ ps -l

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY
0 R 12000 28931 28930 0 80 0- 1602- pts/28
0 S 12000 28334 28317 0 80 0 - 3136 rt_sig pts/28 00:00:00 tcsh
0 S 12000 28928 28334 0 80 0 - 976 hrtime pts/28 00:00:00 myprog 0 S 12000 28930 28334 0 80 0 - 3332 wait pts/28 00:00:00 bash

In the space below draw the process hierarchy reflected in the information from ps. Identify each proc- ess in the diagram by its PID and the command it is executing. Also indicate the parent-child relation- ships between the processes using directed edges. Make your diagram as understandable as possible.

Cmpt 214 Midterm Examination October 22, 2015

F. (1 mark each, total 6 marks)

Consider the following recommendations and guidelines from class regarding programming style, defensive programming, and programming practice:

a) use symbolic names for “magic numbers”, literal numeric values that appear in programs

b) use a consistent style for indentation and use of white space in a program

c) use a consistent style for placement of { } when specifying a statement block in an if-then-else statement

d) don’t have useless comments (comments that state the obvious)

e) write clear code, not clever code

f) use a “preamble, definition, sample usage” pattern for data definitions

g) follow programming idioms

h) be consistent in naming (constants, data types, variables, functions); adopt a single naming convention

and stick to it

For each of each of the following program fragments, indicate the letter (label) associated with the recom- mendation(s) or guideline(s) above violated by that fragment. If the fragment appears to violate multiple recommendations or guidelines, choose the one most seriously violated. Necessarily, some of the recommen- dations and guidelines above will not be violated by any of the examples below.

1.

}
else {

y = 0; }

2.

}; 3. if(

4. n=5;
for(;n<100;field[n++]=\'\\0\');
*end=\'\\0\'; return( \'\ \' );

char buffer[500], mssg[80];
void read_instance( void ), SaveCurrent( void );

i++; // increment i

page 8

Cmpt 214 Midterm Examination October 22, 2015

G. (1 mark each, total 6 marks)

Suppose that the file phone_directory.txt contains the following lines of information. Each line consists of 4 fields (columns) separated by single tab characters. The fields are obvious from viewing the layout of the file when it is printed on a terminal:

A Hacker Alyssa P B Ator Eva Lu C Reasoner Louis A D BitDiddle Ben B E Fect Cyd E F Tweakit Lem E

We will refer to the above lines in phone_directory.txt by the letters A through F to the left of each line. For example, A refers the first line, while F refers to the final line. The labelling letters are not part of the lines of text in the file.
Below are commands (given to bash) that operate on phone_directory.txt. The commands may or may not produce any output. For each of the commands, enter the letter label (A–F) of the line in the file phone_directory.txt which originally contained the text which is output first. That is, for all the commands below, answer the question, “which of the above lines contains the text that first appears in response to the command?” For example, if a command first yields a line consisting of the text “Eva” from the second line in phone_directory.txt, you should enter “B” as the answer to the question (reflecting the fact that this text came from line “B” of phone_directory.txt). Additionally, if the command generates no output, enter “N”. Finally, if none of the answers A–F or N is correct, enter “X” as indicating “None of the above”.

grep \'A\' phone_directory.txt

grep \'^A\' phone_directory.txt

egrep \'([a-zA-Z])\\1\' phone_directory.txt

grep -E \'(ab)\\w\' phone_directory.txt

egrep \'[a-zA-Z]{2}\' phone_directory.txt

cat phone_directory.txt phone_directory.txt | sort | uniq | tail -2 | head

H. (2+3+4 = 9 marks)

Answer each of the following questions with a technically-oriented answer. In some cases, a very short, pre- cise answer is in order. In others, a concise descriptive answer is required.

1. A user has a file whose name contains a space character, \' \'. For example, the file might be named \"the exam\". The user wishes to invoke the more command on this file. The user types

more the exam

to the shell. Unfortunately, the outcome is not as the user intended; an error message is produced say- ing that files ”the” and ”exam” could not be found. Give a fix to the problem above. What should the user have typed to obtain the functionality she wanted?

page 9

Cmpt 214 Midterm Examination October 22, 2015

2. Consider the following program for copying n bytes from the location pointed to by src to the location pointed to by dst:

char *d, *s;

d=dst;

s=src;

while(n-->=0){

*d++ = *s++; }
}

You can assume that it is guaranteed that there are at least n+1 characters at the memory location pointed to by src, and that the memory space pointed to dst is at least n+1 characters in size. Also, it is not required that a terminating null byte is copied.
The function above contains an error. Describe a test case that you could use to cause the error to be manifest (to appear). That is, give a description of what you could set src, dst, and n to so that the func- tion would exhibit the bug it contains.

3. Consider the following C/C++ function similar to one used in class:

}

} }

return;

// 1 // 2

// 3

} else {

// 9 // 10

Suppose that the function is tested with inputs 0, 1, and 2000. That is, the function is tested with year set successively to 0, 1, and 2000.

// 5 // 6 // 7

page 10

Cmpt 214 Midterm Examination October 22, 2015

(a) What is the path coverage of this test set? Give your answer as a percentage or ratio. To make this calculation easier, lines with executable statements have been numbered in the function.

(b) What condition coverage is provided by this test set? Give your answer as a percentage or ratio.

Solution

A)1.True , Since all environment variable are dynamic in nature so it start with \"$\"

2. Ture, Test driven development shows it.

3. True, to test anything we need to know what will be output of each test scinarios.

4. False,pointer size always depends on what address system there in system.

A. (4 marks) Say whether each of the following statements is true (“T”) or false (“F”). __ An environment variable is a shell variable whose name begins with a
A. (4 marks) Say whether each of the following statements is true (“T”) or false (“F”). __ An environment variable is a shell variable whose name begins with a
A. (4 marks) Say whether each of the following statements is true (“T”) or false (“F”). __ An environment variable is a shell variable whose name begins with a
A. (4 marks) Say whether each of the following statements is true (“T”) or false (“F”). __ An environment variable is a shell variable whose name begins with a
A. (4 marks) Say whether each of the following statements is true (“T”) or false (“F”). __ An environment variable is a shell variable whose name begins with a
A. (4 marks) Say whether each of the following statements is true (“T”) or false (“F”). __ An environment variable is a shell variable whose name begins with a
A. (4 marks) Say whether each of the following statements is true (“T”) or false (“F”). __ An environment variable is a shell variable whose name begins with a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site