mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
POSIX compliance fix: make 'times' a proper builtin
As of this commit, the 'times' command is a POSIX-compliant special
builtin command instead of an alias that doesn't produce the
required output. It displays the accumulated user and system CPU
times, one line with the times used by the shell and another with
those used by all of the shell's child processes.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_27
This was originally written by Kurtis Rader and is now backported
and tweaked from the abandoned ksh2020 branch. I chose an earlier
and simpler version[*1] that uses times(3), with a precision of
hundredths of seconds, so it outputs the same precision as mksh and
zsh. Rader later wrote another version[*2] that uses getrusage(2),
giving it the same millisecond precision as bash. But that required
adding a feature test and a fallback to the old version, which is
non-trivial in the old INIT/iffe system. This simpler version is
enough to gain POSIX compliance and I think it will do very nicely
in this stable bugfix branch.
[*1] https://github.com/att/ast/pull/1332
[*2] 038045f6
src/cmd/ksh93/bltins/misc.c
- Add b_times() function for 'times' builtin.
- Note we include <times.h>, not <sys/times.h>, so that we use the
AST feature-tested version with fallback on systems that need it.
src/cmd/ksh93/data/aliases.c:
- Remove times='{ { time;} 2>&1;}' builtin alias.
src/cmd/ksh93/data/builtins.c,
src/cmd/ksh93/include/builtins.h:
- Add entry for 'times' special builtin.
- Add --help/--man info for same.
src/cmd/ksh93/sh.1:
- Update manual page.
src/cmd/ksh93/tests/builtins.sh:
- Add a couple of simple regression tests.
(cherry picked from commit ebf71e619eb298ec1cf6b81d1828fa7cdf6e9203)
This commit is contained in:
parent
3a3776f1df
commit
65d363fd34
8 changed files with 96 additions and 5 deletions
|
@ -115,6 +115,7 @@ const struct shtable3 shtab_builtins[] =
|
|||
"read", NV_BLTIN|BLT_ENV, bltin(read),
|
||||
"sleep", NV_BLTIN, bltin(sleep),
|
||||
"alarm", NV_BLTIN, bltin(alarm),
|
||||
"times", NV_BLTIN|BLT_SPC, bltin(times),
|
||||
"ulimit", NV_BLTIN|BLT_ENV, bltin(ulimit),
|
||||
"umask", NV_BLTIN|BLT_ENV, bltin(umask),
|
||||
#ifdef _cmd_universe
|
||||
|
@ -1761,6 +1762,15 @@ USAGE_LICENSE
|
|||
"[+SEE ALSO?\bulimit\b(2), \bgetrlimit\b(2)]"
|
||||
;
|
||||
|
||||
const char sh_opttimes[] =
|
||||
"[-1c?@(#)$Id: times (ksh community) 2020-06-06 $\n]"
|
||||
"[+NAME?times - display CPU usage by the shell and child processes]"
|
||||
"[+DESCRIPTION?\btimes\b displays the accumulated user and system CPU times, "
|
||||
"one line with the times used by the shell and another with those used by "
|
||||
"all of the shell's child processes. No options are supported.]"
|
||||
"[+SEE ALSO?\btime\b(1)]"
|
||||
;
|
||||
|
||||
const char sh_optumask[] =
|
||||
"[-1c?\n@(#)$Id: umask (AT&T Research) 1999-04-07 $\n]"
|
||||
USAGE_LICENSE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue