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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA.
25 $FUNCTION times_builtin
27 Print the accumulated user and system times for processes run from
33 #if defined (HAVE_UNISTD_H)
38 #include "../bashtypes.h"
41 #if TIME_WITH_SYS_TIME
42 # include <sys/time.h>
45 # if defined (HAVE_SYS_TIME_H)
46 # include <sys/time.h>
52 #if defined (HAVE_SYS_TIMES_H)
53 # include <sys/times.h>
54 #endif /* HAVE_SYS_TIMES_H */
56 #if defined (HAVE_SYS_RESOURCE_H)
57 # include <sys/resource.h>
62 /* Print the totals for system and user time used. */
67 #if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF)
68 struct rusage self, kids;
70 getrusage (RUSAGE_SELF, &self);
71 getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
73 print_timeval (stdout, &self.ru_utime);
75 print_timeval (stdout, &self.ru_stime);
77 print_timeval (stdout, &kids.ru_utime);
79 print_timeval (stdout, &kids.ru_stime);
83 # if defined (HAVE_TIMES)
84 /* As of System V.3, HP-UX 6.5, and other ATT-like systems, this stuff is
85 returned in terms of clock ticks (HZ from sys/param.h). C'mon, guys.
86 This kind of stupid clock-dependent stuff is exactly the reason 4.2BSD
87 introduced the `timeval' struct. */
92 print_time_in_hz (stdout, t.tms_utime);
94 print_time_in_hz (stdout, t.tms_stime);
96 print_time_in_hz (stdout, t.tms_cutime);
98 print_time_in_hz (stdout, t.tms_cstime);
100 # else /* !HAVE_TIMES */
101 printf ("0.00 0.00\n0.00 0.00\n");
102 # endif /* HAVE_TIMES */
103 #endif /* !HAVE_TIMES */
105 return (EXECUTION_SUCCESS);