i-bash/builtins/times.def

120 lines
2.7 KiB
Modula-2
Raw Normal View History

1996-08-26 18:22:31 +00:00
This file is times.def, from which is created times.c.
It implements the builtin "times" in Bash.
2009-01-12 13:36:28 +00:00
Copyright (C) 1987-2009 Free Software Foundation, Inc.
1996-08-26 18:22:31 +00:00
This file is part of GNU Bash, the Bourne Again SHell.
2009-01-12 13:36:28 +00:00
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
1996-08-26 18:22:31 +00:00
2009-01-12 13:36:28 +00:00
Bash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
1996-08-26 18:22:31 +00:00
2009-01-12 13:36:28 +00:00
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
1996-08-26 18:22:31 +00:00
$PRODUCES times.c
$BUILTIN times
$FUNCTION times_builtin
$SHORT_DOC times
2009-01-12 13:36:28 +00:00
Display process times.
Prints the accumulated user and system times for the shell and all of its
child processes.
Exit Status:
Always succeeds.
1996-08-26 18:22:31 +00:00
$END
1996-12-23 17:02:34 +00:00
#include <config.h>
1996-08-26 18:22:31 +00:00
1996-12-23 17:02:34 +00:00
#if defined (HAVE_UNISTD_H)
1998-04-17 19:52:44 +00:00
# ifdef _MINIX
# include <sys/types.h>
# endif
1996-12-23 17:02:34 +00:00
# include <unistd.h>
#endif
1996-08-26 18:22:31 +00:00
1996-12-23 17:02:34 +00:00
#include <stdio.h>
#include "../bashtypes.h"
#include "../shell.h"
2000-03-17 21:46:59 +00:00
#include <posixtime.h>
1996-12-23 17:02:34 +00:00
#if defined (HAVE_SYS_TIMES_H)
# include <sys/times.h>
#endif /* HAVE_SYS_TIMES_H */
1998-04-17 19:52:44 +00:00
#if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
1996-08-26 18:22:31 +00:00
# include <sys/resource.h>
1996-12-23 17:02:34 +00:00
#endif
#include "common.h"
1996-08-26 18:22:31 +00:00
1996-12-23 17:02:34 +00:00
/* Print the totals for system and user time used. */
int
1996-08-26 18:22:31 +00:00
times_builtin (list)
WORD_LIST *list;
{
1996-12-23 17:02:34 +00:00
#if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF)
1996-08-26 18:22:31 +00:00
struct rusage self, kids;
2002-07-17 14:10:11 +00:00
USE_VAR(list);
if (no_options (list))
return (EX_USAGE);
1996-08-26 18:22:31 +00:00
getrusage (RUSAGE_SELF, &self);
getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
1996-12-23 17:02:34 +00:00
print_timeval (stdout, &self.ru_utime);
1996-08-26 18:22:31 +00:00
putchar (' ');
1996-12-23 17:02:34 +00:00
print_timeval (stdout, &self.ru_stime);
1996-08-26 18:22:31 +00:00
putchar ('\n');
1996-12-23 17:02:34 +00:00
print_timeval (stdout, &kids.ru_utime);
1996-08-26 18:22:31 +00:00
putchar (' ');
1996-12-23 17:02:34 +00:00
print_timeval (stdout, &kids.ru_stime);
1996-08-26 18:22:31 +00:00
putchar ('\n');
1996-12-23 17:02:34 +00:00
#else
# if defined (HAVE_TIMES)
2000-03-17 21:46:59 +00:00
/* This uses the POSIX.1/XPG5 times(2) interface, which fills in a
`struct tms' with values of type clock_t. */
1996-12-23 17:02:34 +00:00
struct tms t;
2002-07-17 14:10:11 +00:00
USE_VAR(list);
if (no_options (list))
return (EX_USAGE);
1996-12-23 17:02:34 +00:00
times (&t);
1996-08-26 18:22:31 +00:00
2000-03-17 21:46:59 +00:00
print_clock_t (stdout, t.tms_utime);
1996-08-26 18:22:31 +00:00
putchar (' ');
2000-03-17 21:46:59 +00:00
print_clock_t (stdout, t.tms_stime);
1996-08-26 18:22:31 +00:00
putchar ('\n');
2000-03-17 21:46:59 +00:00
print_clock_t (stdout, t.tms_cutime);
1996-08-26 18:22:31 +00:00
putchar (' ');
2000-03-17 21:46:59 +00:00
print_clock_t (stdout, t.tms_cstime);
1996-08-26 18:22:31 +00:00
putchar ('\n');
2002-07-17 14:10:11 +00:00
1996-12-23 17:02:34 +00:00
# else /* !HAVE_TIMES */
2002-07-17 14:10:11 +00:00
USE_VAR(list);
if (no_options (list))
return (EX_USAGE);
1996-12-23 17:02:34 +00:00
printf ("0.00 0.00\n0.00 0.00\n");
2002-07-17 14:10:11 +00:00
1996-12-23 17:02:34 +00:00
# endif /* HAVE_TIMES */
#endif /* !HAVE_TIMES */
1996-08-26 18:22:31 +00:00
2009-01-12 13:36:28 +00:00
return (sh_chkwrite (EXECUTION_SUCCESS));
1996-08-26 18:22:31 +00:00
}