CS439: Principles of Computer Systems
Discussion Section 5 Problem Set Solutions
Due in Section on Friday, February 27, 2026
The problem set must be completed before section and brought to section. To
ensure that your problem set is turned in correctly and that you receive credit
for discussion section, you must follow these guidelines exactly.
-
System Calls vs. Procedure Calls:
How much more expensive is a system call than a procedure call? Write
a simple test program to compare the cost of a simple procedure call
to a simple system call ("getuid()" is a good candidate on
UNIX; see the man page.) (Note: be careful to prevent the optimizing
compiler from "optimizing out" your procedure calls. Do not
compile with optimization on.)
- Explain the difference (if any) between the time required by your
simple procedure call and simple system call by discussing what work
each call must do (be specific). [Note: Do not provide the source code
for your program, just the results].
Hint: You should use system calls such as gethrtime()
or gettimeofday() for time measurements. Design your code such
that the measurement overhead is negligible. Also, be aware that timer
values in some systems have limited resolution (e.g., millisecond
resolution).
-
Write a C program that expects an integer command line argument, x,
and then uses recursion to print, Hello, World! x times.
Paste the code into your problem set.
Compile your program on the CS Linux machines
using gcc. Use command line options to:
- Name the executable file hello.
- Set the optimization to level 0.
-
Turn on the debugging information.
You may find the overview of gcc on the resource page of the website helpful.
What command did you use?
Run your program from within gdb with an argument of 5.
- Set a break point at the entrance to your recursive function.
- Print the value of the argument to the function.
- Step through each line of the function until Hello,
World! is printed.
- Continue the execution until the next breakpoint is reached.
Check the value of the argument, and, if it is not the last recursive
call, continue the program.
- On the last recursive call, print a backtrace of the call stack.
Identify the line number of the call to your recursive function
in main().
-
Return to your program and add an if statement in main after
the recursive call that reads:
if(x == x)
printf("Goodbye\n");
where x is the name of the argument to the recursive call. (If
you didn't save it into a variable before, please do so now!)
Recompile your program with the optimizations set to level 4.
Run your program using gdb, but set a breakpoint
in main for the if statement and inspect the value of x.
What do you learn?
-
What is a virtual address? What is a physical address? How do they
relate to each other?
-
Name two advantages of paging over relocation.
-
Consider a paging system with 16 pages and a page size of 256
bytes. The system has 1024 bytes of physical memory.
- How many bits are in a physical address?
- How many bits represent the page number?
- How many bits are in the complete virtual address?
- What size are the page frames?
|