109 lines
2.8 KiB
Modula-2
109 lines
2.8 KiB
Modula-2
This file is times.def, from which is created times.c.
|
|
It implements the builtin "times" in Bash.
|
|
|
|
Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
|
|
|
|
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
|
|
Software Foundation; either version 1, or (at your option) any later
|
|
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
|
|
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
$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
|
|
|
|
#include <config.h>
|
|
|
|
#if defined (HAVE_UNISTD_H)
|
|
# ifdef _MINIX
|
|
# include <sys/types.h>
|
|
# endif
|
|
# include <unistd.h>
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include "../bashtypes.h"
|
|
#include "../shell.h"
|
|
|
|
#if TIME_WITH_SYS_TIME
|
|
# include <sys/time.h>
|
|
# include <time.h>
|
|
#else
|
|
# if defined (HAVE_SYS_TIME_H)
|
|
# include <sys/time.h>
|
|
# else
|
|
# include <time.h>
|
|
# endif
|
|
#endif
|
|
|
|
#if defined (HAVE_SYS_TIMES_H)
|
|
# include <sys/times.h>
|
|
#endif /* HAVE_SYS_TIMES_H */
|
|
|
|
#if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
|
|
# include <sys/resource.h>
|
|
#endif
|
|
|
|
#include "common.h"
|
|
|
|
/* Print the totals for system and user time used. */
|
|
int
|
|
times_builtin (list)
|
|
WORD_LIST *list;
|
|
{
|
|
#if defined (HAVE_GETRUSAGE) && defined (HAVE_TIMEVAL) && defined (RUSAGE_SELF)
|
|
struct rusage self, kids;
|
|
|
|
getrusage (RUSAGE_SELF, &self);
|
|
getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
|
|
|
|
print_timeval (stdout, &self.ru_utime);
|
|
putchar (' ');
|
|
print_timeval (stdout, &self.ru_stime);
|
|
putchar ('\n');
|
|
print_timeval (stdout, &kids.ru_utime);
|
|
putchar (' ');
|
|
print_timeval (stdout, &kids.ru_stime);
|
|
putchar ('\n');
|
|
|
|
#else
|
|
# if defined (HAVE_TIMES)
|
|
/* As of System V.3, HP-UX 6.5, and other ATT-like systems, this stuff is
|
|
returned in terms of clock ticks (HZ from sys/param.h). C'mon, guys.
|
|
This kind of stupid clock-dependent stuff is exactly the reason 4.2BSD
|
|
introduced the `timeval' struct. */
|
|
struct tms t;
|
|
|
|
times (&t);
|
|
|
|
print_time_in_hz (stdout, t.tms_utime);
|
|
putchar (' ');
|
|
print_time_in_hz (stdout, t.tms_stime);
|
|
putchar ('\n');
|
|
print_time_in_hz (stdout, t.tms_cutime);
|
|
putchar (' ');
|
|
print_time_in_hz (stdout, t.tms_cstime);
|
|
putchar ('\n');
|
|
# else /* !HAVE_TIMES */
|
|
printf ("0.00 0.00\n0.00 0.00\n");
|
|
# endif /* HAVE_TIMES */
|
|
#endif /* !HAVE_TIMES */
|
|
|
|
return (EXECUTION_SUCCESS);
|
|
}
|