Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
/usr/bin/time always give 0 for average resident set size

I am trying to use /usr/bin/time to collect the average resident set size of programs. I tried this command with several programs but the average resident set size is always zero. For example:

/usr/bin/time result

My OS is ubuntu 10.04.

Could you please tell me what is the reason or how I can fix it? Thank you very much!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Look, /usr/bin/time does not calculate this data itself. It uses wait4 to get this data from Linux. This is a description of wait4:

>man wait4

       pid_t wait4(pid_t pid, int *status, int options,
                   struct rusage *rusage);

The problem is that not all fields in struct ruusage are maintained:

   Not all fields are completed; unmaintained fields are set to zero by
   the kernel.  (The unmaintained fields are provided for compatibility
   with other systems, and because they may one day be supported on
   Linux.)  The fields are interpreted as follows:

While maxrss is mantained other fields about rss are not. So it just returns returns 0 and /usr/bin/time also prints 0.

Moreover, if you take a look at source files of GNU time you will see this code:

/*
FMT is the format string, interpreted as described above.
*/
static void
summarize (fp, fmt, command, resp)
     FILE *fp;
     const char *fmt;
     const char **command;
     RESUSE *resp;
{

  while (*fmt)
    {
      switch (*fmt)
    {

        case 'M':       /* Maximum resident set size.  */
          fprintf (fp, "%lu", ptok ((UL) resp->ru.ru_maxrss));
          break;

        case 't':       /* Average resident set size.  */
          fprintf (fp, "%lu",
               MSEC_TO_TICKS (v) == 0 ? 0 :
               ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v));

Since ru_idrss is returned by Linux as 0 then average resident set size is 0.

Useful links:

  • http://man7.org/linux/man-pages/man2/getrusage.2.html
  • Is getrusage broken in Linux (2.6.30)
  • http://ftp.gnu.org/gnu/time/
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!