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: