1 This file is times.def
, from which is created times.c.
2 It implements the builtin
"times" in Bash.
4 Copyright (C
) 1987-2002 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
;
66 if (no_options (list
))
69 getrusage (RUSAGE_SELF
, &self
);
70 getrusage (RUSAGE_CHILDREN
, &kids
); /* terminated child processes
*/
72 print_timeval (stdout
, &self.ru_utime
);
74 print_timeval (stdout
, &self.ru_stime
);
76 print_timeval (stdout
, &kids.ru_utime
);
78 print_timeval (stdout
, &kids.ru_stime
);
82 # if
defined (HAVE_TIMES
)
83 /* This uses the POSIX
.1/XPG5
times(2) interface
, which fills in a
84 `struct tms
' with values of type clock_t. */
89 if (no_options (list))
94 print_clock_t (stdout, t.tms_utime);
96 print_clock_t (stdout, t.tms_stime);
98 print_clock_t (stdout, t.tms_cutime);
100 print_clock_t (stdout, t.tms_cstime);
103 # else /* !HAVE_TIMES */
107 if (no_options (list))
109 printf ("0.00 0.00\n0.00 0.00\n");
111 # endif /* HAVE_TIMES */
112 #endif /* !HAVE_TIMES */
114 return (EXECUTION_SUCCESS);