Added gitignore entries needed to ignore derived objects generated from full build...
[bash.git] / builtins / times.def
blobf31f43331e96a8cb5a5961d75c4696ef0920e229
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/>.
21 $PRODUCES times.c
23 $BUILTIN times
24 $FUNCTION times_builtin
25 $SHORT_DOC times
26 Display process times.
28 Prints the accumulated user and system times for the shell and all of its
29 child processes.
31 Exit Status:
32 Always succeeds.
33 $END
35 #include <config.h>
37 #if defined (HAVE_UNISTD_H)
38 # ifdef _MINIX
39 # include <sys/types.h>
40 # endif
41 # include <unistd.h>
42 #endif
44 #include <stdio.h>
45 #include "../bashtypes.h"
46 #include "../shell.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>
56 #endif
58 #include "common.h"
60 /* Print the totals for system and user time used. */
61 int
62 times_builtin (list)
63 WORD_LIST *list;
65 #if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF)
66 struct rusage self, kids;
68 USE_VAR(list);
70 if (no_options (list))
71 return (EX_USAGE);
73 getrusage (RUSAGE_SELF, &self);
74 getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
76 print_timeval (stdout, &self.ru_utime);
77 putchar (' ');
78 print_timeval (stdout, &self.ru_stime);
79 putchar ('\n');
80 print_timeval (stdout, &kids.ru_utime);
81 putchar (' ');
82 print_timeval (stdout, &kids.ru_stime);
83 putchar ('\n');
85 #else
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. */
89 struct tms t;
91 USE_VAR(list);
93 if (no_options (list))
94 return (EX_USAGE);
96 times (&t);
98 print_clock_t (stdout, t.tms_utime);
99 putchar (' ');
100 print_clock_t (stdout, t.tms_stime);
101 putchar ('\n');
102 print_clock_t (stdout, t.tms_cutime);
103 putchar (' ');
104 print_clock_t (stdout, t.tms_cstime);
105 putchar ('\n');
107 # else /* !HAVE_TIMES */
109 USE_VAR(list);
111 if (no_options (list))
112 return (EX_USAGE);
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));