<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">This file is times.def, from which is created times.c.
It implements the builtin "times" in Bash.

Copyright (C) 1987-2002 Free Software Foundation, Inc.

This file is part of GNU Bash, the Bourne Again SHell.

Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

Bash is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING.  If not, write to the Free Software
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.

$PRODUCES times.c

$BUILTIN times
$FUNCTION times_builtin
$SHORT_DOC times
Print the accumulated user and system times for processes run from
the shell.
$END

#include &lt;config.h&gt;

#if defined (HAVE_UNISTD_H)
#  ifdef _MINIX
#    include &lt;sys/types.h&gt;
#  endif
#  include &lt;unistd.h&gt;
#endif

#include &lt;stdio.h&gt;
#include "../bashtypes.h"
#include "../shell.h"

#include &lt;posixtime.h&gt;

#if defined (HAVE_SYS_TIMES_H)
#  include &lt;sys/times.h&gt;
#endif /* HAVE_SYS_TIMES_H */

#if defined (HAVE_SYS_RESOURCE_H) &amp;&amp; !defined (RLIMTYPE)
#  include &lt;sys/resource.h&gt;
#endif

#include "common.h"

/* Print the totals for system and user time used. */
int
times_builtin (list)
     WORD_LIST *list;
{
#if defined (HAVE_GETRUSAGE) &amp;&amp; defined (HAVE_TIMEVAL) &amp;&amp; defined (RUSAGE_SELF)
  struct rusage self, kids;

  USE_VAR(list);

  if (no_options (list))
    return (EX_USAGE);

  getrusage (RUSAGE_SELF, &amp;self);
  getrusage (RUSAGE_CHILDREN, &amp;kids);	/* terminated child processes */

  print_timeval (stdout, &amp;self.ru_utime);
  putchar (' ');
  print_timeval (stdout, &amp;self.ru_stime);
  putchar ('\n');
  print_timeval (stdout, &amp;kids.ru_utime);
  putchar (' ');
  print_timeval (stdout, &amp;kids.ru_stime);
  putchar ('\n');

#else
#  if defined (HAVE_TIMES)
  /* This uses the POSIX.1/XPG5 times(2) interface, which fills in a 
     `struct tms' with values of type clock_t. */
  struct tms t;

  USE_VAR(list);

  if (no_options (list))
    return (EX_USAGE);

  times (&amp;t);

  print_clock_t (stdout, t.tms_utime);
  putchar (' ');
  print_clock_t (stdout, t.tms_stime);
  putchar ('\n');
  print_clock_t (stdout, t.tms_cutime);
  putchar (' ');
  print_clock_t (stdout, t.tms_cstime);
  putchar ('\n');

#  else /* !HAVE_TIMES */

  USE_VAR(list);

  if (no_options (list))
    return (EX_USAGE);
  printf ("0.00 0.00\n0.00 0.00\n");

#  endif /* HAVE_TIMES */
#endif /* !HAVE_TIMES */

  return (EXECUTION_SUCCESS);
}
</pre></body></html>