Imported from ../bash-1.14.7.tar.gz.
This commit is contained in:
commit
726f63884d
402 changed files with 150297 additions and 0 deletions
89
builtins/times.def
Normal file
89
builtins/times.def
Normal file
|
@ -0,0 +1,89 @@
|
|||
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 "../shell.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined (hpux) || defined (USGr4) || defined (XD88) || defined (USGr3)
|
||||
# undef HAVE_RESOURCE
|
||||
#endif /* hpux || USGr4 || XD88 || USGr3 */
|
||||
|
||||
#if defined (_POSIX_VERSION) || !defined (HAVE_RESOURCE)
|
||||
# include <sys/times.h>
|
||||
#else /* !_POSIX_VERSION && HAVE_RESOURCE */
|
||||
# include <sys/time.h>
|
||||
# include <sys/resource.h>
|
||||
#endif /* !_POSIX_VERSION && HAVE_RESOURCE */
|
||||
|
||||
/* Print the totals for system and user time used. The
|
||||
information comes from variables in jobs.c used to keep
|
||||
track of this stuff. */
|
||||
times_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
#if !defined (_POSIX_VERSION) && defined (HAVE_RESOURCE) && defined (RUSAGE_SELF)
|
||||
struct rusage self, kids;
|
||||
|
||||
getrusage (RUSAGE_SELF, &self);
|
||||
getrusage (RUSAGE_CHILDREN, &kids); /* terminated child processes */
|
||||
|
||||
print_timeval (&self.ru_utime);
|
||||
putchar (' ');
|
||||
print_timeval (&self.ru_stime);
|
||||
putchar ('\n');
|
||||
print_timeval (&kids.ru_utime);
|
||||
putchar (' ');
|
||||
print_timeval (&kids.ru_stime);
|
||||
putchar ('\n');
|
||||
|
||||
#else /* _POSIX_VERSION || !HAVE_RESOURCE || !RUSAGE_SELF */
|
||||
# if !defined (BrainDeath)
|
||||
struct tms t;
|
||||
|
||||
times (&t);
|
||||
|
||||
/* 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. */
|
||||
|
||||
print_time_in_hz (t.tms_utime);
|
||||
putchar (' ');
|
||||
print_time_in_hz (t.tms_stime);
|
||||
putchar ('\n');
|
||||
print_time_in_hz (t.tms_cutime);
|
||||
putchar (' ');
|
||||
print_time_in_hz (t.tms_cstime);
|
||||
putchar ('\n');
|
||||
# endif /* BrainDeath */
|
||||
#endif /* _POSIX_VERSION || !HAVE_RESOURCE || !RUSAGE_SELF */
|
||||
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue