1 This file is times.def, from which is created times.c.
2 It implements the builtin "times" in Bash.
4 Copyright (C) 1987-2009 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
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 Bash is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Bash. If not, see <http://www.gnu.org/licenses/>.
24 $FUNCTION times_builtin
26 Display process times.
28 Prints the accumulated user and system times for the shell and all of its
37 #if defined (HAVE_UNISTD_H)
39 # include <sys/types.h>
45 #include "../bashtypes.h"
48 #include <posixtime.h>
50 #if defined (HAVE_SYS_TIMES_H)
51 # include <sys/times.h>
52 #endif /* HAVE_SYS_TIMES_H */
54 #if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
55 # include <sys/resource.h>
60 /* Print the totals for system and user time used. */
65 #if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF)
66 struct rusage self, kids;
70 if (no_options (list))
73 getrusage (RUSAGE_SELF, &self);
74 getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
76 print_timeval (stdout, &self.ru_utime);
78 print_timeval (stdout, &self.ru_stime);
80 print_timeval (stdout, &kids.ru_utime);
82 print_timeval (stdout, &kids.ru_stime);
86 # if defined (HAVE_TIMES)
87 /* This uses the POSIX.1/XPG5 times(2) interface, which fills in a
88 `struct tms' with values of type clock_t. */
93 if (no_options (list))
98 print_clock_t (stdout, t.tms_utime);
100 print_clock_t (stdout, t.tms_stime);
102 print_clock_t (stdout, t.tms_cutime);
104 print_clock_t (stdout, t.tms_cstime);
107 # else /* !HAVE_TIMES */
111 if (no_options (list))
113 printf ("0.00 0.00\n0.00 0.00\n");
115 # endif /* HAVE_TIMES */
116 #endif /* !HAVE_TIMES */
118 return (sh_chkwrite (EXECUTION_SUCCESS));