i-bash/builtins/times.def

116 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.
2002-07-17 14:10:11 +00:00
Copyright (C) 1987-2002 Free Software Foundation, Inc.
1996-08-26 18:22:31 +00:00
This file is part of GNU Bash, the Bourne Again SHell.
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
2000-03-17 21:46:59 +00:00
Software Foundation; either version 2, or (at your option) any later
1996-08-26 18:22:31 +00:00
version.
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.
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
2000-03-17 21:46:59 +00:00
Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
1996-08-26 18:22:31 +00:00
$PRODUCES times.c
$BUILTIN times
$FUNCTION times_builtin
$SHORT_DOC times
Print the accumulated user and system times for processes run from
the shell.
$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
return (EXECUTION_SUCCESS);
}