CS 497C - Quiz 3 - Name: ________________ Date: Friday, November 9 (in class) Part 1: (48 points - 4 points for each problem) (2) 1. Which one won't remove the file Wal*Mart? (1) rm 'Wal*Mart' (2) rm 'Wal\*Mart' (3) rm Wal*Mart (4) rm Wal\*Mart (1) 2. Which one is not equivalent to wc < in > out? (1) < out wc > in (2) > out wc < in (3) wc > out < in (4) < in wc > out (4) 3. Which command is used to break the output in two streams? (1) tar (2) tr (3) tail (4) tee (3) 4. You want to concatenate two files, a and b, but also insert some text in between from the terminal. How will you do this? (1) cat - a b > c (2) cat - a b > c (3) cat a - b > c (4) cat a b - > c (3) 5. How do you show lines 5 to 10 of the file {\tt foo}? (1) tail +5 foo | head (2) tail +10 foo | head -5 (3) head foo | tail +5 (4) head -5 foo | tail +10 (1) 6. How will you find out the lines common to two sorted files? (1) comm -12 foo1 foo2 (2) cmp -12 foo1 foo2 (3) comm -23 foo1 foo2 (4) cmp -23 foo1 foo2 (2) 7. How do you know how many different users are logging into the system? (1) who | uniq | sort | wc -l (2) who | cut -d' ' | uniq | wc -l (3) who | sort | uniq | wc -l (4) who | cut -d' ' | uniq -d | wc -l (2) 8. How do you remove duplicate lines from the file foo using sort? (1) sort -d foo (2) sort -u foo (3) sort -n foo (4) sort -p foo (1) 9. Which system variable is used to store the PID of the current shell? (1) $$ (2) $! (3) $% (4) %$ (4) 10. How do you find out the complete command line of a process run by user romeo? (1) ps -a -u romeo (2) ps -d -u romeo (3) ps -e -u romeo (4) ps -f -u romeo (3) 11. 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) 12. Which command can you use to schedule a job? (1) cal (2) schedule (3) set (4) at Part 2: (52 points) 1. What are three standard files in UNIX and what are their default source? (6 points) 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? (6 points) 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. What is command substitution? Give an example. (6 points) Ans: 1) The shell executes the command enclosed within a pair of back quotes (``) and places the command text where it occurs with the output the command generates. 2) echo Today is `date`. 4. Sort the file {\tt /etc/passwd} on GUID (primary) and UID (secondary) so that the users with same GUID are placed together. Users with a lower UID should be placed higher in the list. (5 points) Ans: You require to do a numeric sort on the fourth and third fields: sort -t: -n +3 +0 +2 /etc/passwd or sort -t: -n +3 -4 +2 /etc/passwd or sort -t: -n +3 -4 +2 -3 /etc/passwd 5. How will you find out the number of times the character ? occurs in a file? (5 points) Ans: Delete all characters except the ? and then make a character count with wc: tr -cd '?' < foo | wc -c 6. Consider the following text file shortlist: 2233|charles harris |g.m. |sales |12/12/52| 90000 9876|bill johnson |director |production|03/12/50|130000 5678|robert dylan |d.g.m. |marketing |04/19/43| 85000 2365|john woodcock |director |personnel |05/11/47|120000 Each line contains emp-id, name, designation, department, date of birth, and salary. Write the command to sort the file on the salary. (3 points) Write the command to find out the unique designations. (3 points) Ans: 1) sort -t'|' -n +5 +0 shortlist or sort -t'|' -n +5 -6 shortlist or sort -t'|' -n +5 shortlist 2) cut -d'|' -f3 shortlist | sort -u 7. What are three distinct phases in the creation of a process? Explain it. (6 points) 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. 8. What is a signal? What happens to a process when it receive a signal? (6 points) Ans: 1) A signal is an interrupt generated by the shell or even another process in response to some error condition. 2) When a process receives a signal, it has to do one of three things: (i) Do nothing. (ii) Ignore the signal. (iii) Trap the signal. 9. What can you do with the job control facilities? (6 points) 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).