Review Problems for CS 302 / ECE 468 Exam 1 Spring 2009 March 2, 2009. Version 1.0. (In case I need to modify something.) 1. Look at the following problems at the end of Chapters 1-4 from our textbook "Operating Systems Concepts". Chapter 1, page 42, Exercises 1, 2, 3, 7, 8, 22. Chapter 2, page 91, Exercises 1, 2, 3, 5, 13, 17. Chapter 3, page 141, Exercises 3, 6, 7, 9, 10. Chapter 4, page 174, Exercises 1, 2, 3, 4, 7, 9, 10, 11. 2. If you can only run one program at a time, is it still useful to have an operating system? Why or why not? 3. Name three major resources controlled by an operating system. 4. Which of the following machine instructions should be privileged? Explain why. a) Set the value of the timer b) Set the value of the system clock c) Switch from user to supervisor mode 5. Which of the following operations should be privileged? Explain why. a) Read from any sector of the system disk drive b) Read from any sector of a CD-ROM drive c) Read from any sector of a floppy disk drive d) Write directly to a printer 6. What is the difference between an interrupt and a system call? What is the relationship between system calls and mode switches? 7. What is a buffer? Why does the operating system need buffers in the kernel space? Why does an application need buffers in user space? 8. The kernel keeps a data structure for each process, called the Process Control Block (PCB). When a process is not running, its PCB contains the information that is necessary to restart the process on a CPU. List four pieces of information that the PCB must have. 9. What are the different states a process can be in? What are the possible transitions between states? (Draw a picture.) What events can cause each of those transitions to happen? 10. What is a context switch? 11. The kernel keeps a data structure for each thread, called the Thread Control Block (TCB). What is the relationship between thread control blocks and process control blocks. 12. How does creating a thread differ from creating a process? How does context switching for threads differ from context switching for processes. 13.Give four causes for a running process (or thread) to relinquish the CPU. 14. List three things that a running process (or thread) might do that would cause the scheduler not to move it to the ready state when it stops running. 15. Use process (or thread) states to describe the difference between the two function calls Sleep(0) and Sleep(1). 16. Use process (or thread) states to explain the difference between busy waiting and blocking. 17. a) In general, blocking is better than busy waiting. Explain why. b) If it is known in advance that a wait will be very short, then busy waiting can be better than blocking. Explain why. 18. When a process (or thread) runs, there are three measures of run time that are useful, wall clock time, user time, and kernel time. Define each of these. Explain why wall clock time will almost never equal user time plus kernel time. Explain what kind of relationship you would expect to see between the three times for an "I/O bound" process (or thread). Explain what kind of relationship you would expect to see between the three times for an "CPU bound" process (or thread). 19. It is possible for a thread to be completely CPU bound in user space, that is, it makes no system calls, and yet the thread may accumulate some kernel time. How can that be? (Hint: Think about what some other processes might be doing.) 20. Assume the following program. int a[300]; int b = 25; void c() { int d; } int main() { static int e; int * p = new int; } Write the memory section for the running program that corresponds to each of the following memory addresses (the memory sections are: TEXT, DATA, BSS, STACK, HEAP). Memory Address | Section --------------------------- &a | &b | c | &d | &e | &p | p | main | 21. Explain in detail the difference between the following three functions. int functionA() { static int i; i++; return i; } int functionB() { static int i = 0; i++; return i; } int functionC() { static int i; i = 0; i++; return i; } 22. In what way is a static local variable like a global variable? In what way are they different? (Hint: Lifetime and scope.) 23. What does the following functionA() do? int functionA(int i) { static int j = 0; int k; k = j; j = i; if (k > j) return k; else return j; } 24. Determine which of the following C expressions are equivalent to a[i]. The type of a[0] is denoted by . Expression a + i a + i * sizeof() &a + i *(a + i) *(a[0] + i) *(&a[0] + i) *(&a[i]) &a[i] *( *) ((char *) &a[0] + i ) *( *) ((char *)&a[0] + i * sizeof(a[0])) 25. In the declaration int i[10]; the type of i is an array of 10 ints. Describe in words the type if i in each of the following declarations. int *i[10]; int (*i)[10]; int **i[10]; int *(*i)[]; int *(i[]); 26. (a) Write a declaration for a function named f that takes one integer as input and returns a pointer to an array of integers. (b) Write a declaration for an array named holyCow of pointers to functions that take as input an array of char and return a pointer to an int. 27. Suppose you write a C module myStuff.c and in that module you call the function herStuff() but the definition of the function is not in your module. Explain three different places where the definition of the function herStuff() might be. For each place where the definition might be, explain which program, the compiler, the linker, or the loader, will find the definition. 28. Suppose that you wrote a program in C. What does it mean to say that your program is a "Win32 program" or that your program is a "Posix program" or a "Standard C program"? Explain your answer in terms of the compile, link, load process. 29. In homework assignment 3, it is possible to cause the linker to make drastic mistakes. If you mismatch the calling convention for a function implementation in the dll with the function declaration in the client program, the linker may not notice (try this with different combinations of the compilers gcc, cl, and lcc). Which is worse, a callee cleanup reference being linked to a caller clean up definition, or a caller cleanup reference being linked to a callee cleanup definition? (Hint: One causes an immediate problem, the other causes a delayed, or possibly no, problem.) 30. Microsoft's compiler tries to avoid the problems mentioned in the last problem by mangling the names of functions declared _stdcall. Explain how name mangling is supposed to help. Where in the compile, link, load process did this safeguard get circumvented in assignment 3 with dllBlues.c and theCure.c?