Bash Reference Manual says
The use of
time
as a reserved word permits the timing
of shell builtins, shell functions, and pipelines. An externaltime
command cannot time
these easily.
-
What can an external command
time
time?Only a simple external command? Nothing else?
Which rule prevents it from timing other things? Does the rule
belong to the shell (bash) or the implementation of the external
commandtime
?Btw, I am running Ubuntu, so
time
is from Debian. -
Can the Bash's reserved word
time
time all the things that can
run? If not, what can't it time? -
What are the things that the external
time
can time but the reserved wordtime
can't?
Best Answer
My answer is about Linux.
I guess it gets time info only for processes since it actually uses
wait4
system call for getting this time info. The first parameter ofwait4
is the pid of a process. So/usr/bin/time
always callexecve
and then wait4.By the way:
So /usr/bin/time needs something that can be executed by
execve
I guess, yes. It is implemented as two group of calls:
run a command or builtin
So I guess
bash
just calculate a difference and prints it. In that way it can measure anythins like own builtins or child processActually both system calls
getrusage
andwait4
get from a kernel struct rusage usage. Howeverbash time
prints limited number of fields from this structure. This is fromman 1 time
: