Review Problems for CS 59000-01, Operating Systems, Exam 1 Spring 2015 Version 1.0. (In case I modify something.) The exam is over Chapters 1, 2, 3, 4, 8, 9, and 10 from the textbook. 1. This question is about I/O redirection and pipes on the command line. Explain what each of the following possible command lines mean. In each problem, you need to associate an appropriate meaning to the symbols a, b and c (for example "a is the name of a program, b and c are the names of files" or "a and b are the names of programs and c is the name of a file" or "a is the name of a program, b and c are parameters to the program"). $ a > b < c $ a < b > c $ a | b > c $ a < b | c $ a ; b ; c $ a ; b > c $ a ; b | c $ a && b < c $ a || b < c $ a < b ; c $ a < b & c $ a || b | c $ a && b ; c $ a && b || c 2. What problem is there with the following two command lines? $ a | b < c $ a > b | c 3. How would you draw a picture illustrating the processes and files in this command-line? $ a < b | c 2> d | e > f 2> d 4. Give an explanation of how the ideas of "standard in", "standard out", "I/O redirection", "pipes", "processes", and "files" are being used in the following command-line. (You should include a picture that clearly illustrates each of the mentioned ideas.) $ b < a | c > d 5. What is the purpose of environment variables? Give one example. 6. What does the term "built-in command" mean in the shell? 7. What is the difference between a system call and a library function? Give an example of each. 8. Why is it considered a bad idea to write programs that make more system calls than are necessary? 9. What is errno? What is it for? How is it used? 10. What does the function perror() do and when would you use it? 11. Briefly describe "buffered input". What is it, and why is it done? 12. Suppose a process has successfully opened a file object, fp, for reading a file from a disk drive and the program has created a buffer, my_buf, of an appropriate size. Consider the following C function call. fread(my_buf, 1, BUFFERSIZE, fp); a) Explain why this function call may, or may not, cause a system call to the operating system's read(). b) Suppose the the above function call causes a system call. Explain why the operating system may, or may not, initiate an I/O operation to read data from the file on the disk drive. 13. Explain the difference between a program and a process. 14. What is the difference between execl() and execv()? When do you use which? How do you use each? 15. What is the role of the fork() system call? Explain the meaning of its return value and how the return value is used. 16. When a Unix program wants to run another program, it calls fork() then exec(). Why not have one system call to run_program()? Name two useful activities a process can perform between the fork() and the exec(). 17. What is the relationship between the systems calls exit() and wait()? 18. What is a zombie process? What causes them? 19. What three files are open when every process starts? 20. What system calls do you use to redirect the standard input of a process to come from a file? How do you use them? 21. What are inodes and where are they stored? 22. The inode of a file contains fields for both the type of the file and the mode of the file. What is the difference between these two attributes? How are these set, changed, and what do they affect? 23. How does Unix store time and date values for things like file modification times and user login times? 24. Almost all the information about a file is stored in an inode. Name one important piece of information about a file that is not stored in the inode. What are the advantages of not storing this property in the inode? 25. If you know the inode number of a file, how can you find the name of the file? 26. Why is the system call that deletes a file called unlink() rather than delete()? 27. What is the difference between making a copy of a file and making a link to a file? 28. When you create a new file, it has a size of zero bytes. When you create a new directory, it has non-zero size. Why do directories never have size zero? 29. What is the "lowest available file descriptor" principle? Why is it useful? 30. What is the difference between open() and fopen()? Name one advantage of each and one disadvantage of each. 31. Each of the following parts mentions two related concepts. For each pair, explain briefly and clearly (i) what they have in common, (ii) how they differ. a) ln, cp b) fopen(), fdopen() c) dup(), open() d) sleep(), wait() 32. This code is a version of the Unix mv command. mv renames a file, accepting as command line arguments the old name and the new name. Explain, line by line, how this code works. int main(int ac, char *av[]) { if ( link(av[1], av[2]) != -1 ) { unlink( av[1] ); } else if ( errno == EEXIST ) { unlink( av[2] ); main(ac, av); } else { perror("link"); exit(1); } return 0; } 33. With a function prototype of the form f(DS * x, ...); the caller must allocate storage for the data structure pointed to by the parameter x. Explain why it is that the callee cannot do the allocation of the storage for the data structure. 34. With a function prototype of the form f(DS ** x, ...); the callee may do the allocation of the storage for the data structure. Explain why the callee can now do the allocation and show how it would be done. (Drawing a picture might help.)