Home | CS439 |
Discussion Section Problem Set #: Student Name: EID:
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.)
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).
Create a toy hello world program, and give it a name of an unimportant executable (like sl) then edit your PATH so that this program is run instead of its real equivalent. How did you change your PATH, and what does this say about the shell picks programs to run based on your PATH?
Now remove execute permissions from your toy program using chmod -x {program_name}. What happens when you type your programs name into your shell?
Hint: The following commands temporarily edit your PATH, try running them and note how your PATH changes.
export PATH=$PATH:{new_directory}
export PATH={new_directory}:$PATH
Hint 2: sl does not allow keyboard interrupts by default. You might find it useful to read the man pages of sl using man sl.