CS 497C - Quiz 3 Sample Questions
Part 1:
(4) 1. How do you redirect the standard error to a file?
(1) >> (2) > (3) 1> (4) 2>
(2) 2. Which command is used to break the output in two streams?
(1) tar (2) tee (3) tail (4) telnet
(1) 3. Which one is equivalent to cat foo | ispell -l?
(1) ispell -l < foo (2) ispell -l << foo
(3) ispell -l > foo (4) ispell -l >> foo
(1) 4. Which command can you use to translate characters in a character
stream?
(1) tr (2) pr (3) tee (4) tar
(2) 5. Which one is used to select only one copy of the repeated lines?
(1) uniq -u (2) uniq -d (3) uniq -c (4) uniq -i
(2) 6. How do you noninteractively check spelling?
(1) cat foo | ispell (2) ispell -l < foo (3) ispell foo (4) ispell < foo
(3) 7. Which one will you use to make sure that a process is killed?
(1) kill -7 (2) kill -8 (3) kill -9 (4) kill -10
(4) 8. Which command can you use to kill the login shell?
(1) kill 0 (2) kill $$ (3) kill -1 (4) kill -9 0
(1) 9. Which system variable is used to store the PID of the last
background job?
(1) $! (2) !! (3) $% (4) %!
Part 2:
1. Which are three standard files in the UNIX system and what are
their default source?
Ans: 1) Standard input - The default source is the keyboard.
2) Standard output - The default destination is the terminal.
3) Standard error - The default destination is the terminal.
2. What is a filter? Where does a filter get its input from?
Ans: 1) A filter is a command which uses both standard input and standard
output.
2) It can accept input from (i) a file with < (ii) a pipeline using |.
Most filters accpet input from the keyboard as well.
3. Select lines 5 to 10 of a file in two ways by using head and tail.
Ans: 1) tail +5 foo | head -6
2) head -10 foo | tail +5
4. How will you find out the number of times the character ? occurs
in a file?
Ans: Delete all characters except the ? and then make a character count
with wc:
tr -cd '?' < foo | wc -c
5. What are three distinct phases in the creation of a process? Explain
it.
Ans: 1) Fork - A copy of the process that invokes it is created.
2) Exec - The parent then overwrites the copy to create the child.
3) Wait - The parent waits for the death of the child.
6. What can you do with the job control facilities?
Ans: 1) Put a job to the background (bg).
2) Bring it back to the foreground (fg).
3) List the active jobs (jobs).
4) Suspend a foreground job ([Ctrl-z]).
5) Kill a job (kill).