1 This file is times.def, from which is created times.c.
2 It implements the builtin "times" in Bash.
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
25 $FUNCTION times_builtin
27 Print the accumulated user and system times for processes run from
33 #if defined (HAVE_UNISTD_H)
35 # include <sys/types.h>
41 #include "../bashtypes.h"
44 #include <posixtime.h>
46 #if defined (HAVE_SYS_TIMES_H)
47 # include <sys/times.h>
48 #endif /* HAVE_SYS_TIMES_H */
50 #if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
51 # include <sys/resource.h>
56 /* Print the totals for system and user time used. */
61 #if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF)
62 struct rusage self, kids;
64 getrusage (RUSAGE_SELF, &self);
65 getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
67 print_timeval (stdout, &self.ru_utime);
69 print_timeval (stdout, &self.ru_stime);
71 print_timeval (stdout, &kids.ru_utime);
73 print_timeval (stdout, &kids.ru_stime);
77 # if defined (HAVE_TIMES)
78 /* This uses the POSIX.1/XPG5 times(2) interface, which fills in a
79 `struct tms' with values of type clock_t. */
84 print_clock_t (stdout, t.tms_utime);
86 print_clock_t (stdout, t.tms_stime);
88 print_clock_t (stdout, t.tms_cutime);
90 print_clock_t (stdout, t.tms_cstime);
92 # else /* !HAVE_TIMES */
93 printf ("0.00 0.00\n0.00 0.00\n");
94 # endif /* HAVE_TIMES */
95 #endif /* !HAVE_TIMES */
97 return (EXECUTION_SUCCESS);