csci-e215 Final Exam May 16, 1994, USA Your Name Here: ____________________ Instructions: You have two hours for this exam. This exam is `open notes and open book'. Please write your answers on the pages in this exam booklet. No scrap paper or additional sheets will be accepted. Watch your time, be concise, think before you write, look before you leap, listen before you accept, and always check the return value of a system call. Good luck. +------+--------+-----+---------+ | prob | points | got | section | +------+--------+-----+---------+ | 1 | 5 | | | +------+--------+-----+---------+ | 2 | 5 | | | +------+--------+-----+---------+ | 3 | 5 | | | +------+--------+-----+---------+ | 4 | 5 | | | +------+--------+-----+---------+ | 5 | 5 | | | +------+--------+-----+---------+ | 6 | 5 | | | +------+--------+-----+---------+ | 7 | 5 | | | +------+--------+-----+---------+ | | | | | +------+--------+-----+---------+ | 8 | 6 | | | +------+--------+-----+---------+ | 9 | 6 | | | +------+--------+-----+---------+ | 10 | 6 | | | +------+--------+-----+---------+ | 11 | 6 | | | +------+--------+-----+---------+ | 12 | 6 | | | +------+--------+-----+---------+ | 13 | 6 | | | +------+--------+-----+---------+ | 14 | 6 | | | +------+--------+-----+---------+ | | | | | +------+--------+-----+---------+ | a | 5 | | | +------+--------+-----+---------+ | b | 5 | | | +------+--------+-----+---------+ | c | 5 | | | +------+--------+-----+---------+ | d | 5 | | | +------+--------+-----+---------+ | e | 3 | | | +------+--------+-----+---------+ | | | | | +------+--------+-----+---------+ | | | | | +------+--------+-----+---------+ Part One Seven Problems, each worth 5 points page 1 _________________________________________________________________ Problems 1-7: Each problem describes a particular task. For each one, state which system call(s) you would use to perform that task. In the third column, state clearly and briefly the logic of your solution. Part Two Seven problems, each worth 6 points page 2 _________________________________________________________________ Problems 8-14: Compare and contrast. Each of these problems men- tions two related concepts, system calls, or operations. For each pair, explain briefly and clearly (a) what they have in com- mon, (b) when you would use the first item, and (c) when you would use the second item. 8. pipe() , socket() 9. open(), fopen() 10. stat(), ioctl() Part Two continued page 3 _________________________________________________________________ 11. rawmode, cbreak mode 12. sleep(), wait() 13. datagram socket, stream socket 14. errno, perror() Part Three One problem, 23 points page 4 _________________________________________________________________ 15. Another Unix utility: du The Unix utility called du is described in the manual as: Name du - print amount of disk usage Syntax du [-as] [name...] Description The du command gives the number of kilobytes contained in all files and, recursively, directories within each specified directory or file name. If name is missing, `.' is used. Absence of either -a or -s causes an entry to be generated for each directory only. A file that has two links to it is only counted once. Options -a Displays the disk usage for each file. -s Displays a summary total only. Bugs Non-directories given as arguments (not under -a option) are not listed. If there are too many distinct linked files, du counts the excess files multiply. For this part of the exam, answer the following questions about the design and components of du. Use the space on the remaining pages. a) What system calls will you need to use in writing du? What role will each play in the program? [5] b) Write a pseudo-code (or top-level function in C) that outlines the major operation of your program. [5] c) Do directories consume disk space? Why or why not? How does your program address this topic? [5] d) How will you handle the requirement that multiple links are counted once? Be quite specific, and discuss how to handle errors. [5] e) Fill in the details of the code to any degree of com- pleteness you like. [3] Part Three continued page 5 _________________________________________________________________ Part Three continued page 6 _________________________________________________________________