]> git.ipfire.org Git - thirdparty/bash.git/blob - builtins/times.def
Imported from ../bash-1.14.7.tar.gz.
[thirdparty/bash.git] / builtins / times.def
1 This file is times.def, from which is created times.c.
2 It implements the builtin "times" in Bash.
3
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
5
6 This file is part of GNU Bash, the Bourne Again SHell.
7
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
11 version.
12
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
16 for more details.
17
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.
21
22 $PRODUCES times.c
23
24 $BUILTIN times
25 $FUNCTION times_builtin
26 $SHORT_DOC times
27 Print the accumulated user and system times for processes run from
28 the shell.
29 $END
30
31 #include "../shell.h"
32 #include <sys/types.h>
33
34 #if defined (hpux) || defined (USGr4) || defined (XD88) || defined (USGr3)
35 # undef HAVE_RESOURCE
36 #endif /* hpux || USGr4 || XD88 || USGr3 */
37
38 #if defined (_POSIX_VERSION) || !defined (HAVE_RESOURCE)
39 # include <sys/times.h>
40 #else /* !_POSIX_VERSION && HAVE_RESOURCE */
41 # include <sys/time.h>
42 # include <sys/resource.h>
43 #endif /* !_POSIX_VERSION && HAVE_RESOURCE */
44
45 /* Print the totals for system and user time used. The
46 information comes from variables in jobs.c used to keep
47 track of this stuff. */
48 times_builtin (list)
49 WORD_LIST *list;
50 {
51 #if !defined (_POSIX_VERSION) && defined (HAVE_RESOURCE) && defined (RUSAGE_SELF)
52 struct rusage self, kids;
53
54 getrusage (RUSAGE_SELF, &self);
55 getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
56
57 print_timeval (&self.ru_utime);
58 putchar (' ');
59 print_timeval (&self.ru_stime);
60 putchar ('\n');
61 print_timeval (&kids.ru_utime);
62 putchar (' ');
63 print_timeval (&kids.ru_stime);
64 putchar ('\n');
65
66 #else /* _POSIX_VERSION || !HAVE_RESOURCE || !RUSAGE_SELF */
67 # if !defined (BrainDeath)
68 struct tms t;
69
70 times (&t);
71
72 /* As of System V.3, HP-UX 6.5, and other ATT-like systems, this stuff is
73 returned in terms of clock ticks (HZ from sys/param.h). C'mon, guys.
74 This kind of stupid clock-dependent stuff is exactly the reason 4.2BSD
75 introduced the `timeval' struct. */
76
77 print_time_in_hz (t.tms_utime);
78 putchar (' ');
79 print_time_in_hz (t.tms_stime);
80 putchar ('\n');
81 print_time_in_hz (t.tms_cutime);
82 putchar (' ');
83 print_time_in_hz (t.tms_cstime);
84 putchar ('\n');
85 # endif /* BrainDeath */
86 #endif /* _POSIX_VERSION || !HAVE_RESOURCE || !RUSAGE_SELF */
87
88 return (EXECUTION_SUCCESS);
89 }