HOMEWORK 3 (COMMENTS AND COMMON MISTAKES) << General >> o If a problem asks "why is the output correct", the answer is not "because it works as expected". + What are the properties that make you think the output is correct? Are the times consistent with past experience? e.g., The output of 'ls' ... + Try to quantify instead of using "very large" and "very very large" << Problem 5>> << Problem 6>> o Problems with using gettimeofday(3) + gettimeofday(3) returns time since Jan 1, 1970. - The tv_sec and tv_usec components are each 32-bit integers (long ints) - This will result in the number of seconds being a 10-digit decimal number after conversion and the number of microseconds being a 16-digit decimal number. - int64_t converts to a 20-digit decimal number. - Need to be careful when computing the difference (tend - tbegin). + Need to use BOTH components of a struct timeval and treat as a vector Example: sec usec | | v v tbegin = (X, Y) tend = (X+1, Y-Z) If you subtract component-by-component, this will happen: tend - tbegin = (1, -Z) i.e., elapsed time is 1 sec, -Z usec. But you really wanted: tend - tbegin = (0, 10^6-Z) + Truncation can occur unless you force the use of 64-bit integer arithmetic int64_t t = 1000000*(end.tv_sec - begin.tv_sec) + (end.tv_usec - begin.tv_usec); is likely to compute using int32_t and then truncate during assignment. Better is something like this which forces use of 64-bit integer arithmetic: int64_t t = 1000000*(((int64_t)end.tv_sec) - begin.tv_sec) + (end.tv_usec - begin.tv_usec); double also works. + Would help if the key time output values were labeled with units. Maybe ok to leave off units in debug output. << Problem 7>> o There are various command line flags for the ps command ps -e Show every process ps -ejH Show process tree ps l Show BSD long format