title: How getrusage works and What is really inside the rusage struct?
body: <p>I'm trying to understand how</p>
  
  <pre><code>int getrusage(int who, struct rusage* usage)
  </code></pre>
  
  <p>works in order to calculate the running time of one my program.<br> I red the man page, 10 times maybe, and still can't get it. Tried to find something on the web, but nothing but the man page about this function is found.<br> What is unclear to me is what is stored inside the rusage struct - the man page isn't very clear - so I tried to run it with a debugger and directly see what's inside, but Still do not understand it, particularly how the two structs - timeval ru_utime and timeval ru_stime - work.<br> What's inside them assume different values, sometime 0, other times 2000 etc.<br><br>I ran a simple program with a for loop that allocates and frees memory continually. I used a stopwatch to actually see how many time it takes, it took 5.23 secs. But what I see in those structs seems to be completely unrelated:<br><br>Before loop:<br>ru_utime = { tv_sec = 0, tv_usec = 1000}, ru_stime = { tv_sec = 0, tv_usec = 1000}<br>After loop:<br> ru_utime = { tv_sec = 4, tv_usec = 677000}, ru_stime = { tv_sec = 0, tv_usec = 2000}<br><br>so, Can anybody explain this to me or give some good link where this is explained?<br> I shall be very grateful.</p>